how to force succesive variable to be of same value?

北战南征 提交于 2019-12-13 04:35:52

问题


I have a binary variable y[k][t], where k = 1..3 (machines) and t = 1..10 (time). Variable Y is 1 if machine is active and 0 otherwise.

In the optimization if machine 1 is active in period 1 e.g. Y[1][1] = 1, i want the machine to continue to operate for at least 3 time periods. i.e. Y[1][1] = Y[1][2] = Y[1][3] = Y[1][4] = 1.

I only want the succesive variable for t+1,t+2,t+3 to be same as t if it is active.

how can i do that in cplex studio?


回答1:


what Erwin wrote about minimum run length is fine. If you rely on logical constraints that are available in CPLEX the model is a bit easier:

range K=1..3;
range T=1..10;

dvar boolean Y[K][T];
dvar boolean start[K][T];


subject to
{
forall(k in K) start[k][1]==Y[k][1];
forall(k in K,t in T:t!=1) start[k][t] ==  ((Y[k][t]==1) && (Y[k][t-1]==0));

forall(k in K) forall(l in 1..3) 
  forall(t in T:(t+l) in T) (start[k][t]==1) => (Y[k][t+l]==1);


}

But what could lead to long solve time if you grow the time horizon is that we enumerate time. Within CPLEX and OPL you may also use CPOptimizer and its dedicated scheduling concepts : intervals.

Then you would write

using CP;

range K=1..3;
range T=1..10;

int nbMaxIntervals=4;

dvar interval itvs[K][1..nbMaxIntervals] optional in T size 3..10;

subject to
{
forall(k in K) forall(i in 1..nbMaxIntervals-1) 
     endBeforeStart(itvs[k][i],itvs[k][i+1]);


}

What makes sure that you are on for at least 3 time periods is

size 3..10;

NB: More about CPOptimizer




回答2:


This is sometimes called a minimum run length. There are different approaches to handle this. Say we have x(t) as our binary variables indicating if the machine is operating at time t. The first thing is to introduce a binary variable start(t) that indicates when a run starts. This is what I mean:

  t      1 2 3 4 5 6 7 8
  x      0 1 1 1 0 1 1 0
  start  0 1 0 0 0 1 0 0

A run starts when x(t-1)=0 and x(t)=1, or more formally:

start(t) = x(t)*(1-x(t-1)) 

This is nonlinear. We can linearize this using:

start(t) <= x(t)
start(t) <= 1-x(t-1)
start(t) >= x(t)-x(t-1)

Often we just use the bound:

start(t) >= x(t)-x(t-1)

Next we need:

start(t) = 1 ==> x(t)...x(t+K-1) = 1

where K is the minimum run length.

This can be modeled as:

x(t+1) >= start(t)
...
x(t+K-1) >= start(t)

(we already know that x(t)=1 if start(t)=1).



来源:https://stackoverflow.com/questions/58087318/how-to-force-succesive-variable-to-be-of-same-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!