VBA求解器不喜欢关注约束

我一直在试图使VBA中的求解器很好地处理命名范围的GRG非线性问题。 它是如此 – 它一直忽略二进制约束。 尝试跟随其他类似问题的post失败了。

Sub Solver() ' ' Solver Macro ' For solving once we have the data ' SolverReset 'Clearing out the old solver data, allows for named ranges to be used SolverAdd CellRef:=Range("VariableRange"), Relation:=1, FormulaText:=Range("One") ' Previous advice has been to used a range that ='s 1, as that can sometimes make things work. Part A SolverAdd CellRef:=Range("VariableRange"), Relation:=3, FormulaText:="0" 'Part B SolverAdd CellRef:=Range("VariableRange"), Relation:=4, FormulaText:="integer" 'Parts A and B along with this part are supposed to mimic the binary setting, in an attempt to get things working. SolverAdd CellRef:="$D$1", Relation:=1, FormulaText:="$D$2" 'D2 is my limit that D1 needs to stay inside of. SolverAdd CellRef:="$D$1", Relation:=3, FormulaText:="-$D$2" 'Could probably include an ABS on D1 to reduce VBA-ness. Either way, needs to fall within D2 SolverOk SetCell:="$A$1", MaxMinVal:=1, ValueOf:=0, ByChange:=Range("VariableRange"), _ Engine:=1, EngineDesc:="GRG Nonlinear" 'And now we TRY to solve SolverSolve UserFinish:=True 'I don't want to have to confirm to keep the results SolverFinish KeepFinal:=1 'And I'd like to keep the results! End Sub 

我的研究让我偶然发现Excel Solver忽略VBA中的约束以及其他线程。 我已经尝试过那个线程中的每个组合,而且我没有任何地方。

值得注意的是:我也尝试过使用手动方法来强制二进制 – sumproduct(range)= sum(range)必须是真的 – 但是这只是产生一切为0,这是无用的。