Cplex:如何为指定字符串编写约束

时间:2019-11-28 23:38:05

标签: cplex

请帮助我在Cplex中编写约束。 我正在解决人员调度问题。

我有以下几组:

{string} I = ...; //所有医生的集合

{string} E = ...; //一组经验等级

{string} K = ...; //班次类型

{string} A = ...; //工作类型

int D = ...;

range Day = 1..D; //将时间范围安排为从第1天到第30天

数据:

I = {“ A”,“ B”,“ C”,“ D”,“ E”,“ F”,“ G”,“ H”,“ I”,“ J”,“ K”, “ L”,“ M”,“ N”,“ O”,“ P”,“ Q”,“ R”,“ S”,“ T”}};

E = {“高级”,“菜鸟”};

K = {“ o”,“ t”};

A = {“白天”,“晚上”,“夜”,“夜1”,“夜2”};

决策变量:

dvar int x [I] [E] [Day] [K] [A] in 0..1; // 1,如果将经验为e的医师i分配到工作日为a的轮班类型为k的d天

约束: evening+night constraint

我的主要问题是,由于我只需要关注A组中的“夜晚”和“白天”,因此我不知道如何在Cplex中表达它。

forall(i in I, e in E, d in D, k in K, Evening in A, Day in A)
       {
       x [i, e, (d-1), k, Evening]+ x[i, e, d, k, Day]<=1;  
       }

以上是我的尝试,但失败了。

谢谢您的帮助!

1 个答案:

答案 0 :(得分:0)

.mod

{string} I=...; // set of all physicians

{string} E=...; // set of experience levels

{string} K=...; //type of shifts

{string} A=...;//work type

int D=...;

range Day=1..D; //scheduling horizon is from day 1 to day 30

dvar int x[I][E][Day][K][A] in 0..1; //1, if physician i with experience level e is assigned to day d with shift type k with work type a



subject to
{
forall(i in I, e in E, d in Day, k in K, Evening in A:(d-1) in Day)
       {
       x [i, e, (d-1), k,"Evening"]+ x[i, e, d, k, "Day"]<=1;  
       }

     } 

.dat

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

E={"Senior","Rookie"};

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

A={"Day","Evening","Night","Night1","Night2"};

D=7;

工作正常