Skip to content

Commit

Permalink
Set (first) fractions in fractional flow constriants
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Nov 30, 2023
1 parent 8e45df2 commit f2a1097
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions core/src/allocation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -585,20 +585,27 @@ function add_constraints_fractional_flow!(
p::Parameters,
allocation_network_id::Int,
)::Nothing
(; graph) = p
(; graph, fractional_flow) = p
F = problem[:F]
edge_ids = graph[].edge_ids[allocation_network_id]
fraction = 1.0

edges_to_fractional_flow =
[edge_id for edge_id in edge_ids if graph[edge_id[2]].type == :fractional_flow]
edges_to_fractional_flow = Tuple{NodeID, NodeID}[]
fractions = Dict{Tuple{NodeID, NodeID}, Float64}()
for edge_id in edge_ids
node_id_fractional_flow = edge_id[2]
if graph[node_id_fractional_flow] == :fractional_flow
push!(edges_to_fractional_flow, edge_id)
node_idx = findsorted(fractional_flow.node_id, node_id_fractional_flow)
fractions[edge_id] = fractional_flow.fraction[node_idx]

Check warning on line 599 in core/src/allocation.jl

View check run for this annotation

Codecov / codecov/patch

core/src/allocation.jl#L597-L599

Added lines #L597 - L599 were not covered by tests
end
end

if !isempty(edges_to_fractional_flow)
problem[:fractional_flow] = JuMP.@constraint(

Check warning on line 604 in core/src/allocation.jl

View check run for this annotation

Codecov / codecov/patch

core/src/allocation.jl#L604

Added line #L604 was not covered by tests
problem,
[edge = edges_to_fractional_flow],
sum(F[(inflow_id, edge[1])] for inflow_id in inflow_ids(graph, edge[1])) <=
fraction * F[edge],
fractions[edge] * F[edge],
base_name = "fractional_flow"
)
end
Expand Down

0 comments on commit f2a1097

Please sign in to comment.