Cplex:无法获取决策变量的值

Cplex: cannot get value for decision variables

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

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

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

这是一个长款。

非常感谢能得到帮助。

++型号

--套数:

{字符串} E=...; // 一组经验水平(高级,菜鸟)

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

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

{string} Ir=...;//经验水平为R的医师集合

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

{字符串} A1=...; //设置班次o工作(白天,晚上,晚上)

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

--参数

int D=...;

range Day=1..D;//规划范围

积分[是]=...; //具有高级经验水平的医生 i 的聘用成本

int Ct[Ir]=...; //具有菜鸟经验水平的医生 i 的聘用成本

int Pku=...; //最大限度。医生执行班次的天数 o

int Pkd=...; //分钟。医生执行班次的天数 o

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

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

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

int dosd=...; //转移"senior"医生

的日间工作需求

int 剂量=...; //转移 o "senior"医生

的晚间工作需求

int dosn=...; //轮班 "senior" 医生

的夜间工作需求

int dord=...; //转移 "rookie" 医生

的日间工作需求

int dore=...; //转移 o "rookie"医生

的晚间工作需求

int dorn=...; //轮班"rookie"医师

的夜间工作需求

int dtsd=...; //"senior"医生

第t天的工作需求

int dtse=...; //轮班 t 晚间工作需求"senior"医师

int dtsn1=...; //第 t 晚 1 班 "senior" 医生

的工作需求

int dtsn2=...; // shift t night2 "senior"医生

的工作需求

int dtrd=...; //"rookie"医师

的第t天工作需求

int dtre=...; //轮班 t 晚上工作需求"rookie"医生

int dtrn1=...; //第 t night1 班 "rookie" 医生

的工作需求

int dtrn2=...; // shift t night2 "rookie"医生

的工作需求

--二进制判定变量

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

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

dvar int y1[I][Day][A1] in 0..1; //1、如果rookie+shift o+其中一项工作

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

--Desicion变量的表达式

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

--Objective函数

最小化成本;

--约束条件

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={"Senior","Rookie"};

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"};

是={"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 会给您一些松弛和冲突,这将帮助您理解原因。我的建议是标记所有约束条件。

例如你可以改变

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