quintel / refinery

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

Flexible edges sometimes ignore shares of siblings #60

Closed antw closed 4 years ago

antw commented 4 years ago

e3e3ba8 fixed a similar case where reversed flexible edges would ignore the share of sibling edges. This was easily fixed by disabling the Flexible strategy for reversed edges, however the same issue seems to affect non-reversed edges.

Step Image
Start 00000
1 00001
3 00003
Finished 99999
describe 'Graph calculations; with flex and two share siblings' do
  %w[mother child brother sister].each do |key|
    let!(key.to_sym) { graph.add(Refinery::Node.new(key.to_sym)) }
  end

  # The order of these edges is important. Connecting the M->C second or third
  # would trigger a bug where the Flexible strategy would use 100% of the [M]
  # demand, ignoring the shares set on the other edges. The bug would not be
  # triggered when the edge is connected first as it would calculate the
  # flexible before enough information was available from the other edges.

  let!(:mb_edge) { mother.connect_to(brother, :gas) }
  let!(:ms_edge) { mother.connect_to(sister, :gas) }

  let!(:mc_edge) do
    mother.connect_to(child, :gas, type: :flexible)
  end

  context 'when [CHILD] = 10, and [BROTHER] and [SISTER] have shares' do
    before do
      mother.set(:demand, 10)
      mb_edge.set(:parent_share, 0.4)
      ms_edge.set(:parent_share, 0.0)

      calculate! true
    end

    it 'sets demand of [BROTHER] to 4' do
      expect(brother).to have_demand.of(4)
    end

    it 'sets demand of [SISTER] to 0' do
      expect(sister).to have_demand.of(0)
    end

    it 'sets demand of [CHILD] to 6' do
      expect(child).to have_demand.of(6)
    end
  end
end
michieldenhaan commented 4 years ago

An example is changing the industry_final_demand_for_other_CARRIER-industry_final_demand_for_other_non_specified_CARRIER edges to flexible. See: https://github.com/quintel/etsource/commit/bcdb3d4333c7b876756e25cae2809dedfec746d5