objective 函数中的 CPLEX 优化数组错误
CPLEX optimization array error in objective function
我正在尝试优化 CPLEX OPL 中的以下问题。我已经定义了参数和决策变量。但是,当我尝试制定 objective 函数和约束时,我似乎遇到了问题,因为我在 objective 函数调用 'cannot use type range for int' 的行中收到错误。我不确定这里有什么问题。
同样在约束公式中,我在制定约束以确保变量 I 和 W 在两个相应的周期之间保持平衡时遇到了问题。 CPLEX 错误读取运算符不适用于范围 - int.
我试图重现的问题是:
这是我当前的数据文件:
time=2;
// Try product =1
d = [2000,1500];
k = [5000,5000];
h = [1,1];
p = [300,300];
q = [600,600];
e = [1,1];
c = [3,3];
r = [4,4];
这是我到目前为止在模型中得出的结论:
int Time = ...; range T=1..Time;
// Parameters
int d [T] = ...; // demand in period t
int K [T] = ...; // fixed order cost in period t
int h [T] = ...; // unit holding cost in period t
int p [T] = ...; // fixed cost of increasing WH size in period t
int q [T] = ...; // fixed cost of increasing WH size in period t
int e [T] = ...; // variable cost of increasing WH size in period t
int c [T] = ...; // variable cost of decreasing WH size in period t
int r [T] = ...; // WH rental cost per unit in period t
dvar int+ x[T]; //order size in period t
dvar int+ i[T]; //inventory lvl at the end of period t
dvar int+ w[T]; // warehouse size at the end of period t
dvar int+ u[T]; // warehouse size expansion at beginning of period t
dvar int+ v[T]; // warehouse size contraction at beginning of period t
dvar boolean y[T]; // binary variable for ordering in period t
dvar boolean z1[T]; // binary variable for WH expansion in period t
dvar boolean z2[T]; // binary variable for WH contraction in period t
//objecTve funcTon
dexpr int Cost = sum(t in T)(K[T]*y[T]+h[T]*i1[T]+p[T]*z1[T]+e[T]*u[T]+q[T]*z2[T]+c[T]*v[T]+r[T]*w1[T]);
minimize Cost;
//constraints
subject to {
forall(t in T) {
i[T-1] + x[T] - d[T] == i[T];
w[T-1] + u[T] - v[T] == w[T];
i[T] <= w[T];
x[T] <= d[T]*y[T];
u[T] <= d[T]*z1[T];
v[T] <= d[T]*z2[T];
I[0]==0;
}
}
有人可以给我一些建议,告诉我我在 objective 函数公式中做错了什么,以及我如何正确地制定 I(t-1)+x-d=I(t) 的约束?
非常感谢!
一些错误但是
.mod
int Time = ...;
range T=0..Time;
// Parameters
int d [T] = ...; // demand in period t
int K [T] = ...; // fixed order cost in period t
int h [T] = ...; // unit holding cost in period t
int p [T] = ...; // fixed cost of increasing WH size in period t
int q [T] = ...; // fixed cost of increasing WH size in period t
int e [T] = ...; // variable cost of increasing WH size in period t
int c [T] = ...; // variable cost of decreasing WH size in period t
int r [T] = ...; // WH rental cost per unit in period t
dvar int+ x[T]; //order size in period t
dvar int+ i[T]; //inventory lvl at the end of period t
dvar int+ w[T]; // warehouse size at the end of period t
dvar int+ u[T]; // warehouse size expansion at beginning of period t
dvar int+ v[T]; // warehouse size contraction at beginning of period t
dvar boolean y[T]; // binary variable for ordering in period t
dvar boolean z1[T]; // binary variable for WH expansion in period t
dvar boolean z2[T]; // binary variable for WH contraction in period t
//objecTve funcTon
dexpr int Cost = sum(t in T)
(K[t]*y[t]+h[t]*i[t]+p[t]*z1[t]+e[t]*u[t]+q[t]*z2[t]+c[t]*v[t]+r[t]*w[t]);
minimize Cost;
//constraints
subject to {
forall(t in T:(t-1) in T) {
i[t-1] + x[t] - d[t] == i[t];
w[t-1] + u[t] - v[t] == w[t];
i[t] <= w[t];
x[t] <= d[t]*y[t];
u[t] <= d[t]*z1[t];
v[t] <= d[t]*z2[t];
i[0]==0;
}
}
.dat
Time=2;
// Try product =1
d = [2000,1500];
K = [5000,5000];
h = [1,1];
p = [300,300];
q = [600,600];
e = [1,1];
c = [3,3];
r = [4,4];
工作正常
我正在尝试优化 CPLEX OPL 中的以下问题。我已经定义了参数和决策变量。但是,当我尝试制定 objective 函数和约束时,我似乎遇到了问题,因为我在 objective 函数调用 'cannot use type range for int' 的行中收到错误。我不确定这里有什么问题。
同样在约束公式中,我在制定约束以确保变量 I 和 W 在两个相应的周期之间保持平衡时遇到了问题。 CPLEX 错误读取运算符不适用于范围 - int.
我试图重现的问题是:
time=2;
// Try product =1
d = [2000,1500];
k = [5000,5000];
h = [1,1];
p = [300,300];
q = [600,600];
e = [1,1];
c = [3,3];
r = [4,4];
这是我到目前为止在模型中得出的结论:
int Time = ...; range T=1..Time;
// Parameters
int d [T] = ...; // demand in period t
int K [T] = ...; // fixed order cost in period t
int h [T] = ...; // unit holding cost in period t
int p [T] = ...; // fixed cost of increasing WH size in period t
int q [T] = ...; // fixed cost of increasing WH size in period t
int e [T] = ...; // variable cost of increasing WH size in period t
int c [T] = ...; // variable cost of decreasing WH size in period t
int r [T] = ...; // WH rental cost per unit in period t
dvar int+ x[T]; //order size in period t
dvar int+ i[T]; //inventory lvl at the end of period t
dvar int+ w[T]; // warehouse size at the end of period t
dvar int+ u[T]; // warehouse size expansion at beginning of period t
dvar int+ v[T]; // warehouse size contraction at beginning of period t
dvar boolean y[T]; // binary variable for ordering in period t
dvar boolean z1[T]; // binary variable for WH expansion in period t
dvar boolean z2[T]; // binary variable for WH contraction in period t
//objecTve funcTon
dexpr int Cost = sum(t in T)(K[T]*y[T]+h[T]*i1[T]+p[T]*z1[T]+e[T]*u[T]+q[T]*z2[T]+c[T]*v[T]+r[T]*w1[T]);
minimize Cost;
//constraints
subject to {
forall(t in T) {
i[T-1] + x[T] - d[T] == i[T];
w[T-1] + u[T] - v[T] == w[T];
i[T] <= w[T];
x[T] <= d[T]*y[T];
u[T] <= d[T]*z1[T];
v[T] <= d[T]*z2[T];
I[0]==0;
}
}
有人可以给我一些建议,告诉我我在 objective 函数公式中做错了什么,以及我如何正确地制定 I(t-1)+x-d=I(t) 的约束?
非常感谢!
一些错误但是
.mod
int Time = ...;
range T=0..Time;
// Parameters
int d [T] = ...; // demand in period t
int K [T] = ...; // fixed order cost in period t
int h [T] = ...; // unit holding cost in period t
int p [T] = ...; // fixed cost of increasing WH size in period t
int q [T] = ...; // fixed cost of increasing WH size in period t
int e [T] = ...; // variable cost of increasing WH size in period t
int c [T] = ...; // variable cost of decreasing WH size in period t
int r [T] = ...; // WH rental cost per unit in period t
dvar int+ x[T]; //order size in period t
dvar int+ i[T]; //inventory lvl at the end of period t
dvar int+ w[T]; // warehouse size at the end of period t
dvar int+ u[T]; // warehouse size expansion at beginning of period t
dvar int+ v[T]; // warehouse size contraction at beginning of period t
dvar boolean y[T]; // binary variable for ordering in period t
dvar boolean z1[T]; // binary variable for WH expansion in period t
dvar boolean z2[T]; // binary variable for WH contraction in period t
//objecTve funcTon
dexpr int Cost = sum(t in T)
(K[t]*y[t]+h[t]*i[t]+p[t]*z1[t]+e[t]*u[t]+q[t]*z2[t]+c[t]*v[t]+r[t]*w[t]);
minimize Cost;
//constraints
subject to {
forall(t in T:(t-1) in T) {
i[t-1] + x[t] - d[t] == i[t];
w[t-1] + u[t] - v[t] == w[t];
i[t] <= w[t];
x[t] <= d[t]*y[t];
u[t] <= d[t]*z1[t];
v[t] <= d[t]*z2[t];
i[0]==0;
}
}
.dat
Time=2;
// Try product =1
d = [2000,1500];
K = [5000,5000];
h = [1,1];
p = [300,300];
q = [600,600];
e = [1,1];
c = [3,3];
r = [4,4];
工作正常