LowInventoryGuess = 0
HighInventoryGuess = TankFull
InitInv = LowInventoryGuess
For j = 1 To 10
StartInv.Value = InitInv
'Calculate results, and return them to array X
x = Perf(InputData, MilitaryHours, OKtoRun, BldgLoad, InputUnits, _
OutputUnits, MinInv, FinalInv, TotalProduction)
'Exit sub if results meet goal: final inventory near initial
'Capacity, MinInv & FinalInv all measured in input units
FinalInv = FinalInv * (OutputEnergyFactor / InputEnergyFactor)
MinInv = MinInv * (OutputEnergyFactor / InputEnergyFactor)
InitialInventoryOK = FinalInv >= InitInv And FinalInv - InitInv <= Capacity
MinimumInventoryOK = MinInv >= 0
'
'Display iteration counter & latest initial inventory on status bar
GoalChk = Format(InitInv, "#,##0") & " InitInvOK " & InitialInventoryOK _
& " MinInvOK " & MinimumInventoryOK
Application.StatusBar = "Iteration" & Str(i + j) & " Starting Inventory=" & GoalChk
If FinalInv >= InitInv Then
LowInventoryGuess = InitInv '*************
InitInv = (HighInventoryGuess + LowInventoryGuess) / 2
Else
If j = 1 Then
'Convergence impossible. Restore screen updating, but leave status bar unchanged
Results.Value = x 'Update Results section with most recent calculation values
SmartFormatter 'Reformat the loads, capacity & inventory (if necessary)
Application.ScreenUpdating = True
Msg = "Problem either MaximICE/compressor limited or tank limited. Increase one or the other"
MsgBox Msg, vbExclamation
Exit Sub
Else
HighInventoryGuess = InitInv '************
InitInv = (HighInventoryGuess + LowInventoryGuess) / 2
End If
|