简体   繁体   中英

Solver Excel VBA Integer Constraint Ignored

I've looked through as many examples on here as I think there are but for some reason in my code the integer portion of it is being ignored. Underneath the 1st "SolverAdd, you'll see the other 2 that I've tried to use as well but each time the integer requirement is ignored. Any idea what I am doing wrong ? Thanks!

SolverReset
SolverOk SetCell:="$T$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$R$8:$R$13" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
'Solver ignores integer requirement for the reference range
SolverAdd CellRef:="$R$8:$R$13", Relation:=4, FormulaText:="integer"
'Have tried this: SolverAdd CellRef:="$R$8:$R$13", Relation:=4
'Have also tried this: SolverAdd CellRef:="$R$8:$R$13", Relation:=4, FormulaText:=0
SolverSolve True

Have also tried this:

SolverReset
SolverOk SetCell:="$T$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$R$8:$R$13" _
, Engine:=1, EngineDesc:="GRG Nonlinear"
'Solver ignores integer requirement for the reference range
SolverAdd CellRef:=Range("$R$8:$R$13"), _
Relation:=4
SolverSolve True

I thought the constraint was built into the "MaxMinVal" portion of the solver code.

I manually added both constraints with the range of T4 being maxed a 1.000000000001 since just having "1" causes issues from what I've seen.

SolverReset
SolverOk SetCell:=Range("$T$4"), MaxMinVal:=1, ByChange:=Range("$R$8:$R$13") _
, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:=Range("$R$8:$R$13"), _
Relation:=4
SolverAdd CellRef:=Range("$T$4"), _
Relation:=1, FormulaText:="1.00000000001"

FormulaText:=0 SolverSolve True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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