Mathematics model:
Code:
using CP;
int numI = 4;
int numP = 3;
int B = 90000000;
// Define sets
range I = 1..numI; // set of suppliers
range P = 1..numP; // set of products
// Define parameters
float v[I][P]; // production cost per product for each supplier
float f[I][P]; // fixed costs of sourcing from supplier i
float u1[I][I];
float u2[I][I];
float u3[I][I];
int C[I][P]; // Capacity of supplier i (share of the total demand that can be sourced from i)
float MOQ[I][P]; // Minimum order quantity of supplier i (in percent of total demand)
int D[1][P]; // demand of each product throughout 1 year
int Nmax[P] = [2,2,2];
int Nstr[P]=[1,1,1];
int strat[I][P];
float u[I][I][P];
for (int i in I)
for (int j in I)
for (int p in P)
if (p == 1)
u[i][j][p] = u1[i][j]
else if (p == 2)
u[i][j][p] = u2[i][j]
else
u[i][j][p] = u3[i][j]
// Define decision variables
dvar boolean y[I][P]; // binary variable indicating if a supplier produces a product
dvar float+ x[I][P]; // proportion of the total demand ordered from supplier i
// Decision expressions
dexpr float Z = sum(i in I, p in P) (D[1][p]*v[i][p]*x[i][p]) + sum(i in I, p in P) (f[i][p]*y[i][p]);
dexpr float K = sum(i in I, j in I, p in P) u[i][j][p]*x[i][p]*x[j][p];
minimize staticLex(Z, K);
// Define constraints
subject to {
forall(p in P) {
sum(i in I) x[i][p] == 1;
sum(i in I) (D[1][p]*v[i][p]*x[i][p] + f[i][p]*y[i][p]) <= B;
2 <= sum(i in I) y[i][p];
sum(i in I) y[i][p] <= Nmax[p];
Nstr[p] <= sum(i in I) y[i][p]*strat[i][p];
}
forall(i in I, p in P) {
x[i][p] <= C[i][p]*y[i][p];
MOQ[i][p]*y[i][p] <= x[i][p];
0<= x[i][p] <= 1;
0<= y[i][p] <= 1;
0<= C[i][p] <= 1;
0<= MOQ[i][p] <= 1;
0<= strat[i][p] <= 1;
}
}
I ran the code and here is its results:
Impossible to load model. final Unknown OPL Problem Marker syntax error, unexpected '(', expecting (identifier) or '[' final.mod /final 27:5-6 D:/final/final.mod OPL Outline Problem Marker
How can I fix it?
You should use an execute block to do computations. The following works better:
using CP;
int numI = 4;
int numP = 3;
int B = 90000000;
// Define sets
range I = 1..numI; // set of suppliers
range P = 1..numP; // set of products
// Define parameters
float v[I][P]; // production cost per product for each supplier
float f[I][P]; // fixed costs of sourcing from supplier i
float u1[I][I];
float u2[I][I];
float u3[I][I];
dvar int C[I][P]; // Capacity of supplier i (share of the total demand that can be sourced from i)
dvar int MOQ[I][P]; // Minimum order quantity of supplier i (in percent of total demand)
dvar int D[1..1][P]; // demand of each product throughout 1 year
int Nmax[P] = [2,2,2];
int Nstr[P]=[1,1,1];
dvar int strat[I][P];
float u[I][I][P];
execute
{
for (var i in I)
for (var j in I)
for (var p in P)
if (p == 1)
u[i][j][p] = u1[i][j]
else if (p == 2)
u[i][j][p] = u2[i][j]
else
u[i][j][p] = u3[i][j];
}
// Define decision variables
dvar boolean y[I][P]; // binary variable indicating if a supplier produces a product
dvar int+ x[I][P]; // proportion of the total demand ordered from supplier i
// Decision expressions
dexpr float Z = sum(i in I, p in P) (D[1][p]*v[i][p]*x[i][p]) + sum(i in I, p in P) (f[i][p]*y[i][p]);
dexpr float K = sum(i in I, j in I, p in P) u[i][j][p]*x[i][p]*x[j][p];
minimize staticLex(Z, K);
// Define constraints
subject to {
forall(p in P) {
sum(i in I) x[i][p] == 1;
sum(i in I) (D[1][p]*v[i][p]*x[i][p] + f[i][p]*y[i][p]) <= B;
2 <= sum(i in I) y[i][p];
sum(i in I) y[i][p] <= Nmax[p];
Nstr[p] <= sum(i in I) y[i][p]*strat[i][p];
}
forall(i in I, p in P) {
x[i][p] <= C[i][p]*y[i][p];
MOQ[i][p]*y[i][p] <= x[i][p];
0<= x[i][p] <= 1;
0<= y[i][p] <= 1;
0<= C[i][p] <= 1;
0<= MOQ[i][p] <= 1;
0<= strat[i][p] <= 1;
}
}