所以我正在自己解决一个交通优化模型,并进行一些更改。模型运行成功,但当我看到决策变量的值时,它向我显示一个所有值为 0 的 3D 数组。
.mod 文件
int m = ...;
int n = ...;
int o = ...;
range I = 1..m;
range J = 1..n;
range K = 1..o;
float d[I][J] = ...;
float s[I] = ...;
float f = ...;
float v = ...;
float q = ...;
float u[I][J][K];
dvar float x[I][J][K];
dvar int y[I][J][K];
float data[1..9][1..261] = ...;
minimize sum(i in I, j in J, k in K) f*y[i][j][k] + sum(i in I, j in J, k in K) v*d[i][j]*y[i][j][k];
subject to {
Constraint1: forall(j in J, k in K) sum(i in I) x[i][j][k] == sum(i in I) u[i][j][k];
Constraint2: forall(i in I) sum(j in J, k in K) x[i][j][k] <= s[i];
Constraint3: forall(i in I, j in J, k in K) x[i][j][k] <= q*y[i][j][k];
Constraint4: forall(i in I, j in J, k in K) x[i][j][k] >= 0;
Constraint5: forall(i in I, j in J, k in K) y[i][j][k] >= 0;
}
execute {
for (var k = 1; k <= 3; k++) {
for (var i = 1; i <= 3; i++) {
for (var j = 1; j <= 261; j++) {
// Calculate the row index based on k and i
var row = (k - 1) * 3 + i; // 3 rows per k
u[i][j][k] = data[row][j]; // Offset by 1 for customer index
}
}
}
}
.dat 文件
m = 3;
n = 261;
o = 3;
SheetConnection Sheet ("ProjectData.xlsx");
d from SheetRead (Sheet, "CPLEX! C6:JC8");
s from SheetRead (Sheet, "Data! C3:C5");
f from SheetRead (Sheet, "Data! B16");
v from SheetRead (Sheet, "Data! B17");
q from SheetRead (Sheet, "Data! B18");
data from SheetRead (Sheet, "CPLEX! C16:JC24");
我已经检查了所有参数的值,看看该值是否正确,结果确实如此。 CPLEX 也没有给出任何我的模型无法运行的原因。如果有帮助的话,我正在使用学生 CPLEX 版本。
我认为问题可能是你写的
float u[I][J][K];
这意味着你们都是0
int m = 3;
int n = 261;
int o = 3;
range I = 1..m;
range J = 1..n;
range K = 1..o;
float d[i in I][j in J] = rand(10);
float s[i in I] = rand(10)+200000;
float f = 2;
float v = 3;
float q = 8000;
float u[i in I][j in J][k in K]=rand(10);
dvar float x[I][J][K];
dvar int y[I][J][K];
float data[i in 1..9][j in 1..261] = rand(10);
minimize sum(i in I, j in J, k in K) f*y[i][j][k] + sum(i in I, j in J, k in K) v*d[i][j]*y[i][j][k];
subject to {
Constraint1: forall(j in J, k in K) sum(i in I) x[i][j][k] == sum(i in I) u[i][j][k];
Constraint2: forall(i in I) sum(j in J, k in K) x[i][j][k] <= s[i];
Constraint3: forall(i in I, j in J, k in K) x[i][j][k] <= q*y[i][j][k];
Constraint4: forall(i in I, j in J, k in K) x[i][j][k] >= 0;
Constraint5: forall(i in I, j in J, k in K) y[i][j][k] >= 0;
}
execute {
for (var k = 1; k <= 3; k++) {
for (var i = 1; i <= 3; i++) {
for (var j = 1; j <= 261; j++) {
// Calculate the row index based on k and i
var row = (k - 1) * 3 + i; // 3 rows per k
u[i][j][k] = data[row][j]; // Offset by 1 for customer index
}
}
}
}
给出非零解