首页 > 解决方案 > Cplex:无法获取决策变量的值

问题描述

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

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

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

这是一个长模型。

非常感谢我能得到帮助。

++型号

- 套:

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

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

{字符串} 是=...; //一组经验水平为S的医生

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

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

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

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

- 参数

诠释 D=...;

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

int Co[Is]=...; //具有高级经验水平的医师 i 的雇用成本

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

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

诠释PKD = ...; //分钟。医生轮班的天数

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

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

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

诠释dosd = ...; //轮班“高级”医师的日常工作需求

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

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

诠释多德=...;//轮班“菜鸟”医师的日常工作需求

诠释多尔=...; //轮班“菜鸟”医师的晚间工作需求

诠释多恩=...;//“菜鸟”医师的夜班需求

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

诠释 dtse=...; //“高级”医师的晚班工作需求

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

诠释 dtsn2=...; //值班t night2“高级”医师的工作需求

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

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

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

诠释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、如果rookie+ 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={"高级","菜鸟"};

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

是={"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={"白天","晚上","夜晚"};

A2={"白天","晚上","夜晚 1","夜晚 2"};

D=7;

钴=[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

解决方案


您的模型可能不可行。如果您标记约束,那么 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 

推荐阅读