【问题标题】:Cplex: cannot get value for decision variablesCplex:无法获取决策变量的值
【发布时间】:2019-12-02 23:15:46
【问题描述】:

我正在解决 Cplex 的医院工作人员调度问题,而且我是 Cplex 的新手。

但 Cplex 无法配置决策变量的答案。

我想可能是我的模型设计问题。

这是一个长模型。

如果我能得到帮助,非常感谢。

++模型

--集合:

{字符串} E=...; // 一组经验级别(高级,新手)

{字符串} I=...; // 所有医生的集合

{string} 是=...; //经验等级S的医生集合

{string} Ir=...;//经验等级R的医师集合

{字符串} K=...; //班次类型(o & t)

{字符串} A1=...; //一组班次(白天,晚上,晚上)

{字符串} A2=...; //一组轮班t工作(白天,晚上,晚上1,晚上2)

--参数

int D=...;

range Day=1..D;//计划范围的范围

int Co[Is]=...; //高级经验级别的医师 i 的招聘成本

int Ct[Ir]=...; //新人经验级别的医生 i 的雇佣成本

int Pku=...; //最大限度。医生轮班的天数

int Pkd=...; //分钟。医生轮班的天数

int Pkuh=...;//最大。医生轮班的天数

int Pkdh=...;//分钟。医生轮班的天数

int s=...; //最大限度。连续工作日

int dosd=...; //转“高级”医师的日常工作需求

int 剂量=...; //轮班“高级”医师的晚间工作需求

int dosn=...; //“高级”医师的夜班需求

int dord=...; //“菜鸟”医师轮班工作需求

int dore=...; //“菜鸟”医师的夜班需求转移

int 多恩=...; //“菜鸟”医师轮班夜班需求

int dtsd=...; //“高级”医师轮班t天的工作需求

int dtse=...; //“高级”医师的夜班工作需求

int dtsn1=...; //“高级”医师轮班t night1工作需求

int dtsn2=...; //轮班t night2“高级”医师的工作需求

int dtrd=...; //“菜鸟”医师轮班t天工作需求

int dtre=...; //“菜鸟”医师的夜班工作需求

int dtrn1=...; //“菜鸟”医师轮班t night1工作需求

int dtrn2=...; //“菜鸟”医师轮班t night2工作需求

--二进制决策变量

dvar int x1[I][Day][A1] in 0..1; //1、if Senior+ shift o+ 其中一项工作

dvar int x2[I][Day][A2] in 0..1; //1、如果senior+ shift t+其中一项工作

dvar int y1[I][Day][A1] in 0..1; //1、如果菜鸟+ shift o+ 之一的工作

dvar int y2[I][Day][A2] in 0..1; //1、如果菜鸟+ shift t+ 之一的工作

--决策变量的表达

dexpr float cost =sum(i in Is,  d in Day, a in A1)Co[i]*x1[i][d][a]  

+ sum(i in Is,  d in Day, a in A2)Co[i]*x2[i][d][a]

+ sum(i in Ir,  d in Day, a in A1)Ct[i]*y1[i][d][a] 

+ sum(i in Ir,  d in Day, a in A2)Ct[i]*y2[i][d][a] ;

--目标函数

最小化成本;

--约束

subject to

{

forall(d in Day, Day in A1)

{

sum(i in Is) x1[i, d ,"Day"] == dosd; //Daily demand:Senior+shift o+day work 

}

forall(d in Day, Evening in A1)

{

sum(i in Is ) x1[i, d, "Evening"] == dose; //Daily demand:Senior+shift o+evening work 

}

forall(d in Day, Night in A1)

{

sum(i in Is ) x1[i, d, "Night"] == dosn; //Daily demand:Senior+shift o+night work 

}

forall(d in Day, Day in A2)

{

sum(i in Is) x2[i, d, "Day"] == dtsd; //Daily demand:Senior+ shift t +day work 

}

forall(d in Day, Evening in A2)

{

sum(i in Is) x2[i, d, "Evening"] == dtse; //Daily demand:Senior+shift t+evening work 

}

forall(d in Day, Night1 in A2)

{

sum(i in Is) x2[i, d, "Night1"] == dtsn1; //Daily demand:Senior+shift t+night1 work 

}

forall(d in Day, Night2 in A2)

{

sum(i in Is) x2[i, d, "Night2"] == dtsn2; //Daily demand:Senior+shift t+night2 work 

}

forall(d in Day, Day in A1)

{

sum(i in Ir) y1[i, d, "Day"] == dord; //Daily demand:Rookie+shift o+day work 

}

forall(d in Day, Evening in A1)

{

sum(i in Ir) y1[i, d, "Evening"] == dore; //Daily demand:Rookie+shift o+evening work 

}

forall(d in Day, Night in A1)

{

sum(i in Ir) y1[i, d, "Night"] == dorn; //Daily demand:Rookie+shift o+night work 

}

forall(d in Day, Day in A2)

{

sum(i in Ir) y2[i, d, "Day"] == dtrd; //Daily demand:Rookie+shift t+day work 

}

forall(d in Day, Evening in A2)

{

sum(i in Ir) y2[i, d, "Evening"] == dtre; //Daily demand:Rookie+shift t+evening work 

}

forall(d in Day, Night1 in A2)

{

sum(i in Ir) y2[i, d, "Night1"] == dtrn1; //Daily demand:Rookier+shift t+night1 work 

}

forall(d in Day, Night2 in A2)

{

sum(i in Ir) y2[i, d, "Night2"] == dtrn2; //Daily demand:Rookie+shift t+night2 work 

}

forall(i in Is, d in Day:d<D, Evening in A1)

{    

x1[i, d, "Evening"]+ x1[i,(d+1), "Day"]<=1; //(Senior)For shift type o,if previous day is evening 

work, can't have day work the following day'    

}

forall(i in Is, d in Day:d<D, Evening in A2)

{

x2[i, d, "Evening"]+ x2[i,(d+1), "Day"]<=1; //(Senior)For shift type t,if previous day is evening 

work, can't have day work the following day'

}

forall(i in Ir, d in Day:d<D, Evening in A1)

{    

y1[i, d, "Evening"]+ y1[i,(d+1), "Day"]<=1; //(Rookie)For shift type o,if previous day is evening 

work, can't have day work the following day'  

}

forall(i in Ir, d in Day:d<D, Evening in A2)

{    

y2[i, d, "Evening"]+ y2[i,(d+1), "Day"]<=1; //(Rookie)For shift type t,if previous day is evening 

work, can't have day work the following day'

}  

forall(i in Is, d in Day:d<D, Night in A1)

{  

  x1[i, d,"Night"]+ x1[i,(d+1),"Day"]<=1; //(Senior)For shift type o,if previous day is night work, 

can't have day work the following day'    

}

forall(i in Is, d in Day:d<D, Night1 in A2)

{

x2[i, d,"Night1"]+ x2[i,(d+1),"Day"]<=1;  //(Senior)For shift type t,if previous day is night1 work, 

can't have day work the following day'

}

forall(i in Is, d in Day:d<D, Night2 in A2)

{

x2[i, d,"Night2"]+ x2[i,(d+1),"Day"]<=1;  //(Senior)For shift type t,if previous day is night2 work, 

can't have day work the following day'

} 

forall(i in Ir, d in Day:d<D, Night in A1)

 {    

y1[i, d,"Night"]+ y1[i,(d+1),"Day"]<=1; //(Rookie)For shift type o,if previous day is night work, 

can't have day work the following day'    

}

forall(i in Ir, d in Day:d<D, Night1 in A2)

{

y2[i, d,"Night1"]+ y2[i,(d+1),"Day"]<=1;  //(Rookie)For shift type t,if previous day is night1 work, 

can't have day work the following day'

}

forall(i in Ir, d in Day:d<D, Night2 in A2)

{

y2[i, d,"Night2"]+ y2[i,(d+1),"Day"]<=1;  //(Rookie)For shift type t,if previous day is night2 work, 

can't have day work the following day'

} 

forall (i in Is, d in Day)

{

sum(a in A1)x1[i,d,a] + sum(a in A2)x2[i,d,a] <=1;  //(Senior)each day can only have one work with 

one shift

}

forall (i in Ir, d in Day)

{

sum(a in A1)y1[i,d,a] + sum(a in A2)y2[i,d,a] <=1;  //(Rookie)each day can only have one work with 

one shift
  }

forall(i in Is, a in A1)

{

sum(d in Day)x1[i,d,a] <=Pku; //(Senior) can’t have shift type o that more than upper bound. (in 

days)

}

forall(i in Ir, a in A1)

{

sum(d in Day)y1[i,d,a] <=Pku; //(Rookie) can’t have shift type o that more than upper bound. (in 

days)

}

forall(i in Is, a in A1)

{

sum(d in Day)x1[i,d,a]>=Pkd; //(Senior) can’t have shift type o that less than lower bound. (in 

days)

}

forall(i in Ir, a in A1)

{

sum(d in Day)y1[i,d,a]>=Pkd; //(Rookie) can’t have shift type o that less than lower bound. (in 

days)

}


forall(i in Is, a in A2)

{

sum(d in Day)x2[i,d,a]<=Pkuh; //(Senior) can’t have shift type t that more than upper bound. (in 

days)

}

forall(i in Ir, a in A2)

{

sum(d in Day)y2[i,d,a]<=Pkuh; //(Rookie) can’t have shift type t that more than upper bound. (in 

days)

}

forall(i in Is, a in A2)

{

sum(d in Day)x2[i,d,a]>=Pkdh; //(Senior) can’t have shift type t that less than lower bound. (in 

days)

}

forall(i in Ir, a in A2)

{

sum(d in Day)y2[i,d,a]>=Pkdh; //(Rookie) can’t have shift type t that less than lower bound. (in 

days)

}

forall(i in Is)

{

sum(d in Day:d<=(D-s), a in A1)x1[i,d,a]+sum(d in Day:d<=(D-s), a in A2)x2[i,d,a]<=s; //(Senior) 

can’t have consecutive working days (regardless of shift type) that more than upper bound. (in days)

}

forall(i in Ir)

{

sum(d in Day:d<=(D-s), a in A1)y1[i,d,a]+sum(d in Day:d<=(D-s), a in A2)y2[i,d,a]<=s; //(Rookie) 

can’t have consecutive working days (regardless of shift type) that more than upper bound. (in days)

}

++数据

E={"前辈","菜鸟"};

I={"A","B","C","D","E","F","G","H","I","J","K", "L","M","N","O","P","Q","R","S","T","W","X","Y","Z "};

Is={"A","B","C","D","E","F","G","H"};

Ir={"I","J","K","L","M","N","O","P","Q","R","S", "T","W","X","Y","Z"};

K={"o","t"};

A1={"Day","Evening","Night"};

A2={"Day","Evening","Night1","Night2"};

D=7;

Co=[1200,1150,1100,1050,1000,950,900,850];

Ct=[800,750,750,750,700,700,700,700,700,700,650,650,650,650,650,650];

Pku=10;

PKd=5;

Pkuh=8;

Pkdh=4;

s=5;

【问题讨论】:

    标签: cplex


    【解决方案1】:

    您的模型可能不可行。如果您标记您的约束,那么 CPLEX 会给您一些放松和冲突,这将帮助您理解原因。我的建议是标记所有约束。

    例如你可以改变

    forall(d in Day, Day in A1)
    
    {
    
    sum(i in Is) x1[i, d ,"Day"] == dosd; //Daily demand:Senior+shift o+day work 
    
    }
    

    进入

    forall(d in Day, Day in A1)
    
        ct1:sum(i in Is) x1[i, d ,"Day"] == dosd; //Daily demand:Senior+shift o+day work 
    

    【讨论】:

    • 非常感谢亚历克斯!我会试试的。 :D
    猜你喜欢
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多