Originally posted by: Ahlem
Hi,
Thanx you so much
.
But, i have one more question please. In my mathematical formulation that you find below, I have other constraints. When I use ILOG.CP.jar without cplex.jar (and I think it's possible) the program displays this error :
ilog.concert.IloException: CP Optimizer Community Edition solves problems with a search space of up to 2^1000
at ilog.cp.cppimpl.cp_wrapJNI.IloCP_solve(Native Method)
at ilog.cp.cppimpl.IloCP.solve(IloCP.java:149)
I think that my problem is too big for the Community Edition.
This is my piece of code:
import java.util.List;
import java.util.ArrayList;
import ilog.concert.IloException;
import ilog.concert.IloIntExpr;
import ilog.concert.IloIntVar;
import ilog.concert.IloIntervalVar;
import ilog.concert.IloLinearNumExpr;
import ilog.concert.IloModel;
import ilog.concert.IloNumVar;
import ilog.concert.IloNumVarType;
import ilog.concert.cppimpl.IloObjective;
import ilog.cplex.IloCplex;
import ilog.cp.*;
public class evaluationCplex {
public evaluationCplex() {
super();
}
static class IntervalVarList extends ArrayList<IloIntervalVar> {
public IloIntervalVar[] toArray() {
return (IloIntervalVar[]) this.toArray(new IloIntervalVar[this.size()]);
}
}
static IloIntExpr[] arrayFromList(List<IloIntExpr> list) {
return (IloIntExpr[]) list.toArray(new IloIntExpr[list.size()]);
}
public static void modell() {
Information f = new Information();
MatriceGlobal benchmrak = f.getM();
int job = f.getNbjob();
int ressource = f.getNbressource();
int operation = f.getNboperationparjob();
Assignment a = new Assignment();
ArrayList<MatriceGlobal> MG = a.MatrixRandom();
/*
* for(int i=0; i<MG.size();i++)
*
* { for (int j=0 ; j < job ; j++)
* { MG.get(i).get(j).afficher(); }
* System.out.println("mara okhraa"); }
*/
int L = 1000;
int failLimit = 10000;
try {
IloCP cp = new IloCP();
IloCplex cplex = new IloCplex(); // define new model
IntervalVarList[] machines = new IntervalVarList[ressource];
for (int j = 0; j < ressource; j++)
machines[j] = new IntervalVarList();
List<IloIntExpr> ends = new ArrayList<IloIntExpr>();
// variables
Matrice M = new Matrice(ressource, operation);
int [][][] x = new int[job][][];
IloNumVar [][][] c = new IloNumVar[job][][];
IloNumVar [][][] s = new IloNumVar[job][][];
IloNumVar[][][][][] y = new IloNumVar[job][][][][];
IloNumVar [] CTime = new IloNumVar[job];
IloIntervalVar[][] information = new IloIntervalVar[job][operation];
IntervalVarList[] jobs = new IntervalVarList[job]; //hedhi mtaa l'affichage f solve()
for (int m = 0; m < MG.size(); m++) //to extract my information from bechmarks
{
for (int i = 0; i < job; i++) {
c[i] = new IloNumVar[MG.get(m).get(i).getX()][];
s[i] = new IloNumVar[MG.get(m).get(i).getX()][];
for (int j = 0; j < MG.get(m).get(i).getX(); j++) {
c[i][j] = cp.numVarArray(ressource, 0, Double.MAX_VALUE);
s[i][j] = cp.numVarArray(ressource, 0, Double.MAX_VALUE);
}
}
for (int i1 = 0; i1 < job; i1++) {
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[job][][];
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] = cp.boolVarArray(ressource);
}
}
}
}
for (int j = 0; j < job; j++) {
CTime[j] = cp.numVar(0, Double.MAX_VALUE);
}
for (int i1 = 0; i1 < job; i1++) { //Initialize p[i][j][k]
int[][] MatBinaire = MG.get(m).get(i1).getMatrice();
int[][] mat = benchmrak.get(i1).getMatrice();
int[][][] p = new int[job][MG.get(m).get(i1).getX()][MG.get(m).get(i1).getY()];
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++) {
if (MatBinaire[j1][k] ==1) {
int duree = mat[j1][k];
p[i1][j1][k] = duree;
}
cp.addGe(c[i1][j1][k],
cp.sum(c[i2][j2][k], cp.prod(y[i1][j1][i2][j2][k], p[i1][j1][k]),
cp.sum(-L, cp.prod(L, y[i2][j2][i1][j1][k])))); // constraint5
}
}
}
}
for (int j1 = 0; j1 < MG.get(m).get(i1).getX(); j1++) {
for (int i2 = 0; i2 < job; i2++) {
for (int j2 = 1; j2 < MG.get(m).get(i2).getX(); j2++) {
for (int k = 0; k < ressource; k++) {
cp.addGe(c[i1][j1][k], cp.sum(c[i2][j2 - 1][k],
cp.prod(y[i1][j1][i2][j2][k], p[i1][j1][k])));// constraint 6 fame(-1)
}
}
}
}
}
//expressions
for (int i2 = 0; i2 < job; i2++) {
IloLinearNumExpr[][][] expr = new IloLinearNumExpr[job][MG.get(m).get(i2).getX()][ressource];
IloLinearNumExpr[][][] expr1 = new IloLinearNumExpr[job][MG.get(m).get(i2).getX()][ressource];
for (int j2 = 0; j2 < MG.get(m).get(i2).getX(); j2++) {
for (int k = 0; k < ressource; k++) {
expr[i2][j2][k] = cp.linearNumExpr();
expr1[i2][j2][k] = cp.linearNumExpr();
for (int i1 = 0; i1 < job; i1++) {
for (int j1 = 0; j1 < MG.get(m).get(i1).getX(); j1++) {
expr[i2][j2][k].addTerm(1.0, y[i1][j1][i2][j2][k]);
expr1[i2][j2][k].addTerm(1.0, y[i2][j2][i1][j1][k]);
}
}
cp.addLe(expr[i2][j2][k], 1); //Constraint3
cp.addLe(expr[i2][j2][k], expr1[i2][j2][k]); //Constaint4 there is a problem anywhere
}
}
}
//Precedence constraints
for (int i = 0; i < job; i++)
{
jobs[i] = new IntervalVarList();
IloIntervalVar prec = cp.intervalVar();
int[][] MatBinaire = MG.get(m).get(i).getMatrice();
int[][] mat = benchmrak.get(i).getMatrice();
for (int j = 0; j < MG.get(m).get(i).getX(); j++) //operation by job
{
IloIntervalVar master = cp.intervalVar();
jobs[i].add(master);
IntervalVarList members = new IntervalVarList();
for (int k = 0; k < ressource; k++)
{
if (MatBinaire[j][k] ==1)
{
int duree = mat[j][k];
IloIntervalVar member = cp.intervalVar(duree);
member.setOptional();
members.add(member);
machines[k].add(member);
}
}
cp.add(cp.alternative(master, members.toArray()));
if (j > 0)
cp.add(cp.endBeforeStart(prec, master));
prec = master;
}
ends.add(cp.endOf(prec)); //définir l'objectif de minimisation.
}
for (int j = 0; j < ressource; j++)
{
cp.add(cp.noOverlap(machines[j].toArray()));
}
}
IloObjective objective = (IloObjective) cp.minimize(cp.max(arrayFromList(ends)));
cp.add(objective);
cp.setParameter(IloCP.IntParam.FailLimit, failLimit);
if (cp.solve()) {
System.out.println("Makespan \t: " + cp.getObjValue());
for (int i = 0; i < job; i++) {
IloIntervalVar[] jobOps = jobs[i].toArray();
for (int j = 0; j < jobOps.length; j++) {
IloIntervalVar it = jobOps[j];
int m = cp.getStart(it);
int e = cp.getEnd(it);
System.out.println("Job " + i + " Operation " + j + " start at " + m + " end at " + e);
}
}
for (int i = 0; i < ressource; i++) {
IloIntervalVar[] mchOps = machines[i].toArray();
int rt = 0;
for (int j = 0; j < mchOps.length; j++) {
IloIntervalVar it = mchOps[j];
if (cp.isPresent(it)) {
rt += cp.getSize(it);
}
}
System.out.println("Machine" + i + " run time " + rt);
}
} else {
System.out.println("No solution found.");
}
} catch (IloException exc) {
exc.printStackTrace();
}
}
}
How can i take into consideration all my other constraints in this case?
I have attached my mathematical formulation to more understand me.
Help me please !
Thanxs.
#ConstraintProgramming-General#DecisionOptimization