Skip to content

Commit e5a9439

Browse files
authored
Check only connected control states in FractionalFlow validation (#1569)
Fixes part of #1567, bullet point 4.
1 parent dfad5f2 commit e5a9439

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

core/src/validation.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function valid_pid_connectivity(
315315
end
316316

317317
"""
318-
Check that nodes that have fractional flow outneighbors do not have any other type of
318+
Check that nodes that have FractionalFlow outneighbors do not have any other type of
319319
outneighbor, that the fractions leaving a node add up to ≈1 and that the fractions are non-negative.
320320
"""
321321
function valid_fractional_flow(
@@ -328,12 +328,24 @@ function valid_fractional_flow(
328328
# Node IDs that have fractional flow outneighbors
329329
src_ids = Set{NodeID}()
330330

331+
# The set of control states associated with each source node
332+
control_states = Dict{NodeID, Set{String}}()
333+
331334
for id in node_id
332-
union!(src_ids, inflow_ids(graph, id))
335+
src_id = inflow_id(graph, id)
336+
push!(src_ids, inflow_id(graph, id))
337+
338+
if !haskey(control_states, src_id)
339+
control_states[src_id] = Set{String}()
340+
end
341+
for (controlled_id, control_state) in keys(control_mapping)
342+
if controlled_id == id
343+
push!(control_states[src_id], control_state)
344+
end
345+
end
333346
end
334347

335348
node_id_set = Set{NodeID}(node_id)
336-
control_states = Set{String}([key[2] for key in keys(control_mapping)])
337349

338350
for src_id in src_ids
339351
src_outflow_ids = Set(outflow_ids(graph, src_id))
@@ -343,7 +355,7 @@ function valid_fractional_flow(
343355
end
344356

345357
# Each control state (including missing) must sum to 1
346-
for control_state in control_states
358+
for control_state in control_states[src_id]
347359
fraction_sum = 0.0
348360

349361
for ff_id in intersect(src_outflow_ids, node_id_set)

0 commit comments

Comments
 (0)