@@ -315,7 +315,7 @@ function valid_pid_connectivity(
315
315
end
316
316
317
317
"""
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
319
319
outneighbor, that the fractions leaving a node add up to ≈1 and that the fractions are non-negative.
320
320
"""
321
321
function valid_fractional_flow (
@@ -328,12 +328,24 @@ function valid_fractional_flow(
328
328
# Node IDs that have fractional flow outneighbors
329
329
src_ids = Set {NodeID} ()
330
330
331
+ # The set of control states associated with each source node
332
+ control_states = Dict {NodeID, Set{String}} ()
333
+
331
334
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
333
346
end
334
347
335
348
node_id_set = Set {NodeID} (node_id)
336
- control_states = Set {String} ([key[2 ] for key in keys (control_mapping)])
337
349
338
350
for src_id in src_ids
339
351
src_outflow_ids = Set (outflow_ids (graph, src_id))
@@ -343,7 +355,7 @@ function valid_fractional_flow(
343
355
end
344
356
345
357
# 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]
347
359
fraction_sum = 0.0
348
360
349
361
for ff_id in intersect (src_outflow_ids, node_id_set)
0 commit comments