Skip to content

Commit

Permalink
fix: add weigths to nodalbalance constraints to provide correct price…
Browse files Browse the repository at this point in the history
…s as duals
  • Loading branch information
Daniel Schwabeneder committed Sep 27, 2024
1 parent 911d03d commit 2d1ec51
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/core/node/con_nodalbalance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,18 @@ function _node_con_nodalbalance!(node::Node)
node.con.nodalbalance = @constraint(
model,
[t = _iesopt(model).model.T],
node.exp.injection[t] == 0,
_weight(model, t) * node.exp.injection[t] == 0,
base_name = _base_name(node, "nodalbalance"),
container = Array
)
else
# Create all representatives.
_repr = Dict(
t => @constraint(model, node.exp.injection[t] == 0, base_name = _base_name(node, "nodalbalance[$(t)]")) for t in _iesopt(model).model.T if _iesopt(model).model.snapshots[t].is_representative
t => @constraint(
model,
_weight(model, t) * node.exp.injection[t] == 0,
base_name = _base_name(node, "nodalbalance[$(t)]")
) for t in _iesopt(model).model.T if _iesopt(model).model.snapshots[t].is_representative
)

# Create all constraints, either as themselves or their representative.
Expand All @@ -137,14 +141,18 @@ function _node_con_nodalbalance!(node::Node)
node.con.nodalbalance = @constraint(
model,
[t = _iesopt(model).model.T],
node.exp.injection[t] <= 0,
_weight(model, t) * node.exp.injection[t] <= 0,
base_name = _base_name(node, "nodalbalance"),
container = Array
)
else
# Create all representatives.
_repr = Dict(
t => @constraint(model, node.exp.injection[t] <= 0, base_name = _base_name(node, "nodalbalance[$(t)]")) for t in _iesopt(model).model.T if _iesopt(model).model.snapshots[t].is_representative
t => @constraint(
model,
_weight(model, t) * node.exp.injection[t] <= 0,
base_name = _base_name(node, "nodalbalance[$(t)]")
) for t in _iesopt(model).model.T if _iesopt(model).model.snapshots[t].is_representative
)

# Create all constraints, either as themselves or their representative.
Expand All @@ -158,14 +166,18 @@ function _node_con_nodalbalance!(node::Node)
node.con.nodalbalance = @constraint(
model,
[t = _iesopt(model).model.T],
node.exp.injection[t] >= 0,
_weight(model, t) * node.exp.injection[t] >= 0,
base_name = _base_name(node, "nodalbalance"),
container = Array
)
else
# Create all representatives.
_repr = Dict(
t => @constraint(model, node.exp.injection[t] >= 0, base_name = _base_name(node, "nodalbalance[$(t)]")) for t in _iesopt(model).model.T if _iesopt(model).model.snapshots[t].is_representative
t => @constraint(
model,
_weight(model, t) * node.exp.injection[t] >= 0,
base_name = _base_name(node, "nodalbalance[$(t)]")
) for t in _iesopt(model).model.T if _iesopt(model).model.snapshots[t].is_representative
)

# Create all constraints, either as themselves or their representative.
Expand All @@ -180,7 +192,7 @@ function _node_con_nodalbalance!(node::Node)
node.con.nodalbalance = @constraint(
model,
[t0 = begin_steps],
sum(node.exp.injection[t] for t in t0:(t0 - 1 + node.sum_window_size)) == 0,
sum(_weight(model, t) * node.exp.injection[t] for t in t0:(t0 - 1 + node.sum_window_size)) == 0,
base_name = _base_name(node, "nodalbalance"),
container = Array
)
Expand Down

0 comments on commit 2d1ec51

Please sign in to comment.