Is it possible for "alwaysIn" (state functions) select from set of values?

71 Views Asked by At

State functions looks like the best option for modeling my situation.

The image as it is now

Now interval variable X might be in range of state functin from 'vmin' to 'vmax'.

But in my situation any interval variable is related to set of states and this states are not going in order.

For example, interval "product_1_Interval" is related to states 1 and 3. And not allowed in state 2. But interval "product_2_Interval" is related to states 2 and 3.

My desirable situation is this one: the image about how it should be

OPL Code example:

stateFunction myStateFunction;
dvar interval product_1_Interval;
dvar interval product_2_Interval;

subject to
{
alwaysConstant (myStateFunction, 0, 155);
alwaysConstant (myStateFunction, 156, 310);

/* Below need constraint that interval variable product_1_Interval might be in state 1 or 3 */
/* Below need constraint that interval variable product_2_Interval might be in state 2 or 3 */

}

I've tried to write something like:

alwaysEqual(myStateFunction, product_1_Interval,  1) or alwaysEqual(myStateFunction, product_1_Interval,  3);

But I got an error "Exception in presolve: Constraint 'alwaysEqual' is a top level constraint, it cannot be used in an expression..".

My question: Is it possible now in CPLEX Solver to model situation when an interval variable relates to some set of states (stateFunction) which are not going in order?

1

There are 1 best solutions below

6
Alex Fleischer On

I would use alternative and write

using CP;

{int} options={1,3};

stateFunction myStateFunction;
dvar interval product_1_Interval;
dvar interval product_1_Interval_v[options] optional in 0..100 size 100 ;

dvar interval product_2_Interval in 0..10;


subject to
{
alwaysConstant (myStateFunction, 0, 155);
alwaysConstant (myStateFunction, 156, 310);

alternative(product_1_Interval,all(v in options)product_1_Interval_v[v]);

/* Below need constraint that interval variable product_1_Interval might be in state 1 or 3 */
/* Below need constraint that interval variable product_2_Interval might be in state 2 or 3 */


//alwaysEqual(myStateFunction, product_1_Interval,  1) or alwaysEqual(myStateFunction, product_1_Interval,  3);

forall(v in options)alwaysEqual(myStateFunction,product_1_Interval_v[v],  v);


}

execute
{
  writeln(myStateFunction);
}

and to get something like you look for

using CP;

{int} options={1,3};

stateFunction myStateFunction;
dvar interval product_1_Interval size 150;
dvar interval product_1_Interval_v[options]  optional;

dvar interval product_2_Interval size 150;
dvar interval product_2_Interval_v[options]  optional;

subject to
{
alwaysConstant (myStateFunction, 0, 155);
alwaysConstant (myStateFunction, 156, 310);

endAtStart(product_1_Interval,product_2_Interval,1);

alternative(product_1_Interval,all(v in options)product_1_Interval_v[v]);
alternative(product_2_Interval,all(v in options)product_2_Interval_v[v]);

/* Below need constraint that interval variable product_1_Interval might be in state 1 or 3 */
/* Below need constraint that interval variable product_2_Interval might be in state 2 or 3 */


//alwaysEqual(myStateFunction, product_1_Interval,  1) or alwaysEqual(myStateFunction, product_1_Interval,  3);

forall(v in options)alwaysEqual(myStateFunction,product_1_Interval_v[v],  v);
forall(v in options)alwaysEqual(myStateFunction,product_2_Interval_v[v],  v);

presenceOf(product_2_Interval_v[1])!=presenceOf(product_1_Interval_v[1]);

}

execute
{
  writeln(myStateFunction);
}

gives

stepwise{ -1 -> 0; 1 -> 155; 3 -> 310; -1 }

enter image description here

and

using CP;

{int} options={1,3};

stateFunction myStateFunction;
dvar interval product_1_Interval size 10..200;
dvar interval product_1_Interval_v[options]  optional;

dvar interval product_2_Interval size 10..200;
dvar interval product_2_Interval_v[options]  optional;

subject to
{
alwaysConstant (myStateFunction, 0, 155);
alwaysConstant (myStateFunction, 156, 310);

endAtStart(product_1_Interval,product_2_Interval,1);

alternative(product_1_Interval,all(v in options)product_1_Interval_v[v]);
alternative(product_2_Interval,all(v in options)product_2_Interval_v[v]);

/* Below need constraint that interval variable product_1_Interval might be in state 1 or 3 */
/* Below need constraint that interval variable product_2_Interval might be in state 2 or 3 */


//alwaysEqual(myStateFunction, product_1_Interval,  1) or alwaysEqual(myStateFunction, product_1_Interval,  3);

forall(v in options)alwaysEqual(myStateFunction,product_1_Interval_v[v],  v);
forall(v in options)alwaysEqual(myStateFunction,product_2_Interval_v[v],  v);

presenceOf(product_2_Interval_v[1])!=presenceOf(product_1_Interval_v[1]);

startOf(product_1_Interval) == 120;

}

execute
{
  writeln(myStateFunction);
  writeln(product_1_Interval);
  writeln(product_2_Interval);
}

gives

stepwise{ -1 -> 0; 1 -> 155; 3 -> 310; -1 }
 <1 120 154 34>
 <1 155 165 10>