Skip to content

Commit

Permalink
Linear fit for NCD pump power
Browse files Browse the repository at this point in the history
  • Loading branch information
hskkanth committed Sep 16, 2023
1 parent 47a6f1d commit 48cb3e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
35 changes: 13 additions & 22 deletions src/core/objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,25 @@ cost of building and operating all network expansion components is minimized.
"""
function objective_ne(wm::AbstractWaterModel)::JuMP.AffExpr
# Get all network IDs in the multinetwork.
network_ids = sort(collect(nw_ids(wm)))
first_network_id = sort(collect(nw_ids(wm)))[1]

# Find the network IDs over which the objective will be defined.
if length(network_ids) > 1
network_ids_flow = network_ids[1]
# network_ids_flow = network_ids[1:end-1]
else
network_ids_flow = network_ids
end

# Initialize the objective expression to zero.
objective = JuMP.AffExpr(0.0)

for n in network_ids_flow
# Get the set of network expansion short pipes at time index `n`.
for (a, ne_short_pipe) in ref(wm, n, :ne_short_pipe)
# Add the cost of network expansion component `a` at time period `n`.
term = ne_short_pipe["construction_cost"] * var(wm, n, :z_ne_short_pipe, a)
JuMP.add_to_expression!(objective, term)
end

# Get the set of network expansion pumps at time index `n`.
for (a, ne_pump) in ref(wm, n, :ne_pump)
# Add the cost of network expansion component `a` at time period `n`.
term = ne_pump["construction_cost"] * var(wm, n, :x_ne_pump, a)
JuMP.add_to_expression!(objective, term)
end
n = first_network_id
# Get the set of network expansion short pipes at time index `n`.
for (a, ne_short_pipe) in ref(wm, n, :ne_short_pipe)
# Add the cost of network expansion component `a` at time period `n`.
term = ne_short_pipe["construction_cost"] * var(wm, n, :z_ne_short_pipe, a)
JuMP.add_to_expression!(objective, term)
end

# Get the set of network expansion pumps at time index `n`.
for (a, ne_pump) in ref(wm, n, :ne_pump)
# Add the cost of network expansion component `a` at time period `n`.
term = ne_pump["construction_cost"] * var(wm, n, :x_ne_pump, a)
JuMP.add_to_expression!(objective, term)

Check warning on line 106 in src/core/objective.jl

View check run for this annotation

Codecov / codecov/patch

src/core/objective.jl#L105-L106

Added lines #L105 - L106 were not covered by tests
end

# Minimize the total cost of network expansion.
Expand Down
16 changes: 9 additions & 7 deletions src/form/ncd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,11 @@ function constraint_on_off_pump_power(
z = var(wm, n, :z_pump, a)

# Add constraint equating power with respect to the power curve.
power_qa = _calc_pump_power_linear_coeff(wm, n, z)
# power_qa = _calc_pump_power_quadratic_approximation(wm, n, a, z)
c_1 = JuMP.@constraint(wm.model, power(q) <= P)
c_2 = JuMP.@constraint(wm.model, power(q) >= P)
power_la = _calc_pump_power_linear_coeff(wm, n, z)
println("power_la = $power_la")

Check warning on line 739 in src/form/ncd.jl

View check run for this annotation

Codecov / codecov/patch

src/form/ncd.jl#L739

Added line #L739 was not covered by tests
# power_la = _calc_pump_power_quadratic_approximation(wm, n, a, z)
c_1 = JuMP.@constraint(wm.model, power_la(q) <= P)
c_2 = JuMP.@constraint(wm.model, power_la(q) >= P)

Check warning on line 742 in src/form/ncd.jl

View check run for this annotation

Codecov / codecov/patch

src/form/ncd.jl#L741-L742

Added lines #L741 - L742 were not covered by tests

# Append the :on_off_pump_power constraint array.
append!(con(wm, n, :on_off_pump_power)[a], [c_1, c_2])
Expand All @@ -757,9 +758,10 @@ function constraint_on_off_pump_power_ne(
z = var(wm, n, :z_ne_pump, a)

# Add constraint equating power with respect to the power curve.
power = _calc_pump_power_linear_coeff(wm, n, z)
c_1 = JuMP.@constraint(wm.model, power(q) <= P)
c_2 = JuMP.@constraint(wm.model, power(q) >= P)
# power_la = _calc_pump_power_quadratic_approximation_ne(wm, n, a, z)
power_la = _calc_pump_power_linear_coeff(wm, n, z)
c_1 = JuMP.@constraint(wm.model, power_la(q) <= P)
c_2 = JuMP.@constraint(wm.model, power_la(q) >= P)

Check warning on line 764 in src/form/ncd.jl

View check run for this annotation

Codecov / codecov/patch

src/form/ncd.jl#L762-L764

Added lines #L762 - L764 were not covered by tests

# Append the :on_off_pump_power constraint array.
append!(con(wm, n, :on_off_pump_power_ne)[a], [c_1, c_2])
Expand Down

0 comments on commit 48cb3e2

Please sign in to comment.