Excel求解器,初始variables单元值影响求解器

我有以下问题:我需要通过改变另一个单元格的值,这需要一个整数,以最小化单元格。 我的Excel解算器有时可以正常工作,有时候它不能解决问题。 我注意到它取决于初始条件,所以根据初始可变单元值,求解器可能会find一个不是最优的解。

有什么想法呢?

附上你find运行解算器的VBA代码块。

Sub optimizer1() optimizer1 Macro SolverReset 'resetting solver SolverOk SetCell:="$AD$4", MaxMinVal:=2, ValueOf:=0, ByChange:="$Q$4", Engine:= _ 1, EngineDesc:="GRG Nonlinear" 'setting up target and input cell SolverAdd CellRef:="$Q$4", Relation:=4, FormulaText:="integer" 'The value of variable cell must be integer 'SolverAdd CellRef:="$U$4", Relation:=1, FormulaText:="$L$4" 'setting up the range (these are the boundary conditions) 'SolverAdd CellRef:="$U$4", Relation:=3, FormulaText:="$K$4" 'SolverAdd CellRef:="$AA$4", Relation:=1, FormulaText:="$L$4" 'SolverAdd CellRef:="$AA$4", Relation:=3, FormulaText:="$K$4" '(some Boundary conditions have been disabled, please neglect them for the purpose of the question) SolverOk SetCell:="$AD$4", MaxMinVal:=2, ValueOf:=0, ByChange:="$Q$4", Engine:= _ 1, EngineDesc:="GRG Nonlinear" SolverAdd CellRef:="$Q$4", Relation:=3, FormulaText:="$O$4" SolverOk SetCell:="$AD$4", MaxMinVal:=2, ValueOf:=0, ByChange:="$Q$4", Engine:= _ 1, EngineDesc:="GRG Nonlinear" ' Another boundary condition SolverOk SetCell:="$AD$4", MaxMinVal:=2, ValueOf:=0, ByChange:="$Q$4", Engine:= _ 1, EngineDesc:="GRG Nonlinear" SolverSolve UserFinish:=True End Sub 

谢谢!