Originally posted by: SystemAdmin
Re: green hand ... no worries. I am coming up to speed on the details of OPL but have lots of experience troublshooting MIP/LP in general. So it is easier for me to explain with a .lp example than with OPL code, but the principle is exactly the same.
Suppose I had a model like
Min
obj:
1.5 UnitsProducedCleveland + 2.1 UnitsProducedNewYork +
2.3 UnitsShipClevelandToPortland + 0.9 UnitsShipClevelandToBaltimore +
4.1 UnitsShipNewYorkToPortland + 0.8 UnitsShipNewYorkToBaltimore
Subject To
"bunch of constraints"
So in the objective function the first line is the cost of production, the second and third lines are the cost of shipping.
You could easily rewrite this model as
Min
obj:
CostOfProduction + CostOfShipping
Subject To
CostOfProductionConstraint:
1.5 UnitsProducedCleveland + 2.1 UnitsProducedNewYork - CostOfProduction = 0
CostOfShippingConstraint:
2.3 UnitsShipClevelandToPortland + 0.9 UnitsShipClevelandToBaltimore +
4.1 UnitsShipNewYorkToPortland + 0.8 UnitsShipNewYorkToBaltimore
"bunch of constraints"
The second model is in general easier to trouble shoot. For example, if you're expecting the cost of production to be reasonably close to the cost of shipping, then the second model will let you verify that result much more easily.
CPLEX won't get hung up on these "extra variables" as a rule. CPLEX has a good pre-processor that simplifies them away. If you make 1,000,000 variables, and 800,000 of them are dummies, then perhaps you're overdoing it, but otherwise add the extra variables and constraints you need to make the model easy to read. Getting the correct results is the most important thing.
So in your example you could create a variable called PdAverage, then have a constraint somewhere in your model that was like
PdAverage - (sum(i in 1..T) Pd[i]+(sum(j in 1..N0) X[j][i]))/T = 0;
and then your objective function would be
minimize (sum(t in 1..T) pow(Pd[t]+(sum(k in 1..N0) X[k][t])- PdAverage ,2)/(T-1));
The part of the objective function that I called PdAverage is exactly the same for every t. So life will be easier if you pull that out and compute it in a dedicated variable.
Also perhaps the name PdAverage doesn't make sense. It seems like you're doing a big more there than just taking the average of Pd. Feel free to come up with longish variable names that are easy to read and describe things with some accuracy. A variable name that is 15-20 characters long would be ok for a tricky concept, and easier concepts can get shorter names.
And finally, even if you go overboard and decide you've made too many dummy variables, it's always easier to take a model that is working and gets correct results and rewrite it to be less verbose than it is to debug a really messy model that just isn't working.
Does that make sense?
#DecisionOptimization#OPLusingCPLEXOptimizer