VBA control of Solver with variable bychange cells

jerH

Board Regular
Joined
Dec 3, 2008
Messages
168
A few months ago I built a solver tool for work that optimized cuts to various projects. Given the number of projects, the number of decision variables was greater than standard solver could handle, so I used Premium Solver Platform from Frontline and it all worked great. So well in fact, that I've been asked to basically build the whole thing over again, but this time for a smaller number of projects so that it can be done with standard solver, and thus shared widely in the organization rather than only to those of us who have Premium Solver Platform licenses.

The data setup looks like this:

ProjectWeightStartFinishRed CutTakenOrange Cut Taken?Yellow CutTakenGreen CutTakenTotal Cuts
A0.1Green?00-1000000-50000
B0.25Yellow?-500000000000
C0.05Orange?-100000000000
D0.15Yellow?-2500000-2500000
etc

<tbody>
</tbody>

So the idea is that the different projects are weighted, and they having a starting "risk status" in the start column. The "cut" columns represent dollars that can be taken from these projects' budgets and leave them in the corresponding risk category. So for instance Project A is currently green, and the project manager has identified a $1000 cut that will make it orange, and a $500 cut that will still leave it green. Not every cut column will have a value. The "taken" columns are the decision variables and will be binary, and if there is no cut identified, there won't be a decision variable added to the model. There will be "cascading" constraints, so for example in Project A you can't take the $1000 orange cut unless you also take the $500 green cut. Project D can't take the $2500 red cut unless it first takes the $250 yellow cut, etc. There is a "roll up" rule that gives an overall risk color to the set of projects, based on the colors of the individual projects and their weights. The goal of the optimization will be to maximize the dollars cut and leave the overall set at each of the different risk colors.

If you're still reading, thank you!

Here's where I need help...or at least some advice before I embark on coding this. With the API for Premium Solver Platform, you don't have to specify the bychange parameter in the solverok call. You could just loop your way along making calls that looked like:

Code:
solveradd cellref:="$M$" & i+1
solveradd cellref:="$M$" & i+1, relation:=5, formulatext:=binary

to add your decision variables, and calls like:

Code:
solveradd cellref:="$M$" & i+1, relation:=1, formulatext:=$I$" & i+1

to handle the "cascading" constraints. And when you got to the end you could call

Code:
solverok setcell:=$Q$12", MaxMinVal:=2, ValueOf:="0", Engine:=3
set some options
solversolve

and all your binary variables would be there complete with their cascading constraints.

I don't believe it works this way with the standard solver, does it? Do I first need to loop through and identify all of the decision cells and concatenate them all together into a string and call

Code:
solverok setcell:=blah, MaxMinVal:=2, ValueOf:=0, ByChange:=decision_variable_string, Engine:=3

so that I can get them all into the model, and then loop through again and add all the binary and cascading constraints?

I hope this question makes sense....please feel free to hit me up for clarification.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,215,497
Messages
6,125,158
Members
449,208
Latest member
emmac

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