[英]CPLEX optimization array error in objective function
我正在尝试优化 CPLEX OPL 中的以下问题。 我已经定义了参数和决策变量。 但是,当我尝试制定目标函数和约束时,我似乎遇到了一个问题,因为我在目标函数调用“不能使用类型范围为 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;
}
}
有人能给我一些关于我在目标函数公式中做错了什么的建议,以及我如何正确制定约束 I(t-1)+xd=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];
工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.