如何修复数据元素“;”意想不到的“?”超过 3 维数组出错并修改数据?

问题描述 投票:0回答:1

我是 CPLEX 初学者,目前尝试使用以下代码和输入数据练习多目标模型以进行个人学习:

int Typeprod=...; //type of  product //
int Supplierloca=...; //supplier location //
{int} J1=...; //locations of existing whs//
{int} J2=...; //mobile facilities locations//
{int} J= J1 inter J2; //possible location of whs //
int NumbDC=...; //number of distribution centers//
int Customer=...; //number of customer //
int Timeperiod=...; //time periods//
int Routes=...; //number of routes//
int NumbDisasterscenario=...; //number of scenario//


//range of sets and input data//
range M=1..Typeprod; // m type of prod//
range I= 1..Supplierloca; //supplier location i//
range K=1..NumbDC; // k distribution centers//
range L=1..Customer; //l customer//
range T=1..Timeperiod; //time t//
range R=1..Routes; //route r//
range S=1..NumbDisasterscenario; //disaster scenario s//


//parameters or input data//
float Pi[S]=...; //probability of disaster//
int o=...; //fixed cost of establishing a mobile facility//
int q=...; //equipping cost of existing whs//
int e[K]=...; //capacity of DC k //
int f[J1]=...; //capacity of a product reception by existing whs at location j1//
int c[J2]=...; // para chua dc them vào report- - by mobile facilities// 
int p[S][I][T]=...; //expected supply of product at location i and period t under scenario s//
//tuple set for 
float Psi[I][M]=...; //exchange rate of product m at location i//
int d[S][M][L][T]=...; //product demand at customer l in period t under s//
int ti[L][T]=...; //travel time from DC in other place to cus l in period t//
int t1[J][K][R]=...; //travel time from whs j to dc k with route r//
int t2[K][L]=...; //travel time from DC k to customer l//
int Alpha[S][J1][T]=...; //equal to 1 if J1 is disrupted//
int Beta[S][K][T]=...; // equal to 1 if DC k is disrupted//
int Xi[S][J][K][R][T]=...; //equal to 1 if route r between whs J and DC k is disrupted//
int N=...; //number of mobile whs//

//decision variables//

//int+//
dvar int+ V[S][M][K][T];
dvar int+ F[S][M][J][K][T][R];
dvar int+ U[S][M][K][L][T];
dvar int+ G[S][I][J][T];
dvar int+ H[S][M][L][T];

//binary//
dvar boolean Z[J1];
dvar boolean Y[S][J2][I];
dvar boolean X[S][J][K][R][T];
dvar boolean W[S][J][I][T];

//objective functions//

//Minimize delivery time//
minimize 
sum(m in M,j in J,k in K,t in T, r in R, s in S)Pi[s]*F[s][m][j][k][t][r]*t1[j][k][r] +
 sum(m in M,k in K, l in L,t in T,s in S)Pi[s]*U[s][m][k][l][t]*t2[k][l] +
  sum(m in M,l in L,t in T,s in S)Pi[s]*H[s][m][l][t]*ti[l][t]; 

//Minimize total costs//
minimize 
o*N + sum(j in J1)q*Z[j];

subject to {

//3-4 quantity of product from each urban area not exceed expected supply of products//
forall (i in I, j in J, t in T, s in S){
 G[s][i][j][t] <= p[s][i][t]*W[s][j][i][t]; 
 sum(j in J) G[s][i][j][t] <= p[s][i][t];   
}

//5- Limit the capacity of whs at each facility - cannot exceed total capacity from existing and mobile whs//
forall ( j in J, j1 in J1, j2 in J2, t in T, s in S, i in I){
 sum(i in I) G[s][i][j][t] <= Z[j1]*f[j1] + c[j2]*Y[s][j2][i];  //remember to add this para cj into report//
}

//6- In each location, one of existing whs or mobile facility is established//
forall (j1 in J1,j2 in J2, t in T, s in S, i in I){
 Z[j1]+Y[s][j2][i] <= 1;  //6//
}

//7 - Suppliers can only be assigned to exist whs that not disrupted//
forall ( j in J, i in I, j1 in J1, j2 in J2, t in T, s in S){ 
 W[s][i][j][t] <= (1- Alpha[s][j1][t])*Z[j1] + Y[s][j2][i];
}

//8 - Value of prod m output is less than the input value at whs//
forall (m in M, j in J, t in T, s in S, r in R){
 sum(k in K, t in T)F[s][m][j][k][t][r] <= sum (i in I)Psi[i][m]*G[s][i][j][t];
}

//9- Capacity at each DC k without disruption//
forall (k in K, t in T, s in S){
 sum(j in J, r in R, m in M)F[s][m][j][k][t][r] <= e[k]*(1- Beta[s][k][t]);
}

//10 - If whs j1 is assigned to DC k, facilities and routes are not disrupted//
forall (j in J, j1 in J1, k in K, t in T, r in R, s in S) {
X[s][j][k][t][r] <= (1- Alpha[s][j1][t])*(1- Beta[s][k][t])*(1- Xi[s][j][k][r][t])*Z[j1];
}

//11 - If a mobile facility j2 is assign to DC k, facility is not disrupted//
forall (j in J, j2 in J2, k in K, t in T, r in R, s in S) {
X[s][j][k][t][r] <= Y[s][j2][t]*(1- Beta[s][k][t])*(1- Xi[s][j][k][r][t]);
}

//12 - One route is allocated between each WHS and DC//
forall (j in J, k in K, t in T, s in S) {
sum(r in R)X[s][j][k][t][r] <= 1;
}
 
//13 - Only one WHS is assigned to one DC//
forall (j in J, t in T, s in S) {
sum(k in K, r in R)X[s][j][k][t][r] <= 1;
}

//14 - Products cannot be transported from a mobile WHS to an unassigned DC//
forall ( k in K, j in J, j2 in J2, t in T, r in R, s in S) {
sum( m in M)F[s][m][j][k][t][r] <= c[j2]*X[s][j][k][t][r];
}

//15 - A DC can be assigned to customer when not disrupted only //
forall (k in K, t in T, s in S){
  sum(m in M, l in L)U[s][m][k][l][t] <= e[k]*(1- Beta[s][k][t]);
} 

//16 - The amount of products delivered to each customer from DCs in other provinces//
forall (m in M, l in L, t in T, s in S) {
d[s][m][l][t] - sum(k in K)U[s][m][k][l][t] == H[s][m][l][t];
}

//17 - Product inventory balance at DCs//
forall (m in M, k in K, t in T, s in S) {
V[s][m][k][t-1]+sum(j in J, r in R)F[s][m][j][k][t][r] == V[s][m][k][t] + sum(l in L)U[s][m][k][l][t];
}

//18 - The number of mobile WHS in each period t does not exceed the number of established mobile facilities//
forall (t in T, s in S) {
sum(j in J2)Y[s][j][t] <= N;
}

//19 - Capacities for storing at DC k // 
forall (k in K, t in T, s in S) {
sum(m in M)V[s][m][k][t] <= e[k];
}

//20 - Eligible domains of decision variables//
forall (m in M, i in I, j in J, k in K, l in L, t in T, r in R, s in S) {
V[s][m][k][t] >= 0;
F[s][m][j][k][t][r] >= 0;
U[s][m][k][l][t] >= 0;
G[s][i][j][t] >= 0;
H[s][m][l][t] >= 0;
0 <= Z[j] <=1; 
0 <= Y[s][j][t] <=1;
0 <= X[s][j][k][t][r] <=1;
0 <= W[s][i][j][t] <=1;
}
}

输入数据如下:

 Typeprod= 1 ;
 Supplierloca= 1 ;
 J1= {1}  ;
 J2= {2}  ;
 N= 1;
 NumbDC= 1 ;
 Customer= 1 ;
 Timeperiod= 12 ;
 Routes= 1 ;

 NumbDisasterscenario= 1;

//probability of scenario//
 Pi= 0.1; 
 
 o= 180 ;

 q= 1000 ;

 e= 3500 ; 

 f= 4500 ; 
 
 c= 900 ; 
 
 p= [ [600, 520, 370, 150, 250, 440, 350, 380, 500, 610, 740, 380];
 
 Psi= 0.05;
 
 d= [150, 170, 300, 220, 110, 550, 50, 190, 70, 120, 60, 1420, 320]  ;
 
 ti= [70 85 100 95 90 60 75 70 65 85 80 90 ]  ;
 
 t1= 35 ;
 
 t2= 45  ;

 Alpha= 0;
 
 Beta= 0 ;
 
 Xi= 0;

问题出现在Pi=0.1的数据行,导致错误:数据元素“;”意外的“?”,我是否有可能错误地定义了数据类型?而且,我仍然在努力修改一些特定数据,因为它的索引太多(例如:产品M的产品需求,客户L在T期间和场景S => d[S][M][L][T ]。)

那么如何解决这个问题并修改数据类型来达到要求呢?

非常感谢您,祝您有愉快的一天!

optimization cplex opl
1个回答
0
投票

你忘了括号:Pi= [0.1];

© www.soinside.com 2019 - 2024. All rights reserved.