diff --git a/core/src/allocation_init.jl b/core/src/allocation_init.jl index 37e62dd1e..85ad53848 100644 --- a/core/src/allocation_init.jl +++ b/core/src/allocation_init.jl @@ -462,6 +462,8 @@ function allocation_problem( end """ +Get the sources within the subnetwork in the order in which they will +be optimized over. TODO: Get preferred source order from input """ function get_sources_in_order( diff --git a/core/src/allocation_optim.jl b/core/src/allocation_optim.jl index be11c1f19..ac80e0c8c 100644 --- a/core/src/allocation_optim.jl +++ b/core/src/allocation_optim.jl @@ -223,6 +223,9 @@ function set_initial_capacities_source!( return nothing end +""" +Reduce the capacity of a source by the amount of flow taken from them in the latest optimization. +""" function reduce_source_capacity!(problem::JuMP.Model, source::AllocationSource)::Nothing (; edge) = source @@ -870,6 +873,10 @@ function set_source_capacity!( return nothing end +""" +Solve the allocation problem for a single priority by optimizing for each source +in the subnetwork individually. +""" function optimize_per_source!( allocation::Allocation, allocation_model::AllocationModel, @@ -933,6 +940,9 @@ function optimize_per_source!( return nothing end +""" +Keep track of how much is taken from or added to the basins in the subnetwork. +""" function increase_allocateds!(basin::Basin, problem::JuMP.Model)::Nothing (; allocated) = basin @@ -999,7 +1009,7 @@ function optimize_priority!( end """ -Set the initial capacities and demands which are recuded by usage. +Set the initial capacities and demands which are reduced by usage. """ function set_initial_values!( allocation_model::AllocationModel, diff --git a/core/src/parameter.jl b/core/src/parameter.jl index ef1cfb025..ce2f1d298 100644 --- a/core/src/parameter.jl +++ b/core/src/parameter.jl @@ -130,6 +130,13 @@ cache(len::Int)::Cache = LazyBufferCache(Returns(len); initializer! = set_zero!) @enumx AllocationSourceType edge basin main_to_sub user_return buffer +""" +Data structure for a single source within an allocation subnetwork. +edge: The outflow edge of the source +type: The type of source (edge, basin, main_to_sub, user_return, buffer) +capacity: The initial capacity of the source as determined by the physical layer +capacity_reduced: The capacity adjusted by passed optimizations +""" @kwdef struct AllocationSource edge::Tuple{NodeID, NodeID} type::AllocationSourceType.T diff --git a/core/test/allocation_test.jl b/core/test/allocation_test.jl index 7f7b8be5e..9eb658721 100644 --- a/core/test/allocation_test.jl +++ b/core/test/allocation_test.jl @@ -11,9 +11,6 @@ db = SQLite.DB(db_path) p = Ribasim.Parameters(db, cfg) - - model = Ribasim.Model(cfg) - (; p) = model.integrator (; graph, allocation) = p allocation.mean_input_flows[(NodeID(:FlowBoundary, 1, db), NodeID(:Basin, 2, db))] = 4.5