CPLEX:CP Optimizer 用 0 个解决方案永远 运行
CPLEX: CP Optimizer took forever to run with 0 solution
我 运行 我的 model 在 CPLEX 中使用约束编程,我的 model 设法 运行 有 8 个工人。但是3小时后,仍然没有解决方案,所以我不得不停止model。
我的 model 有问题吗?我尝试 运行 model Excel 文件中只有几个样本,但在 运行 几个小时后它仍然没有给我一个解决方案。提前致谢!
我的mod。文件:
using CP;
int scale=10;
int NumbDay =...;
int NumbTask =...;
range Day = 1 .. NumbDay;
range Task = 1 .. NumbTask;
int maxRepetition = NumbDay;
dvar int F [Task] in 1..maxRepetition;
range Repetition = 0 .. maxRepetition;
int h [Day]=...;
int R [Task]=...;
int c [Day]=...;
int E [Task]=...;
int d [Day]=...;
int O [Task]=...;
int P [Task] =...;
float t [Task]=...;
dvar int+ r [i in Task][j in Repetition];
dvar int+ e [i in Task][j in Repetition];
dvar int+ o [i in Task][j in Repetition];
dvar int+ n [i in Task][j in Repetition];
dvar int scalenW[Day] in 0..100;
dexpr float W [k in Day]=scalenW[k]/scale;
dvar boolean X [Day][Task][Repetition];
dexpr float e1 = sum(k in Day)(((sum(k in Day, i in Task, j in Repetition) t [i]*X[k][i][j])/365) - W [k])^2;
dexpr float e2 = sum(i in Task, j in Repetition) n [i][j];
minimize staticLex(e1, e2);
subject to
{
constraint_1:
forall (i in Task){
F [i] >= P [i];
}
constraint_2:
forall (k in Day){
sum(i in Task) (sum(j in Repetition)(t [i]*X [k][i][j]*(j<=F[i]-1))) == W [k];
}
constraint_3:
forall (i in Task, j in Repetition){
sum(k in Day) X [k][i][j] == 1 * (j<=F[i]-1);
}
constraint_4:
forall (k in Day, i in Task, j in Repetition){
X [k][i][j] == 0 || X [k][i][j] == 1;
}
constraint_5:
forall (i in Task, j in Repetition){
(r[i][j]!=0) => sum(k in Day)(X [k][i][j] * h [k]) <= r [i][j];
}
constraint_6:
forall (i in Task, j in Repetition){
r [i][j] <= 10 * NumbDay;
}
constraint_7:
forall (i in Task){
r [i][0] == R [i];
}
constraint_8:
forall (i in Task, j in 1..NumbDay){
r [i][j] == (R [i] + sum(k in Day) (X [k][i][j-1] * h [k])) * (j<=F[i]-1);
}
constraint_9:
forall (i in Task, j in Repetition){
(e[i][j]!=0) => sum(k in Day)(X [k][i][j] * c [k]) <= e [i][j];
}
constraint_10:
forall (i in Task, j in Repetition){
n [i][j] == e [i][j] - sum(k in Day)( X [k][i][j] * c [k]);
}
constraint_11:
forall (i in Task, j in Repetition){
e [i][j] <= 10 * NumbDay;
}
constraint_12:
forall (i in Task){
e [i][0] == E [i];
}
constraint_13:
forall (i in Task, j in 1..NumbDay){
e [i][j] == (E [i] + sum(k in Day) (X [k][i][j-1] * c [k])) * (j<=F[i]-1);
}
constraint_14:
forall (i in Task, j in Repetition){
(o[i][j]!=0) => sum(k in Day)(X [k][i][j] * d [k]) <= o [i][j];
}
constraint_15:
forall (i in Task, j in Repetition){
o [i][j] <= 10 * NumbDay;
}
constraint_16:
forall (i in Task){
o [i][0] == O [i];
}
constraint_17:
forall (i in Task, j in 1..NumbDay){
o [i][j] == (O [i] + sum(k in Day) (X [k][i][j-1] * d [k])) * (j<=F[i]-1);
}
}
我的数据。文件:
SheetConnection ModelData("ModelData.xlsx");
NumbDay from SheetRead(ModelData,"1mosize!B1");
NumbTask from SheetRead(ModelData,"1mosize!B2");
h from SheetRead(ModelData,"1mo1D2!B2:B31");
R from SheetRead(ModelData,"1mo1D1!B2:B20");
c from SheetRead(ModelData,"1mo1D2!C2:C31");
E from SheetRead(ModelData,"1mo1D1!C2:C20");
d from SheetRead(ModelData,"1mo1D2!D2:D31");
O from SheetRead(ModelData,"1mo1D1!D2:D20");
t from SheetRead(ModelData,"1mo1D1!E2:E20");
P from SheetRead(ModelData,"1mo1D1!I2:I20");
如果把比例尺变成
int scale=1000;
和
// constraint_2:
// forall (k in Day){
// sum(i in Task) (sum(j in Repetition)(t [i]*X [k][i][j]*(j<=F[i]-1))) == W [k];
// }
进入
constraint_2:
forall (k in Day){
abs(sum(i in Task) (sum(j in Repetition)(t [i]*X [k][i][j]*(j<=F[i]-1))) - W [k])<=1;
}
你会得到解决方案
我 运行 我的 model 在 CPLEX 中使用约束编程,我的 model 设法 运行 有 8 个工人。但是3小时后,仍然没有解决方案,所以我不得不停止model。
我的 model 有问题吗?我尝试 运行 model Excel 文件中只有几个样本,但在 运行 几个小时后它仍然没有给我一个解决方案。提前致谢!
我的mod。文件:
using CP;
int scale=10;
int NumbDay =...;
int NumbTask =...;
range Day = 1 .. NumbDay;
range Task = 1 .. NumbTask;
int maxRepetition = NumbDay;
dvar int F [Task] in 1..maxRepetition;
range Repetition = 0 .. maxRepetition;
int h [Day]=...;
int R [Task]=...;
int c [Day]=...;
int E [Task]=...;
int d [Day]=...;
int O [Task]=...;
int P [Task] =...;
float t [Task]=...;
dvar int+ r [i in Task][j in Repetition];
dvar int+ e [i in Task][j in Repetition];
dvar int+ o [i in Task][j in Repetition];
dvar int+ n [i in Task][j in Repetition];
dvar int scalenW[Day] in 0..100;
dexpr float W [k in Day]=scalenW[k]/scale;
dvar boolean X [Day][Task][Repetition];
dexpr float e1 = sum(k in Day)(((sum(k in Day, i in Task, j in Repetition) t [i]*X[k][i][j])/365) - W [k])^2;
dexpr float e2 = sum(i in Task, j in Repetition) n [i][j];
minimize staticLex(e1, e2);
subject to
{
constraint_1:
forall (i in Task){
F [i] >= P [i];
}
constraint_2:
forall (k in Day){
sum(i in Task) (sum(j in Repetition)(t [i]*X [k][i][j]*(j<=F[i]-1))) == W [k];
}
constraint_3:
forall (i in Task, j in Repetition){
sum(k in Day) X [k][i][j] == 1 * (j<=F[i]-1);
}
constraint_4:
forall (k in Day, i in Task, j in Repetition){
X [k][i][j] == 0 || X [k][i][j] == 1;
}
constraint_5:
forall (i in Task, j in Repetition){
(r[i][j]!=0) => sum(k in Day)(X [k][i][j] * h [k]) <= r [i][j];
}
constraint_6:
forall (i in Task, j in Repetition){
r [i][j] <= 10 * NumbDay;
}
constraint_7:
forall (i in Task){
r [i][0] == R [i];
}
constraint_8:
forall (i in Task, j in 1..NumbDay){
r [i][j] == (R [i] + sum(k in Day) (X [k][i][j-1] * h [k])) * (j<=F[i]-1);
}
constraint_9:
forall (i in Task, j in Repetition){
(e[i][j]!=0) => sum(k in Day)(X [k][i][j] * c [k]) <= e [i][j];
}
constraint_10:
forall (i in Task, j in Repetition){
n [i][j] == e [i][j] - sum(k in Day)( X [k][i][j] * c [k]);
}
constraint_11:
forall (i in Task, j in Repetition){
e [i][j] <= 10 * NumbDay;
}
constraint_12:
forall (i in Task){
e [i][0] == E [i];
}
constraint_13:
forall (i in Task, j in 1..NumbDay){
e [i][j] == (E [i] + sum(k in Day) (X [k][i][j-1] * c [k])) * (j<=F[i]-1);
}
constraint_14:
forall (i in Task, j in Repetition){
(o[i][j]!=0) => sum(k in Day)(X [k][i][j] * d [k]) <= o [i][j];
}
constraint_15:
forall (i in Task, j in Repetition){
o [i][j] <= 10 * NumbDay;
}
constraint_16:
forall (i in Task){
o [i][0] == O [i];
}
constraint_17:
forall (i in Task, j in 1..NumbDay){
o [i][j] == (O [i] + sum(k in Day) (X [k][i][j-1] * d [k])) * (j<=F[i]-1);
}
}
我的数据。文件:
SheetConnection ModelData("ModelData.xlsx");
NumbDay from SheetRead(ModelData,"1mosize!B1");
NumbTask from SheetRead(ModelData,"1mosize!B2");
h from SheetRead(ModelData,"1mo1D2!B2:B31");
R from SheetRead(ModelData,"1mo1D1!B2:B20");
c from SheetRead(ModelData,"1mo1D2!C2:C31");
E from SheetRead(ModelData,"1mo1D1!C2:C20");
d from SheetRead(ModelData,"1mo1D2!D2:D31");
O from SheetRead(ModelData,"1mo1D1!D2:D20");
t from SheetRead(ModelData,"1mo1D1!E2:E20");
P from SheetRead(ModelData,"1mo1D1!I2:I20");
如果把比例尺变成
int scale=1000;
和
// constraint_2:
// forall (k in Day){
// sum(i in Task) (sum(j in Repetition)(t [i]*X [k][i][j]*(j<=F[i]-1))) == W [k];
// }
进入
constraint_2:
forall (k in Day){
abs(sum(i in Task) (sum(j in Repetition)(t [i]*X [k][i][j]*(j<=F[i]-1))) - W [k])<=1;
}
你会得到解决方案