|
36 | 36 |
|
37 | 37 | from shapely.geometry import box, Point, Polygon, MultiPolygon
|
38 | 38 |
|
| 39 | +import nomopyomo |
| 40 | + |
39 | 41 | octant_folder = "../cutouts/"
|
40 | 42 |
|
41 | 43 | colors = {"wind":"#3B6182",
|
@@ -440,10 +442,17 @@ def run_optimisation(assumptions, pu):
|
440 | 442 | efficiency = assumptions_df.at['battery_power','efficiency'])
|
441 | 443 |
|
442 | 444 | def extra_functionality(network,snapshots):
|
443 |
| - def battery(model): |
444 |
| - return model.link_p_nom["battery_power"] == model.link_p_nom["battery_discharge"]*network.links.at["battery_power","efficiency"] |
445 |
| - |
446 |
| - network.model.battery = Constraint(rule=battery) |
| 445 | + group = "battery" |
| 446 | + nomopyomo.add_group(network,"constraint",group,1) |
| 447 | + start = network.constraint_positions.at[group,"start"] |
| 448 | + |
| 449 | + # charge-power = efficiency * discharge-power |
| 450 | + constraint_matrix = {} |
| 451 | + i_battery_power = network.variable_positions.at["Link-p_nom","start"] + network.links.index.get_loc("battery_power") |
| 452 | + i_battery_discharge = network.variable_positions.at["Link-p_nom","start"] + network.links.index.get_loc("battery_discharge") |
| 453 | + constraint_matrix[i_battery_power] = 1. |
| 454 | + constraint_matrix[i_battery_discharge] = -network.links.at["battery_power","efficiency"] |
| 455 | + nomopyomo.write_constraint(network,constraint_matrix,"==",0.,start) |
447 | 456 | else:
|
448 | 457 | def extra_functionality(network,snapshots):
|
449 | 458 | pass
|
@@ -481,9 +490,10 @@ def extra_functionality(network,snapshots):
|
481 | 490 |
|
482 | 491 | solver_name = "cbc"
|
483 | 492 | formulation = "kirchhoff"
|
484 |
| - status, termination_condition = network.lopf(solver_name=solver_name, |
485 |
| - formulation=formulation, |
486 |
| - extra_functionality=extra_functionality) |
| 493 | + status, termination_condition = nomopyomo.network_lopf(network, |
| 494 | + solver_name=solver_name, |
| 495 | + formulation=formulation, |
| 496 | + extra_functionality=extra_functionality) |
487 | 497 |
|
488 | 498 | print(status,termination_condition)
|
489 | 499 |
|
|
0 commit comments