我在运行 cplex 时遇到一些错误: OPL 无法提取表达式:forall(i in 1..193, t in 1..24) p[i][(tau[i](-1)+h[i]5+t)]+(e [i]+n[i](-5))(S[i][(t+(-1))]+S[i][t](-1))+(sum(j in 1) ..3) p[i][t]b[i][j])(-1) <= d[i][t]. OPL cannot extract expression: forall(i in 1..193, t in 1..24) p[i][(tau[i](-1)+h[i]5+t)]+(e[i]+n[ i]5)(S[i][(t+(-1))]+S[i][t](-1))+(sum(j in 1..3) p[i][ t]b[i][j])(-1) >= d[i][t]。 OPL 无法提取表达式: forall(i in 1..193, t in 1..24) sum(j in 1..3) p[i][t]*b[i][j]+d[i] [t]+e[i]*S[i][t] == e[i]S[i][(t+(-1))]+p[i][(t+tau[i] (-1))]。
这是我的代码:
// INDEX
int I=...;
int R =...;
int T=...;
range items = 1..I; //Index of items in the production system i
range resources = 1..R; //Index of production resources defining capacity r
range times = 1..T; //Index of discrete periods in the planning horizon t
range trucks = 1..3; //Index of item j according to the bill of materials
// DATA & PARAMATER
int lamda=...;
float d[items][times]=...; //Independent (external) demand for item i in period t
float b[items][trucks]=...; //Number of units of item i required per unit of item j according to the bill of materials
int tau[items]=...; //Time to process or purchase a lot of the product i
float f[items][resources]=...; //Fraction of resource r required to process a unit of item i
float w[items][resources]=...; //Fraction of resource r required to set up a unit of item i
float ma[resources][times]=...;//Maximum fraction of resourcer that can be added in period t
float e[items]=...; //Inventory accuracy of item i
float l[items]=...; //Minimum production lot size for item i
float ac[resources][times]=...;//Cost per added capacity fraction to resource r in period t
float wc[items]=...; //Total fixed cost of setting up the production/purchase of item i in a period
float sc[items]=...; //Inventory holding cost per period for one unit of item i
float s0[items]=...; //Initial on-hand inventory for item i
int h[items]=...; // Maximum slack for production or purchase time
float g[items][resources]=...; // Maximum tolerance of capacity for manufacturing
float n[items]=...; // Tolerance for inventory accuracy
//DECISION VARIABLES
dvar int+ p[items][times]; //Production quantity of item i in period t
dvar int+ S[items][times]; //Final inventory of item i in period t
dvar int+ a[resources][times]; //Added fraction of resource r in period t
dvar int+ q[items][times]; //Binary production indicator for product i in period t
// Auxiliary variable
dvar float+ sreal[items][times];
// OBLJECTIVE FUNCTION
minimize sum(t in times, r in resources) a[r][t]*ac[r][t] + sum(t in times, i in items)q[i][t]*wc[i] + sum(t in times, i in items) e[i]*S[i][t]*sc[i] ;
// Flow constraint
subject to {
forall(t in times, r in resources)
sum (i in items)(p[i][t]*f[i][r] + q[i][t]*w[i][r]) <= 1 + a[r][t]; //(1)
forall (i in items, t in times)
sum (j in trucks) p[i][t]*b[i][j] + d[i][t] + e[i]*S[i][t] == e[i]*S[i][t-1] + p[i][t-tau[i]]; //(2)
forall (r in resources, t in times)
a[r][t] <= ma[r][t]; //(3)
forall (i in items, t in times)
p[i][t] >= q[i][t]*l[i]; //(4)
forall(i in items, r in resources, t in times)
sum(j in trucks) (p[i][t] * (f[i][r] + (1 - lamda) * q[i][t] * g[i][r]) + q[i][t] * w[i][r]) <= 1 + a[r][t];//(5)
forall(i in items, t in times)
p[i][t - (tau[i] + (1 - lamda) * h[i])] + ((e[i] + n[i] * (1 - lamda)) * (S[i][t - 1] - S[i][t])) - sum(j in trucks) (p[i][t] * b[i][j]) <= d[i][t]; //(6)
forall(i in items, t in times)
p[i][t - (tau[i] + (1 - lamda) * h[i])] + ((e[i] - n[i] * (1 - lamda)) * (S[i][t - 1] - S[i][t])) - sum(j in trucks) (p[i][t] * b[i][j]) >= d[i][t]; //(7)
forall(i in items, t in times)
(e[i] + n[i] * (1 - lamda)) * S[i][t] <= sreal[i][t]; //(8)
forall(i in items, t in times)
(e[i] - n[i] * (1 - lamda)) * S[i][t] >= sreal[i][t]; //(9)
}
请帮助我
您多次使用 t-1,因此您应该确保 t-1 属于时间。 例如,你应该改变
forall(i in items, t in times)
进入
forall(i in items, t in times:(t-1) in times)
以下模型运行良好:
// INDEX
int I=2;
int R =3;
int T=4;
range items = 1..I; //Index of items in the production system i
range resources = 1..R; //Index of production resources defining capacity r
range times = 1..T; //Index of discrete periods in the planning horizon t
range trucks = 1..3; //Index of item j according to the bill of materials
// DATA & PARAMATER
int lamda=1;
float d[items][times]; //Independent (external) demand for item i in period t
float b[items][trucks]; //Number of units of item i required per unit of item j according to the bill of materials
int tau[items]; //Time to process or purchase a lot of the product i
float f[items][resources]; //Fraction of resource r required to process a unit of item i
float w[items][resources]; //Fraction of resource r required to set up a unit of item i
float ma[resources][times];//Maximum fraction of resourcer that can be added in period t
float e[items]; //Inventory accuracy of item i
float l[items]; //Minimum production lot size for item i
float ac[resources][times];//Cost per added capacity fraction to resource r in period t
float wc[items]; //Total fixed cost of setting up the production/purchase of item i in a period
float sc[items]; //Inventory holding cost per period for one unit of item i
float s0[items]; //Initial on-hand inventory for item i
int h[items]; // Maximum slack for production or purchase time
float g[items][resources]; // Maximum tolerance of capacity for manufacturing
float n[items]; // Tolerance for inventory accuracy
//DECISION VARIABLES
dvar int+ p[items][times]; //Production quantity of item i in period t
dvar int+ S[items][times]; //Final inventory of item i in period t
dvar int+ a[resources][times]; //Added fraction of resource r in period t
dvar int+ q[items][times]; //Binary production indicator for product i in period t
// Auxiliary variable
dvar float+ sreal[items][times];
// OBLJECTIVE FUNCTION
minimize sum(t in times, r in resources) a[r][t]*ac[r][t] + sum(t in times, i in items)q[i][t]*wc[i] + sum(t in times, i in items) e[i]*S[i][t]*sc[i] ;
// Flow constraint
subject to {
forall(t in times, r in resources)
sum (i in items)(p[i][t]*f[i][r] + q[i][t]*w[i][r]) <= 1 + a[r][t]; //(1)
forall (i in items, t in times:(t-1) in times)
sum (j in trucks) p[i][t]*b[i][j] + d[i][t] + e[i]*S[i][t] == e[i]*S[i][t-1] + p[i][t-tau[i]]; //(2)
forall (r in resources, t in times)
a[r][t] <= ma[r][t]; //(3)
forall (i in items, t in times)
p[i][t] >= q[i][t]*l[i]; //(4)
forall(i in items, r in resources, t in times)
sum(j in trucks) (p[i][t] * (f[i][r] + (1 - lamda) * q[i][t] * g[i][r]) + q[i][t] * w[i][r]) <= 1 + a[r][t];//(5)
forall(i in items, t in times:(t-1) in times)
p[i][t - (tau[i] + (1 - lamda) * h[i])] + ((e[i] + n[i] * (1 - lamda)) * (S[i][t - 1] - S[i][t])) - sum(j in trucks) (p[i][t] * b[i][j]) <= d[i][t]; //(6)
forall(i in items, t in times:(t-1) in times)
p[i][t - (tau[i] + (1 - lamda) * h[i])] + ((e[i] - n[i] * (1 - lamda)) * (S[i][t - 1] - S[i][t])) - sum(j in trucks) (p[i][t] * b[i][j]) >= d[i][t]; //(7)
forall(i in items, t in times:(t-1) in times)
(e[i] + n[i] * (1 - lamda)) * S[i][t] <= sreal[i][t]; //(8)
forall(i in items, t in times:(t-1) in times)
(e[i] - n[i] * (1 - lamda)) * S[i][t] >= sreal[i][t]; //(9)
}