public void CalculateBangBangDecisionSet_InjectWithdrawRangeBothPositiveUnconstrainedWithExtraDecisions_ReturnsMinAndMaxRateWithExtraDecisions() { var injectWithdrawRange = new InjectWithdrawRange(15.5, 65.685); const double currentInventory = 1010.0; const double inventoryLoss = 10.0; const double nextStepMinInventory = 900.0; const double nextStepMaxInventory = 1070.0; const int numExtraDecisions = 1; double[] decisionSet = StorageHelper.CalculateBangBangDecisionSet(injectWithdrawRange, currentInventory, inventoryLoss, nextStepMinInventory, nextStepMaxInventory, NumericalTolerance, numExtraDecisions); double[] expectedDecisionSet = new[] { injectWithdrawRange.MinInjectWithdrawRate, (injectWithdrawRange.MinInjectWithdrawRate + injectWithdrawRange.MaxInjectWithdrawRate) / 2.0, injectWithdrawRange.MaxInjectWithdrawRate }; Assert.Equal(expectedDecisionSet, decisionSet); }
public void CalculateBangBangDecisionSet_NextStepInventoryConstrainsWithdrawalHigherThanCurrentNoExtraDecisions_ReturnsArrayWithTwoValuesNoneZero() { var injectWithdrawRange = new InjectWithdrawRange(-15.5, 65.685); const double currentInventory = 1010.0; const double inventoryLoss = 10.0; const double nextStepMinInventory = 1001.8; const double nextStepMaxInventory = 1009.51; const int numExtraDecisions = 0; double[] decisionSet = StorageHelper.CalculateBangBangDecisionSet(injectWithdrawRange, currentInventory, inventoryLoss, nextStepMinInventory, nextStepMaxInventory, NumericalTolerance, numExtraDecisions); double expectedWithdrawalRate = nextStepMaxInventory - currentInventory + inventoryLoss; double expectedInjectionRate = nextStepMinInventory - currentInventory + inventoryLoss; // Negative injection, i.e. withdrawal double[] expectedDecisionSet = new[] { expectedInjectionRate, expectedWithdrawalRate }; Assert.Equal(expectedDecisionSet, decisionSet); }
CalculateBangBangDecisionSet_NextStepInventoryConstrainsInjectionAndWithdrawalAroundCurrentInventoryExtraDecisions_ReturnsAdjustedInjectWithdrawRangeZeroAndExtraDecisions() // TODO rename! { var injectWithdrawRange = new InjectWithdrawRange(-15.5, 65.685); const double currentInventory = 1010.0; const double inventoryLoss = 10.0; const double nextStepMinInventory = 991.87; const double nextStepMaxInventory = 1051.8; const int numExtraDecisions = 1; double[] decisionSet = StorageHelper.CalculateBangBangDecisionSet(injectWithdrawRange, currentInventory, inventoryLoss, nextStepMinInventory, nextStepMaxInventory, NumericalTolerance, numExtraDecisions); double expectedWithdrawalRate = nextStepMaxInventory - currentInventory + inventoryLoss; double expectedInjectionRate = nextStepMinInventory - currentInventory + inventoryLoss; double[] expectedDecisionSet = new[] { expectedInjectionRate, expectedInjectionRate / 2.0, 0.0, expectedWithdrawalRate / 2.0, expectedWithdrawalRate }; Assert.Equal(expectedDecisionSet, decisionSet); }
public void GetInjectWithdrawRange_InventoryDependentInjectWithdrawRate_EqualToInputsAtInventoryPillars() { var injectWithdrawalRanges = new List <InjectWithdrawRangeByInventory> { (inventory : 0.0, (minInjectWithdrawRate : -44.85, maxInjectWithdrawRate : 56.8)), (inventory : 100.0, (minInjectWithdrawRate : -45.01, maxInjectWithdrawRate : 54.5)), (inventory : 300.0, (minInjectWithdrawRate : -45.78, maxInjectWithdrawRate : 52.01)), (inventory : 600.0, (minInjectWithdrawRate : -46.17, maxInjectWithdrawRate : 51.9)), (inventory : 800.0, (minInjectWithdrawRate : -46.99, maxInjectWithdrawRate : 50.8)), (inventory : 1000.0, (minInjectWithdrawRate : -47.12, maxInjectWithdrawRate : 50.01)) }; var linearInjectWithdrawConstraint = new PiecewiseLinearInjectWithdrawConstraint(injectWithdrawalRanges); foreach ((double inventoryPillar, InjectWithdrawRange inputInjectWithdrawRange) in injectWithdrawalRanges) { InjectWithdrawRange outputInjectWithdrawRange = linearInjectWithdrawConstraint.GetInjectWithdrawRange(inventoryPillar); Assert.Equal(inputInjectWithdrawRange.MinInjectWithdrawRate, outputInjectWithdrawRange.MinInjectWithdrawRate); Assert.Equal(inputInjectWithdrawRange.MaxInjectWithdrawRate, outputInjectWithdrawRange.MaxInjectWithdrawRate); } }