Originally posted by: Ahlem
Hi,
I'm working on the flexible job shop scheduling problem and the output of my program is the makespan using the command cp.getObjValue(). But, the display slows me down the execution.
And, this is the code :
import java.util.List;
import java.util.ArrayList;
import ilog.concert.IloException;
import ilog.concert.IloIntExpr;
import ilog.concert.IloIntervalVar;
import ilog.concert.cppimpl.IloObjective;
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 double modell(MatriceGlobal MG) throws IloException {
Information f = new Information();
MatriceGlobal benchmrak = f.getM();
int job = f.getNbjob();
int ressource = f.getNbressource();
int failLimit = 10000;
IloCP cp = new IloCP();
try {
IntervalVarList[] machines = new IntervalVarList[ressource];
for (int j = 0; j < ressource; j++)
machines[j] = new IntervalVarList();
List<IloIntExpr> ends = new ArrayList<IloIntExpr>();
IntervalVarList[] jobs = new IntervalVarList[job]; //hedhi mtaa l'affichage f solve()
//Precedence constraints
for (int i = 0; i < job; i++)
{
jobs[i] = new IntervalVarList();
IloIntervalVar prec = cp.intervalVar();
int[][] MatBinaire = MG.get(i).getMatrice();
int[][] mat = benchmrak.get(i).getMatrice();
for (int j = 0; j < MG.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());
} else {
System.out.println("No solution found.");
}
} catch (IloException exc) {
exc.printStackTrace();
}
return (cp.getObjValue());
}
}
How can i display only the value of the makespan ?
Please help me.
Best regards.
#ConstraintProgramming-General#DecisionOptimization