import random def generate_baseline(): "““模拟一栋大楼24小时的基础用电负荷(单位:kW)””" loads = [] for h in range(24): if 8 <= h <= 18: load = 300 + 200 * (1 - abs(h - 13) / 5) + random.uniform(-8, 8) elif 19 <= h <= 22: load = 250 + 100 * (1 - abs(h - 20) / 2) + random.uniform(-8, 8) else: load = 100 + random.uniform(-5, 5) loads.append(round(max(load, 40), 1)) return loads def apply_schedule(base_load): "““把高峰时段的负荷转移到低谷时段(储能+柔性负荷)””“ plan = base_load[:] shift = 150 # 可转移功率(kW) peak_hours = [11, 12, 13, 14, 15] valley_hours = [2, 3, 4, 5] for h in peak_hours: plan[h] = round(plan[h] - shift, 1) for h in valley_hours: plan[h] = round(plan[h] + shift, 1) return plan def peak_reduction_rate(original, planned): ”““计算削峰率(%)””“ peak_old = max(original) peak_new = max(planned) return (peak_old - peak_new) / peak_old * 100 def main(): random.seed(42) base = generate_baseline() plan = apply_schedule(base) rate = peak_reduction_rate(base, plan) print(“时段:” + ” ".join(f"{h:2d}“ for h in range(24))) print(“原始:” + ” ".join(f"{v:5.1f}“ for v in base)) print(“调度后:” + ” ".join(f"{v:5.1f}“ for v in plan)) print(f“\n峰值负荷:{max(base):.1f} kW -> {max(plan):.1f} kW”) print(f“削峰率:{rate:.1f}%”) print(f“需量电费节省(按40元/kW): {(max(base) - max(plan)) * 40:.1f} 元/月”) if name == ”main": main() ```

岗位关联

代码用途:模拟一栋大楼24小时的原始用电曲线,将高峰时段的150kW负荷转移到低谷时段,计算削峰率和每月节省的需量电费。