簡體   English   中英

目標函數中的 CPLEX 優化數組錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM