Solver in a loop bug

R1988

New Member
Joined
Apr 10, 2011
Messages
1
I am trying to implement solver in loop that will have 8 iterations. The solver works perfectly and gives the correct results until there is a scenario with no feasible solution. After that all iterations ignore my binary constraint and does not give me relevant results. If I try to run the solver manually with the constraints after the bad scenario it returns good solutions. Here is the loop:


For j = 0 To 7
Range("I22:I75").ClearContents
SolverReset
With Worksheets("Optimize")

SolverOk SetCell:="$F$16", MaxMinVal:=1, ValueOf:="0", ByChange:="$I$22:$I$35"
solveradd CellRef:="$I$22:$I$35", Relation:=5, FormulaText:="binary"
solveradd CellRef:="$I$19", Relation:=1, FormulaText:="1"
solveradd CellRef:="$I$19", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$J$40", Relation:=1, FormulaText:=Range("D5").offset(j, 0)
solveradd CellRef:="$J$40", Relation:=3, FormulaText:=Range("C5").offset(j, 0)
solveradd CellRef:="$L$27", Relation:=3, FormulaText:="0"
solveradd CellRef:="$M$27", Relation:=3, FormulaText:="0"
solveradd CellRef:="$N$27", Relation:=3, FormulaText:="0"
SolverOk SetCell:="$F$16", MaxMinVal:=1, ValueOf:="0", ByChange:="$I$22:$I$35"
SolverSolve userfinish:=True

End With

Worksheets("Optimize").Activate
If Range("I19") = 0 Then
Range("L31").offset(j, 0).Value = "No Soln"
ElseIf CInt(Range("I19").Value) = 1 Then

For i = 0 To Range("A22", Range("A22").End(xlDown)).Count - 1
If (Range("I22").offset(i, 0)) = 1 Then
Range("A22:H22").offset(i, 0).Copy
Range("L31").offset(j, 0).PasteSpecial (xlPasteValues)
End If
Next
End If

Next


Is there any known reason why solver would be doing this or is there something wrong with my logic? I have tested this a lot. The maximizing cell is the sum product of the binary values with some other values and the other constraints look like the following:
<table width="214" border="0" cellpadding="0" cellspacing="0"><col style="width: 80pt;" width="106"> <col style="width: 81pt;" width="108"> <tbody><tr style="height: 15.75pt;" height="21"> <td class="xl63" style="height: 15.75pt; width: 80pt;" width="106" align="right" height="21">
C5
$10,000,000.00</td> <td class="xl64" style="width: 81pt;" width="108" align="right">
D5
$20,000,000.00</td> </tr> <tr style="height: 15.75pt;" height="21"> <td class="xl63" style="height: 15.75pt;" align="right" height="21">$0.00</td> <td class="xl63" align="right">$10,000,000.00</td> </tr> <tr style="height: 15.75pt;" height="21"> <td class="xl63" style="height: 15.75pt;" align="right" height="21">-$10,000,000.00</td> <td class="xl63" align="right">$0.00</td> </tr> <tr style="height: 15.75pt;" height="21"> <td class="xl63" style="height: 15.75pt;" align="right" height="21">-$20,000,000.00</td> <td class="xl63" align="right">-$10,000,000.00</td> </tr> <tr style="height: 15.75pt;" height="21"> <td class="xl63" style="height: 15.75pt;" align="right" height="21">-$30,000,000.00</td> <td class="xl63" align="right">-$20,000,000.00</td> </tr> <tr style="height: 15.75pt;" height="21"> <td class="xl63" style="height: 15.75pt;" align="right" height="21">-$40,000,000.00</td> <td class="xl63" align="right">-$30,000,000.00</td> </tr> <tr style="height: 15.75pt;" height="21"> <td class="xl63" style="height: 15.75pt;" align="right" height="21">-$50,000,000.00</td> <td class="xl63" align="right">-$40,000,000.00</td> </tr> <tr style="height: 15.75pt;" height="21"> <td class="xl63" style="height: 15.75pt;" align="right" height="21">-$60,000,000.00</td> <td class="xl63" align="right">-$50,000,000.00</td> </tr> </tbody></table>
I19 is the sum of the binary column and needs to be 1 if there is a solution or should be zero otherwise and the other constraints are problem related but do not cause issues with feasibility for my current test cases. The if statements afterwords are just to record the results as the program iterates. Thanks!!!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,224,574
Messages
6,179,628
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top