Technote (FAQ)
Question
How to extract constraint relaxation information from IloOplRelaxationIterator in OPL Script?
Answer
Currently, the constraint relaxation information are stored as properties info, info2 and info3. Properties info and info2 store the original bounds and the relaxed bounds as strings. Property info3 stores the new bounds as numbers.
The below is an improved version of sample relaxationIterator that demonstrates how to extract the relaxation information from info, info2 and info3.
range r = 1..10;
dvar int+ x[r] in 1..10;
// Preferences are stated as data of the opl model.
// prefs[i] will be used to represent the preference of seeing cts[i] in the relaxation.
float prefs[i in r] = i;
minimize sum(i in r) x[i];
subject to {
ct: sum(i in r) x[i] >= 10;
forall(i in r)
cts: x[i] >= i+5;
}
main {
thisOplModel.generate();
var def = thisOplModel.modelDefinition;
// Default behavior
writeln("Default Behavior");
var cons = new Array ();
var changeLB = new Array();
var vals = new Array ();
var count = 0;
var iter = opl1.relaxationIterator;
for(var c in iter)
{
var ct=c.ct;
writeln(ct.name);
writeln("info = ",c.info);
writeln("info2 = ",c.info2);
writeln("info3 = ",c.info3);
var info_index=c.info.indexOf(",");
var info2_index=c.info2.indexOf(",");
if (c.info.substring(0, info_index)!=c.info2.substring(0,
info2_index)) {
writeln("Lower bound changed");
//lower bound changed
cons[count]=ct;
changeLB[count] = true;
vals[count]=c.info3;
count++;
}
else if
(c.info.substring(info_index)!=c.info2.substring(info2_index)) {
writeln("Upper bound changed");
//upper bound changed
cons[count]=ct;
changeLB[count] = false;
vals[count]=c.info3;
count++;
}
}
for (var i =0; i<cons.length; i++){
if (changeLB[i]) {
cons[i].LB=vals[i];
} else {
cons[i].UB=vals[i];
}
}
cplex1.solve();
}
In the above codes, info and info2 are treated as strings. By checking whether the lower bound or the upper bound is changed, it determines whether the lower bound or the upper bound should be modified. Then the modification information (constraint, Upper bound or lower bound to be modified, and the new bound) will be stored in arrays first. Then all the modifications are applied together in the end.
| Segment | Product | Component | Platform | Version | Edition |
|---|---|---|---|---|---|
| Business Integration | IBM ILOG OPL-CPLEX Development Bundles | Platform Independent | 12.2, 12.3, 12.4 | All Editions |
Rate this page:
Copyright and trademark information
IBM, the IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.