gpt4 book ai didi

目标函数中的 CPLEX 优化数组错误

转载 作者:行者123 更新时间:2023-12-04 17:10:06 29 4
gpt4 key购买 nike

我正在尝试优化 CPLEX OPL 中的以下问题。我已经定义了参数和决策变量。但是,当我尝试制定目标函数和约束时,我似乎遇到了一个问题,因为我在目标函数调用行中收到错误“不能使用 int 的类型范围”。我不确定这里出了什么问题。

同样在约束公式中,我在制定约束以确保变量 I 和 W 在两个相应的周期之间保持平衡时遇到了问题。 CPLEX 错误读取运算符不适用于范围 - int。

我试图重现的问题是: enter image description here这是我当前的数据文件:

 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)+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 优化数组错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69643354/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com