我有一个使用Excel解算器运行多组排列的宏。每个宏运行解算器3次,使用Simplex,然后使用2 x Evolutionary。它似乎工作得相当好。
但是,我注意到解决方案不断变化,因为其中一个变量仅受最大值的约束。因此,我需要将变量设为最大/最小目标。
我知道Excel的解算器只允许一个最大/最小目标。有什么办法可以设定第二个最大/最小目标吗?
我的代码如下:
a = Range("Q1")
SolverReset
SolverOk SetCell:="$N$1", MaxMinVal:=1, ValueOf:=0, ByChange:="$M$2:$M" & a, _
Engine:=3, EngineDesc:="Simplex LP"
SolverAdd CellRef:="$O$1", Relation:=1, FormulaText:="80"
SolverAdd CellRef:="$M$1", Relation:=2, FormulaText:="8"
SolverAdd CellRef:="$P$1", Relation:=3, FormulaText:="5"
SolverOk SetCell:="$N$1", MaxMinVal:=1, ValueOf:=0, ByChange:="$M$2:$M" & a, _
Engine:=3, EngineDesc:="Simplex LP"
SolverAdd CellRef:="$M$2:$M" & a, Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$M$2:$M" & a, Relation:=1, FormulaText:="1"
SolverAdd CellRef:="$M$2:$M" & a, Relation:=3, FormulaText:="0"
SolverOk SetCell:="$N$1", MaxMinVal:=1, ValueOf:=0, ByChange:="$M$2:$M" & a, _
Engine:=3, EngineDesc:="Simplex LP"
SolverSolve ShowRef = 0
SolverReset
SolverOk SetCell:="$N$1", MaxMinVal:=1, ValueOf:=0, ByChange:="$M$2:$M" & a, _
Engine:=3, EngineDesc:="Evolutionary"
SolverAdd CellRef:="$O$1", Relation:=1, FormulaText:="80"
SolverAdd CellRef:="$M$1", Relation:=2, FormulaText:="8"
SolverAdd CellRef:="$P$1", Relation:=3, FormulaText:="5"
SolverOk SetCell:="$N$1", MaxMinVal:=1, ValueOf:=0, ByChange:="$M$2:$M" & a, _
Engine:=3, EngineDesc:="Evolutionary"
SolverAdd CellRef:="$M$2:$M" & a, Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$M$2:$M" & a, Relation:=1, FormulaText:="1"
SolverAdd CellRef:="$M$2:$M" & a, Relation:=3, FormulaText:="0"
SolverOk SetCell:="$N$1", MaxMinVal:=1, ValueOf:=0, ByChange:="$M$2:$M" & a, _
Engine:=3, EngineDesc:="Evolutionary"
SolverSolve ShowRef = 0
SolverReset
SolverOk SetCell:="$N$1", MaxMinVal:=1, ValueOf:=0, ByChange:="$M$2:$M" & a, _
Engine:=3, EngineDesc:="Evolutionary"
SolverAdd CellRef:="$O$1", Relation:=1, FormulaText:="80"
SolverAdd CellRef:="$M$1", Relation:=2, FormulaText:="8"
SolverAdd CellRef:="$P$1", Relation:=3, FormulaText:="5"
SolverOk SetCell:="$N$1", MaxMinVal:=1, ValueOf:=0, ByChange:="$M$2:$M" & a, _
Engine:=3, EngineDesc:="Evolutionary"
SolverAdd CellRef:="$M$2:$M" & a, Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$M$2:$M" & a, Relation:=1, FormulaText:="1"
SolverAdd CellRef:="$M$2:$M" & a, Relation:=3, FormulaText:="0"
SolverOk SetCell:="$N$1", MaxMinVal:=1, ValueOf:=0, ByChange:="$M$2:$M" & a, _
Engine:=3, EngineDesc:="Evolutionary"
SolverSolve ShowRef = 0
答案 0 :(得分:1)
您应将此视为一个顺序过程。
因此,您的第一个目标将会实现,并且通过将其最佳值添加到约束系统中,它将无法影响它。而且,只要它不影响之前的目标,你的第二个目标也将得到满足。
事实上,这样做可以添加任意数量的目标,并且可以通过词典顺序解决(对前一个目标给予更高的优先级)。