quintel / refinery

Calculates node demands and edge shares for sparse energy graphs.
2 stars 0 forks source link

when all the demands of a certain set of nodes are zero, the corresponding input ratio between them should be determined #58

Closed grdw closed 6 years ago

grdw commented 6 years ago

Assume graph as:

screen shot 2018-05-07 at 15 42 35

Whent the demand of A,B,C = 0. The input slot ratio of D (input slot A-D, B-D, C-D) should be able to calculate and not throw a "SystemStackError: stack level too deep".

Suggestions for solving this:

Related issue: https://github.com/quintel/etlocal/issues/73

grdw commented 6 years ago

How does https://github.com/quintel/refinery/commit/90cc27ef67e620d8d26e80097d8408a31fbce3fb this actually work? recursing is never ever set to true is it?

antw commented 6 years ago

recursing is never ever set to true is it?

It is on line 100, when calling share on the other slots:

098 |            set(:share, 0.0)
099 |          elsif ! recursing && node_demand.zero? &&
100 |                others.all? { |o| o.share(true) }
### |                                  ^^^^^^^^^^^^^
101 |            # Opposite of the special case above.
102 |            set(:share, 1.0 - others.sum(&:share))
103 |          elsif ! node_demand.zero?

The stack would overflow when demands were zero because slot A would try to look at the share of slot B, which would look at slot A, which would look at slot B, ad infinitum... We break that loop (line 99) by setting recursing to true.