Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jingru923 committed Jun 3, 2024
1 parent ec3357a commit 4486651
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
20 changes: 9 additions & 11 deletions core/src/allocation_optim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,6 @@ function empty_sources!(allocation_model::AllocationModel, allocation::Allocatio
return nothing
end

"""
Loop over the priorities
"""
function loop_opt_priorities(priorities::Vector{Int32})::Nothing
for priority_idx in eachindex(priorities)
optimize_priority!(allocation_model, u, p, t, priority_idx, optimization_type)
end
end
"""
Update the allocation optimization problem for the given subnetwork with the problem state
and flows, solve the allocation problem and assign the results to the UserDemand.
Expand All @@ -1007,7 +999,10 @@ function collect_demands(

set_initial_values!(allocation_model, p, u, t)

loop_opt_priorities(priorities)
# Loop over priorities
for priority_idx in eachindex(priorities)
optimize_priority!(allocation_model, u, p, t, priority_idx, optimization_type)
end

## Collect demand
optimization_type = OptimizationType.collect_demands
Expand All @@ -1027,10 +1022,13 @@ function collect_demands(
# from the main to subnetwork connections
empty_sources!(allocation_model, allocation)

loop_opt_priorities(priorities)
# Loop over priorities
for priority_idx in eachindex(priorities)
optimize_priority!(allocation_model, u, p, t, priority_idx, optimization_type)
end
end

function allocate_demands(
function allocate_demands!(
p::Parameters,
allocation_model::AllocationModel,
t::Float64,
Expand Down
2 changes: 1 addition & 1 deletion core/src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ function update_allocation!(integrator)::Nothing
# If a main network is present this is solved first,
# which provides allocation to the subnetworks
for allocation_model in allocation_models
allocate_demands(p, allocation_model, t, u)
allocate_demands!(p, allocation_model, t, u)
end

# Reset the mean source flows
Expand Down
2 changes: 1 addition & 1 deletion core/test/allocation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
allocation.mean_flows[(NodeID(:FlowBoundary, 1), NodeID(:Basin, 2))][] = 4.5
allocation_model = p.allocation.allocation_models[1]
u = ComponentVector(; storage = zeros(length(p.basin.node_id)))
Ribasim.allocate_demands(p, allocation_model, 0.0, u)
Ribasim.allocate_demands!(p, allocation_model, 0.0, u)

# Last priority (= 2) flows
F = allocation_model.problem[:F]
Expand Down

0 comments on commit 4486651

Please sign in to comment.