Skip to content

Commit

Permalink
fix objective
Browse files Browse the repository at this point in the history
  • Loading branch information
degleris1 committed Dec 30, 2024
1 parent 7294d00 commit 5a8bda0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
28 changes: 20 additions & 8 deletions development/19_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_pypsa_net(drop_battery=True, time_horizon=12):
net, devices = zap.importers.load_pypsa_network(
pn,
dates,
scale_load=0.7,
scale_load=1.0,
power_unit=1000.0,
cost_unit=100.0,
load_cost_perturbation=10.0,
Expand Down Expand Up @@ -208,7 +208,7 @@ def _(
):
planner_objective = MultiObjective(
objectives=[DispatchCostObjective(net, devices), EmissionsObjective(devices)],
weights=[1.0, 0.1],
weights=[1.0, 10.0],
)
return (planner_objective,)

Expand All @@ -233,20 +233,32 @@ def _(


@app.cell
def _():
# help(pao.Solver("pao.pyomo.FA").solve)
def _(bilevel_model, devices, np, parse_output):
sum(np.round(parse_output(devices, bilevel_model.dispatch)[0][0][0], decimals=2))
return


@app.cell
def _(bilevel_model, devices, np, parse_output):
sum(np.round(parse_output(devices, bilevel_model.dispatch)[0][0][0], decimals=2))
def _(bilevel_model, pyo):
pyo.value(bilevel_model.param_blocks[0].investment_cost)
return


@app.cell
def _(bilevel_model, pyo):
pyo.value(bilevel_model.dispatch.device[0].emissions)
return


@app.cell
def _(bilevel_model, devices, np):
np.sum(np.array([bilevel_model.param_blocks[0].param[k].value for k in range(devices[0].num_devices)]))
return


@app.cell
def _(bilevel_model, devices):
sum([bilevel_model.param_blocks[0].param[k].value for k in range(devices[0].num_devices)])
def _():
# help(pao.Solver("pao.pyomo.FA").solve)
return


Expand Down
9 changes: 4 additions & 5 deletions zap/pyomo/bilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ def solve_bilevel_model(

# Create top level objective
planner_objective = convert_to_pyo_objective(planner_objective)
M.objective = pyo.Objective(
M.planner_objective = pyo.Expression(
expr=planner_objective.get_objective(M.dispatch),
)
M.objective = pyo.Objective(
expr=(M.planner_objective + sum(M.param_blocks[p].investment_cost for p in param_devices)),
sense=pyo.minimize,
)
# M.objective = pyo.Objective(
# expr=(M.dispatch.objective + sum(M.param_blocks[p].investment_cost for p in param_devices)),
# sense=pyo.minimize,
# )

# Solve bilevel problem
mip = pao.Solver(mip_solver)
Expand Down

0 comments on commit 5a8bda0

Please sign in to comment.