Technote (FAQ)
Question
There can be times when a model requires a decision variable to be continuous (as a float type) or discrete (as an int type) over a set of non-contiguous ranges. How do I formulate/declare such a decision variable?
Answer
Let us assume a particular use-case where decision variables in an integer array can only take integer values in the (1..6) or (9..10) range. You could model this requirement in OPL using one of the two approaches as shown in the following code snippet:
range i=1..5;
range x_all=1..10;
dvar int x[i] in x_all;
{int} x_no = {7,8};
{int} x_yes = {j|j in x_all: j not in x_no};
....
subject to{
//1st approach
forall(index in i){
forall(t in x_no){
x[index]!=t;
}
}
//2nd approach
forall(index in i){
sum(t in x_yes)(x[index]==t) == 1;
}
....
}
The decision variables are first declared to lie in the overall range of allowed values (1..10 in this case). The first approach involves adding logical constraints to disallow assigning values belonging to the x_no set (the set of dis-allowed values). The second approach forces the decision variables to be equal to only one value in the x_yes set (the set of allowed values).
If you are using the CP engine (indicated by the using CP; statement at the beginning of the mod file) instead of the CPLEX engine, then you could use the following simplified approach:
subject to{
//1st approach
forall(index in i){
x[index] not in x_no;
}
//2nd approach
forall(index in i){
x[index] in x_yes;
}
....
}
| Segment | Product | Component | Platform | Version | Edition |
|---|---|---|---|---|---|
| Business Integration | IBM ILOG CPLEX Optimization Studio | Area:Modelling new constraints and variables | AIX, Linux, Windows | 12.4, 12.3, 12.2.0.1, 12.2 | Edition Independent |
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.