有没有一种方法可以在不使用CPLEX中的约束编程的情况下将决策变量插入索引范围


  • 我有以下索引:
  1. k:天数索引:k∈{1,…,k=365}
  2. i: 任务索引:i∈{1,…,N=200}
  3. j: 任务i第j次的索引:j∈{1,…,Fi}

With F_i是一个决策变量,表示任务i 的重复次数

  • 以及涉及Fi和j的2个约束:此处有2个约束条件

有办法在CPLEX中编写此模型吗?我不能使用约束编程,因为有浮点值。

这是我的样本代码

int NumbDay = ...;
int NumbTask = ...;

range Day = 1 .. NumbDay;
range Task = 1 .. NumbTask;
dvar int F [Task];
range Repetition = [1..F[Task]]; //Error: Decision variable (or expression) "F" not allowed.
float TotalFH [Day]=...;
float TimeIntervalFH [Task]=...;
float TotalFC [Day]=...;
float TimeIntervalFC [Task]=...;
float TotalDY [Day]=...;
float TimeIntervalDY [Task]=...;
float Manhour [Task]=...;
float NumberOfDaysScheduled =...;
float MinimumNumberOfRepetitions [Task] =...;
dvar float r [Task][Repetition];
dvar float e [Task][Repetition];
dvar float o [Task][Repetition];
dvar float q [Task][Repetition];
dvar float n [Task][Repetition];
dvar float m [Task][Repetition];
dvar float W [Day];
dvar boolean X [Day][Task][Repetition];

execute PRE_PROCESSING {
cplex.epgap = 0.1;
cplex.tilim = 100;
}
// Objective: first criterion for minimize the total of the squared differences between the “Average manhour per day” and “Total manhour load of day k” 
//            second criterion for minimize the total differences of the time we execute the task and the due date of those tasks
dexpr float e1 = sum(k in Day)(((sum(k in Day, i in Task, j in Repetition) Manhour[i]*X[i][j][k])/365) - W [Day])^2; //Cannot use type range for int.
dexpr float e2 = sum(i in Task, j in Repetition)q[i][j]*n[i][j]*m[i][j];
// trying to minimize the total of the squared differences between the “Average manhour per day” and “Total manhour load of day k” first
minimize staticLex(e1, e2);
subject to {
constraint_1:
forall (i in Task){
F [i] >= MinimumNumberOfRepetitions [i];
}
constraint_2:
forall (k in Day){
sum(i in Task, j in Repetition) Manhour[i]*X[i][j][k] == W [k];
}

constraint_3:
forall (i in Task, j in Repetition){
sum(k in Day) X[i][j][k] == 1;
}
....

您可以使用一个逻辑约束:

constraint_2:
forall (k in Day,j in Repetition)
sum(i in Task ) Manhour[i]*X[k][i][j] *(j<=F[i]) == W [k];

首先,以下模型有效:

int NumbDay = 1;
int NumbTask = 2;

range Day = 1 .. NumbDay;
range Task = 1 .. NumbTask;
int maxRepetition=10;
dvar int F [Task] in 0..maxRepetition;
//**range Repetition = [1..F[Task]];**
range Repetition=0..maxRepetition;
float TotalFH [d in Day]=d;
float TimeIntervalFH [Task];
float TotalFC [Day];
float TimeIntervalFC [Task];
float TotalDY [Day];
float TimeIntervalDY [Task];
float Manhour [Task];
float NumberOfDaysScheduled ;
float MinimumNumberOfRepetitions [Task] ;
dvar float r [Task][Repetition];
dvar float e [Task][Repetition];
dvar float o [Task][Repetition];
dvar float q [Task][Repetition];
dvar float n [Task][Repetition];
dvar float m [Task][Repetition];
dvar float W [Day];
dvar boolean X [Day][Task][Repetition];

execute PRE_PROCESSING {
cplex.epgap = 0.1;
cplex.tilim = 100;
}
// Objective: first criterion for minimize the total of the squared differences between the “Average manhour per day” and “Total manhour load of day k” 
//            second criterion for minimize the total differences of the time we execute the task and the due date of those tasks
dexpr float e1 = sum(k in Day)(((sum(k in Day, i in Task, j in Repetition) Manhour[i]*X[k][i][j])/365) - W [k])^2;
//dexpr float e2 = sum(i in Task, j in Repetition)q[i][j]*n[i][j]*m[i][j];
// trying to minimize the total of the squared differences between the “Average manhour per day” and “Total manhour load of day k” first
minimize e1;
//minimize staticLex(e1, e2);
subject to {
constraint_1:
forall (i in Task){
F [i] >= MinimumNumberOfRepetitions [i];
}
constraint_2:
forall (k in Day,j in Repetition)
sum(i in Task ) Manhour[i]*X[k][i][j] *(j<=F[i]) == W [k];


constraint_3:
forall (i in Task, j in Repetition){
sum(k in Day) X[k][i][j] == 1;
}
}

最新更新