Originally posted by: Ahlem
Hi,
I'm working on job shop scheduling problem and i'm using Cplex in Java. But, i found a problem in the initialization of the decision variable Yi1j1i2j2k (5D), it's a boolean variable takes 1 if operation Oi1,j1 precedes operation Oi2,j2 on machine k. The program show me this exception " java.lang.ArrayIndexOutOfBoundsException: 6" but I don't know how to initialize a variable 5 dimensions.
I put my code below, if I have other errors please checked for me (i have attached my mathematical formulation).
Thank you.
import java.util.ArrayList;
import ilog.concert.IloException;
import ilog.concert.IloLinearNumExpr;
import ilog.concert.IloNumVar;
import ilog.concert.IloQuadNumExpr;
import ilog.cplex.IloCplex;
public class evaluationCplex {
public evaluationCplex()
{
super();
}
public static void modell ()
{
Information f = new Information(); // I call class information to get from the benchmark the number of jobs, the number of resources(machines) and the number of operation by job
int job = f.getNbjob();
int ressource = f.getNbressource();
int operation = f.getNboperationparjob();
Assignment a = new Assignment();
ArrayList<MatriceGlobal> MG = a.MatrixRandom(); // I call class Assignment to get the assignment matrices of all individuals knowing that each individual has 10 matrices (number of jobs)
int L = 1000; // A large number
try {
IloCplex cplex = new IloCplex(); //define new model
//variables
Matrice M = new Matrice (ressource,operation);
int [][][] x = new int[job][][]; // I don't use xijk in my code as a decision variable as it is indicated in the mathematical formulation because I am going to extract it from my code but it is boolean: takes 1 if machine k is selected for operation Oij; 0 otherwwise.
IloNumVar[][][] c = new IloNumVar[job][][];
IloNumVar[][][] p = new IloNumVar[job][][];
IloNumVar[][][][][] y = new IloNumVar[job][][][][];
IloNumVar [] CTime = new IloNumVar[job];
for(int m=0; m<MG.size();m++)
{
for (int i = 0; i < job; i++) //initialize cijk and pijk
{
c[i] = new IloNumVar[MG.get(m).get(i).getX()][]; //MG.get(m).get(i).getX() ==> to get the number of operation for the job i
p[i] = new IloNumVar[MG.get(m).get(i).getX()][];
for (int j = 0; j < MG.get(m).get(i).getX(); j++)
{
c[i][j]= cplex.numVarArray(ressource, 0, Double.MAX_VALUE);
p[i][j]= cplex.numVarArray(ressource, 0, Double.MAX_VALUE);
}
}
for (int i1 = 0; i1 < job; i1++) //decision variable Yi1j1i2j2k
{
y[i1] = new IloNumVar[MG.get(m).get(i1).getX()][][][];
for (int j1 = 0; j1 < MG.get(m).get(i1).getX(); j1++)
{
y[i1][j1]= new IloNumVar[MG.get(m).get(i1).getY()][][]; //MG.get(m).get(i).getY() ==> to get the number of ressource
for (int i2 = 0; i2 < job; i2++)
{
y[i1][j1][i2] = new IloNumVar[MG.get(m).get(i2).getX()][];
for (int j2 = 0; j2 < MG.get(m).get(i2).getX(); j2++)
{
y[i1][j1][i2][j2]= cplex.boolVarArray(ressource);
}
}
}
}
for (int j = 0; j < job; j++)
{
CTime[j] = cplex.numVar(0, Double.MAX_VALUE);
}
for(int i1 = 0; i1 < job; i1++)
{
for (int j1 = 0; j1 < MG.get(m).get(i1).getX(); j1++)
{
for (int i2 = 0; i2 < job; i2++)
{
for (int j2 = 0; j2 < MG.get(m).get(i2).getX(); j2++)
{
for (int k = 0; k < ressource ; k++)
{
IloLinearNumExpr expr = cplex.linearNumExpr(); //constraint 3
expr.addTerm(1.0, y[i1][j1][i2][j2][k]);
cplex.addLe(expr, 1);
IloLinearNumExpr expr1 = cplex.linearNumExpr(); //constraint 4
expr1.addTerm(1.0, y[i2][j2][i1][j1][k]);
cplex.addLe(expr, expr1);
IloLinearNumExpr expr3 = cplex.linearNumExpr(); //constraint 5
expr3.addTerm(1.0, c[i1][j1][k]);
cplex.addGe(expr3, cplex.sum(c[i2][j2][k], cplex.prod(y[i1][j1][i2][j2][k], p[i1][j1][k]), cplex.sum(-L, cplex.prod(L, y[i2][j2][i1][j1][k]))));
//constraint 6
cplex.addGe(expr3, cplex.sum(c[i2][j2-1][k], cplex.prod(y[i1][j1][i2][j2][k], p[i1][j1][k])));
}
}
}
}
}
for (int i = 0; i < job; i++) //constraint 7
{
IloLinearNumExpr expr = cplex.linearNumExpr();
expr.addTerm(1.0, CTime[i]);
for (int k =0 ; k<ressource; k++)
{
cplex.addGe(expr, c[i][MG.get(m).get(job).getX()][k]);
}
}
//Objective
IloLinearNumExpr objective = cplex.linearNumExpr();
for (int i = 0; i < job; i++)
{
int [][] mat = MG.get(m).get(i).getMatrice(); //MG.get(m).get(i).getMatrice() ==> to get the matrix of each job
for (int j = 0; j < MG.get(m).get(i).getX(); j++)
{
for (int k = 0; k < MG.get(m).get(i).getY(); k++)
{
if (mat[j][k]==1)
{
x[i][j][k]=1; //if machine k is selected for operation Oij
}
else
{
x[i][j][k]=0; //otherwise
}
objective.addTerm(x[i][j][k], p[i][j][k]); // Cmax
}
}
cplex.addGe(objective, CTime[i]); //constraint 8
}
cplex.addMinimize(objective);
}
if (cplex.solve())
{
System.out.println("Objective = " + cplex.getObjValue());
}
else
{
System.out.println("Problem not solved");
}
}
catch (IloException exc)
{
exc.printStackTrace();
}
}
}
#CPLEXOptimizers#DecisionOptimization