有没有办法在不使用 CPLEX 中的约束编程的情况下在索引范围内插入决策变量?
Is there a way to insert decision variable in index range without using Constraints Programming in CPLEX?
- 我有以下索引:
- k: 天的索引: k ∈ {1, ..., K=365}
- i:任务索引:i ∈ {1, ..., N=200}
- j:第j次任务i的索引:j∈{1,...,Fi}
和F_i是一个决策变量,表示任务i的重复次数
- 以及涉及 Fi 和 j 的 2 个约束:
2 constraints here
有没有办法在 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;
}
}
- 我有以下索引:
- k: 天的索引: k ∈ {1, ..., K=365}
- i:任务索引:i ∈ {1, ..., N=200}
- j:第j次任务i的索引:j∈{1,...,Fi}
和F_i是一个决策变量,表示任务i的重复次数
- 以及涉及 Fi 和 j 的 2 个约束: 2 constraints here
有没有办法在 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;
}
}