简体   繁体   English

Excel 求解器中的多个目标

[英]Multiple objectives in Excel solver

I have a macro that runs through multiple sets of permutations using Excel's solver.我有一个宏,它使用 Excel 的求解器运行多组排列。 Each macro runs the solver 3 times, using Simplex followed by 2 x Evolutionary.每个宏运行求解器 3 次,使用 Simplex,然后使用 2 x Evolutionary。 It seems to work reasonably well.它似乎工作得相当好。

However, I noticed that the solution keeps changing, due to one of the variables only being constrained by a maximum value.但是,我注意到解决方案不断变化,因为其中一个变量仅受最大值约束。 As such, I need to make the variable a max/min objective.因此,我需要将变量设为最大/最小目标。

I know that Excel's solver only allows for one max/min objective.我知道 Excel 的求解器只允许一个最大/最小目标。 Is there any way that I can set a second max/min objective?有什么办法可以设置第二个最大/最小目标吗?

The code I have is as follows:我的代码如下:

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

You shall see this as a sequential process.您将看到这是一个连续的过程。

  1. Obtain the initial optimal solution.得到初始最优解。
  2. Add the optimal value to the system of constraints.将最优值添加到约束系统中。
  3. Solve again the whole problem, but with your new objective wich would be to maximize (or minimize) your variable of interest.再次解决整个问题,但您的新目标是最大化(或最小化)您感兴趣的变量。

So your first objective will be fulfilled, and by adding it's optimal value to the system of constraints it won't be possible to affect it.因此,您的第一个目标将实现,并且通过将其最佳值添加到约束系统中,将不可能影响它。 And then, as long as it doesn't interfere with the previous objective, your second objective will also be fulfilled.然后,只要不干扰前一个目标,你的第二个目标也会实现。

In fact, doing so you could add as many objectives as you want and they would be solve with a lexicographic order (higher priority given to the previous objective).事实上,这样做你可以根据需要添加任意数量的目标,它们将按照字典顺序解决(前一个目标具有更高的优先级)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM