【发布时间】:2014-07-15 00:29:50
【问题描述】:
我的求解器 vba 代码在 Windows (Excel 2013) 上运行良好,但在 macOS 上使用 Excel 2011 时存在一些问题。这是代码:
SolverReset
SolverAdd CellRef:="$CB$2:$CB$" & LastRow, Relation:=5, FormulaText:="binary"
SolverAdd CellRef:="$CA$3", Relation:=1, FormulaText:="100000"
SolverAdd CellRef:="$CA$10", Relation:=2, FormulaText:="8"
SolverAdd CellRef:="$CA$7", Relation:=3, FormulaText:="3"
SolverAdd CellRef:="$CA$8", Relation:=3, FormulaText:="3"
SolverAdd CellRef:="$CA$9", Relation:=2, FormulaText:="=1"
SolverOptions MaxTime:=100, Iterations:=100, precision:=0.000001, Convergence:= _
0.0001, StepThru:=False, Scaling:=False, AssumeNonNeg:=True, Derivatives:=1
SolverOptions PopulationSize:=100, RandomSeed:=0, MutationRate:=0.075, Multistart _
:=False, RequireBounds:=True, MaxSubproblems:=0, MaxIntegerSols:=0, _
IntTolerance:=0, SolveWithout:=False, MaxTimeNoImp:=30
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow,
_ Engine:=2, EngineDesc:="Simplex LP"
SolverSolve
问题是应用上述代码后求解器缺少以下条件:
SolverAdd CellRef:="$CB$2:$CB$" & LastRow, Relation:=5, FormulaText:="binary"
SolverOk SetCell:="$CA$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$CB$2:$CB$" & LastRow,
_ Engine:=2, EngineDesc:="Simplex LP"
一个有趣的事情是,只有 SetCell 和 ByChange 不是从第二个条件设置的,但引擎类型“Simplex LP”很好。 我是通过录制手动设置的宏来获取代码的,所以应该没有任何问题。
【问题讨论】: