如何强制后续变量具有相同的值? [英] how to force succesive variable to be of same value?

查看:94
本文介绍了如何强制后续变量具有相同的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个二进制变量y[k][t],其中k = 1..3(机器)和t = 1..10(时间).如果机器处于活动状态,则变量Y为1,否则为0.

在优化中,如果机器1在周期1中处于活动状态,例如Y[1][1] = 1,我希望机器继续运行至少3个时间段.即Y[1][1] = Y[1][2] = Y[1][3] = Y[1][4] = 1.

我只希望t + 1,t + 2,t + 3的后继变量与t相同(如果处于活动状态).

我如何在cplex Studio中做到这一点?

解决方案

Erwin写的关于最小运行长度的内容是可以的.如果您依赖CPLEX中可用的逻辑约束,则该模型会更简单:

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);


}

但是,如果您延长时间范围,可能会导致较长的求解时间,这是我们枚举了时间.在CPLEX和OPL中,您还可以使用CPOptimizer及其专用的调度概念:间隔.

那你要写

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]);


}

确保您至少打开3个时间段的情况是

size 3..10;

NB:有关 CPOptimizer

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?

解决方案

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

这篇关于如何强制后续变量具有相同的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆