Hello Mr. Excel
I've been working on some solver model that has grown to 40 decision variables and about 60 constraints. It is a model that determines how to split some power demand over several engines, resulting in the lowest fuel consumption.
One problem is that this creates many local minima, that I've tried to overcome by setting several starting values. All these starting values are in the feasible area; they obey the constraints. Then when I run the solver, for some reason some of the values are set outside the constraints. This gives an error in the sheet, so the solution fails.
The code is rather large, but I think it helps if I post it anyway:
Some info to clarify:
- The variables are in in column $M
- Con1_ME_Max_Load1*Con1_ME_Pb1 means the maximum loading of the engines. That is 90% brake power. These values are in the sheet and are just integers. A watch in the VBA editor shows correct values for these.
- The Pprop and Pel variables are the demand. The decision variables should meet these demand, through the given constraints.
- The error I get seems to be when the constraint
is close to the Pprop power demand.
Maybe it conflicts with this constraint or something
but then why does it happen only if the constraint is close to the demand? It works fine on all other lines.
Sorry for the rather long post, but I've spent about all my friday afternoon on this and still couldn't get it to work without errors.
If I need to clarify some more, please say so.
Any help would be greatly appreciated.
Bas
I've been working on some solver model that has grown to 40 decision variables and about 60 constraints. It is a model that determines how to split some power demand over several engines, resulting in the lowest fuel consumption.
One problem is that this creates many local minima, that I've tried to overcome by setting several starting values. All these starting values are in the feasible area; they obey the constraints. Then when I run the solver, for some reason some of the values are set outside the constraints. This gives an error in the sheet, so the solution fails.
The code is rather large, but I think it helps if I post it anyway:
Code:
Sub Solver1()
'
' Macro1 Macro
'Starting point determines the best solution
solverreset
'add all constraints
' relation 1 = "<="
' relation 2 = "="
' relation 3 = ">="
' relation 4 = "integer"
' relation 5 = "binary"
'engines can't be negative
SolverAdd CellRef:="$M$18:$M$20", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$M$22:$M$24", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$M$26:$M$28", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$M$30:$M$32", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$M$34:$M$36", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$M$38:$M$40", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$M$42:$M$44", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$M$46:$M$48", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$M$50:$M$52", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$M$54:$M$56", Relation:=3, FormulaText:="0"
'engines can't deliver more than Pbrake, including engine margin
'ME 1
SolverAdd CellRef:="$M$18", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
SolverAdd CellRef:="$M$22", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
SolverAdd CellRef:="$M$26", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
SolverAdd CellRef:="$M$30", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
SolverAdd CellRef:="$M$34", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
SolverAdd CellRef:="$M$38", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
SolverAdd CellRef:="$M$42", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
SolverAdd CellRef:="$M$46", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
SolverAdd CellRef:="$M$50", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
SolverAdd CellRef:="$M$54", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
'ME 2
SolverAdd CellRef:="$M$19", Relation:=1, FormulaText:="Con1_ME_Max_Load2*Con1_ME_Pb2"
SolverAdd CellRef:="$M$23", Relation:=1, FormulaText:="Con1_ME_Max_Load2*Con1_ME_Pb2"
SolverAdd CellRef:="$M$27", Relation:=1, FormulaText:="Con1_ME_Max_Load2*Con1_ME_Pb2"
SolverAdd CellRef:="$M$31", Relation:=1, FormulaText:="Con1_ME_Max_Load2*Con1_ME_Pb2"
SolverAdd CellRef:="$M$35", Relation:=1, FormulaText:="Con1_ME_Max_Load2*Con1_ME_Pb2"
SolverAdd CellRef:="$M$39", Relation:=1, FormulaText:="Con1_ME_Max_Load2*Con1_ME_Pb2"
SolverAdd CellRef:="$M$43", Relation:=1, FormulaText:="Con1_ME_Max_Load2*Con1_ME_Pb2"
SolverAdd CellRef:="$M$47", Relation:=1, FormulaText:="Con1_ME_Max_Load2*Con1_ME_Pb2"
SolverAdd CellRef:="$M$51", Relation:=1, FormulaText:="Con1_ME_Max_Load2*Con1_ME_Pb2"
SolverAdd CellRef:="$M$55", Relation:=1, FormulaText:="Con1_ME_Max_Load2*Con1_ME_Pb2"
'diesel generator sets
SolverAdd CellRef:="$M$20", Relation:=1, FormulaText:="Con1_DG_Max_Load*Con1_DG_Pbtot"
SolverAdd CellRef:="$M$24", Relation:=1, FormulaText:="Con1_DG_Max_Load*Con1_DG_Pbtot"
SolverAdd CellRef:="$M$28", Relation:=1, FormulaText:="Con1_DG_Max_Load*Con1_DG_Pbtot"
SolverAdd CellRef:="$M$32", Relation:=1, FormulaText:="Con1_DG_Max_Load*Con1_DG_Pbtot"
SolverAdd CellRef:="$M$36", Relation:=1, FormulaText:="Con1_DG_Max_Load*Con1_DG_Pbtot"
SolverAdd CellRef:="$M$40", Relation:=1, FormulaText:="Con1_DG_Max_Load*Con1_DG_Pbtot"
SolverAdd CellRef:="$M$44", Relation:=1, FormulaText:="Con1_DG_Max_Load*Con1_DG_Pbtot"
SolverAdd CellRef:="$M$48", Relation:=1, FormulaText:="Con1_DG_Max_Load*Con1_DG_Pbtot"
SolverAdd CellRef:="$M$52", Relation:=1, FormulaText:="Con1_DG_Max_Load*Con1_DG_Pbtot"
SolverAdd CellRef:="$M$56", Relation:=1, FormulaText:="Con1_DG_Max_Load*Con1_DG_Pbtot"
'engine cylinder numbers between specified in catalog (not yet)
'making cyls part of changing cells doesn't work
'instead, test multiple engine configurations parallel (more solvers at once)
'Interaction between PTO, PTI and engines
'kW EM = P el - kW DG
SolverAdd CellRef:="$M$21", Relation:=2, FormulaText:="P_el1-$M20"
SolverAdd CellRef:="$M$25", Relation:=2, FormulaText:="P_el2-$M24"
SolverAdd CellRef:="$M$29", Relation:=2, FormulaText:="P_el3-$M28"
SolverAdd CellRef:="$M$33", Relation:=2, FormulaText:="P_el4-$M32"
SolverAdd CellRef:="$M$37", Relation:=2, FormulaText:="P_el5-$M36"
SolverAdd CellRef:="$M$41", Relation:=2, FormulaText:="P_el6-$M40"
SolverAdd CellRef:="$M$45", Relation:=2, FormulaText:="P_el7-$M44"
SolverAdd CellRef:="$M$49", Relation:=2, FormulaText:="P_el8-$M48"
SolverAdd CellRef:="$M$53", Relation:=2, FormulaText:="P_el9-$M52"
SolverAdd CellRef:="$M$57", Relation:=2, FormulaText:="P_el10-$M56"
'kW EM = kW ME - P prop
SolverAdd CellRef:="$M$21", Relation:=2, FormulaText:="$M$18+$M$19-P_prop1"
SolverAdd CellRef:="$M$25", Relation:=2, FormulaText:="$M$22+$M$23-P_prop2"
SolverAdd CellRef:="$M$29", Relation:=2, FormulaText:="$M$26+$M$27-P_prop3"
SolverAdd CellRef:="$M$33", Relation:=2, FormulaText:="$M$30+$M$31-P_prop4"
SolverAdd CellRef:="$M$37", Relation:=2, FormulaText:="$M$34+$M$35-P_prop5"
SolverAdd CellRef:="$M$41", Relation:=2, FormulaText:="$M$38+$M$39-P_prop6"
SolverAdd CellRef:="$M$45", Relation:=2, FormulaText:="$M$42+$M$43-P_prop7"
SolverAdd CellRef:="$M$49", Relation:=2, FormulaText:="$M$46+$M$47-P_prop8"
SolverAdd CellRef:="$M$53", Relation:=2, FormulaText:="$M$50+$M$51-P_prop9"
SolverAdd CellRef:="$M$57", Relation:=2, FormulaText:="$M$54+$M$55-P_prop10"
SolverOptions MaxTime:=100, Iterations:=100, Precision:=0.001, AssumeLinear _
:=False, StepThru:=False, Estimates:=1, Derivatives:=1, SearchOption:=1, _
IntTolerance:=0.01, Scaling:=False, Convergence:=0.0001, AssumeNonNeg:=False
SolverOk SetCell:="$M62", MaxMinVal:=2, ValueOf:="0", ByChange:="$M$18:$M$57"
SolverSolve True
End sub
Some info to clarify:
- The variables are in in column $M
- Con1_ME_Max_Load1*Con1_ME_Pb1 means the maximum loading of the engines. That is 90% brake power. These values are in the sheet and are just integers. A watch in the VBA editor shows correct values for these.
- The Pprop and Pel variables are the demand. The decision variables should meet these demand, through the given constraints.
- The error I get seems to be when the constraint
Code:
SolverAdd CellRef:="$M$42", Relation:=1, FormulaText:="Con1_ME_Max_Load1*Con1_ME_Pb1"
Maybe it conflicts with this constraint or something
Code:
SolverAdd CellRef:="$M$45", Relation:=2, FormulaText:="$M$42+$M$43-P_prop7"
Sorry for the rather long post, but I've spent about all my friday afternoon on this and still couldn't get it to work without errors.
If I need to clarify some more, please say so.
Any help would be greatly appreciated.
Bas