Skip to content

Commit

Permalink
deleted the flow cost and deleted the unit tests of flow cost
Browse files Browse the repository at this point in the history
  • Loading branch information
Jingru923 committed Feb 6, 2024
1 parent af3b771 commit ecb2e8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
30 changes: 15 additions & 15 deletions core/src/allocation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -883,20 +883,20 @@ function set_objective_priority!(
add_user_term!(ex, edge_id, objective_type, d, allocation_model)
end

# Add flow cost
if objective_type == :linear_absolute
cost_per_flow = 0.5 / length(F)
for flow in F
JuMP.add_to_expression!(ex, cost_per_flow * flow)
end
elseif objective_type == :linear_relative
if demand_max > 0.0
cost_per_flow = 0.5 / (demand_max * length(F))
for flow in F
JuMP.add_to_expression!(ex, cost_per_flow * flow)
end
end
end
# # Add flow cost
# if objective_type == :linear_absolute
# cost_per_flow = 0.5 / length(F)
# for flow in F
# JuMP.add_to_expression!(ex, cost_per_flow * flow) #
# end
# elseif objective_type == :linear_relative
# if demand_max > 0.0
# cost_per_flow = 0.5 / (demand_max * length(F))
# for flow in F
# JuMP.add_to_expression!(ex, cost_per_flow * flow) #
# end
# end
# end

new_objective = JuMP.@expression(problem, ex)
JuMP.@objective(problem, Min, new_objective)
Expand Down Expand Up @@ -1154,7 +1154,7 @@ function allocate!(
@debug JuMP.solution_summary(problem)
if JuMP.termination_status(problem) !== JuMP.OPTIMAL
(; allocation_network_id) = allocation_model
priority = priorities[priority_index]
priority = priorities[priority_idx]
error(
"Allocation of subnetwork $allocation_network_id, priority $priority coudn't find optimal solution.",
)
Expand Down
8 changes: 0 additions & 8 deletions core/test/allocation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ end

@test objective.terms[F_abs[NodeID(5)]] == 1.0
@test objective.terms[F_abs[NodeID(6)]] == 1.0
@test objective.terms[F[(NodeID(4), NodeID(6))]] 0.125
@test objective.terms[F[(NodeID(1), NodeID(2))]] 0.125
@test objective.terms[F[(NodeID(4), NodeID(5))]] 0.125
@test objective.terms[F[(NodeID(2), NodeID(4))]] 0.125

config = Ribasim.Config(toml_path; allocation_objective_type = "linear_relative")
model = Ribasim.run(config)
Expand All @@ -113,10 +109,6 @@ end

@test objective.terms[F_abs[NodeID(5)]] == 1.0
@test objective.terms[F_abs[NodeID(6)]] == 1.0
@test objective.terms[F[(NodeID(4), NodeID(6))]] 62.585499316005475
@test objective.terms[F[(NodeID(1), NodeID(2))]] 62.585499316005475
@test objective.terms[F[(NodeID(4), NodeID(5))]] 62.585499316005475
@test objective.terms[F[(NodeID(2), NodeID(4))]] 62.585499316005475
end

@testitem "Allocation with controlled fractional flow" begin
Expand Down

0 comments on commit ecb2e8a

Please sign in to comment.