public void InventorySpaceUpperBound_InventoryDependentInjectWithdrawRate_ConsistentWithGetInjectWithdrawRange() { const double inventoryPercentLoss = 0.03; const double minInventory = 0.0; const double maxInventory = 1000.0; var injectWithdrawalRanges = new List <InjectWithdrawRangeByInventory> { (inventory : 0.0, (minInjectWithdrawRate : -44.85, maxInjectWithdrawRate : 56.8)), // Inventory empty, highest injection rate (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)) // Inventory full, highest withdrawal rate }; var polynomialInjectWithdrawConstraint = new PolynomialInjectWithdrawConstraint(injectWithdrawalRanges); const double nextPeriodMinInventory = 320.0; const double nextPeriodMaxInventory = 620.0; double thisPeriodMaxInventory = polynomialInjectWithdrawConstraint.InventorySpaceUpperBound(nextPeriodMinInventory, nextPeriodMaxInventory, minInventory, maxInventory, inventoryPercentLoss); double thisPeriodMaxWithdrawalRateAtInventory = polynomialInjectWithdrawConstraint .GetInjectWithdrawRange(thisPeriodMaxInventory).MinInjectWithdrawRate; double derivedNextPeriodMaxInventory = thisPeriodMaxInventory * (1 - inventoryPercentLoss) + thisPeriodMaxWithdrawalRateAtInventory; Assert.Equal(nextPeriodMaxInventory, derivedNextPeriodMaxInventory, 12); }
public void InventorySpaceLowerBound_ConstantInjectWithdrawRate_EqualsNextPeriodInventoryMinusMaxInjectRateAdjustedForLoss() { const double maxInjectionRate = 56.8; const double maxWithdrawalRate = 47.12; var injectWithdrawRange = new InjectWithdrawRange(-maxWithdrawalRate, maxInjectionRate); const double inventoryPercentLoss = 0.03; const double minInventory = 0.0; const double maxInventory = 1000.0; var injectWithdrawalRanges = new List <InjectWithdrawRangeByInventory> { (inventory : 0.0, injectWithdrawRange), (inventory : 100.0, injectWithdrawRange), (inventory : 300.0, injectWithdrawRange), (inventory : 600.0, injectWithdrawRange), (inventory : 800.0, injectWithdrawRange), (inventory : 1000.0, injectWithdrawRange), }; var polynomialInjectWithdrawConstraint = new PolynomialInjectWithdrawConstraint(injectWithdrawalRanges); const double nextPeriodMinInventory = 620.0; const double nextPeriodMaxInventory = 870.0; double thisPeriodMinInventory = polynomialInjectWithdrawConstraint.InventorySpaceLowerBound(nextPeriodMinInventory, nextPeriodMaxInventory, minInventory, maxInventory, inventoryPercentLoss); const double expectedThisPeriodMinInventory = (nextPeriodMinInventory - maxInjectionRate) / (1 - inventoryPercentLoss); Assert.Equal(expectedThisPeriodMinInventory, thisPeriodMinInventory, 12); }