/* * Copyright 2002, 2003, 2004, 2005 - Koalog */ package com.koalog.jcs.examples; import org.apache.log4j.Category; import org.apache.log4j.PropertyConfigurator; import com.koalog.jcs.constraint.BaseProblem; import com.koalog.jcs.constraint.arithmetic.LeqShift; import com.koalog.jcs.scheduler.Task; import com.koalog.jcs.scheduler.Disjunctive; import com.koalog.jcs.variable.BooleanVariable; import com.koalog.jcs.variable.IntegerVariable; /** * A model for the job-shop problem. * * @author Yan Georget */ public class JobShopProblem extends BaseProblem { //------------------------------------------------------------------------ // PROPERTIES //------------------------------------------------------------------------ /** The number of jobs. */ int n; /** The number of machines. */ int m; /** * The problem data: one line for each job, * listing the machine number and processing time for each step of the job * (the machines are numbered starting with 0). */ int[][] data; /** An upper bound for the problem. */ int ub; /** The makespan. */ IntegerVariable makespan; /** * The tasks per machine then per job. */ Task[][] task; /** * The order variables: * for m and i < j, order[m][k] <=> task[m][i] < task[m][j], * where k is an integer depending on i and j. */ BooleanVariable[][] order; //------------------------------------------------------------------------ // CONSTRUCTORS //------------------------------------------------------------------------ /** * Main constructor. * @param data a matrix of integers */ public JobShopProblem(int[][] data) { this(data, makespanUB(data)); } /** * Auxilliary constructor. * @param data a matrix of integers * @param ub an upper bound */ public JobShopProblem(int[][] data, int ub) { super(); this.ub = ub; this.data = data; n = data.length; // number of jobs m = data[0].length/2; // number of machines task = new Task[m][n]; // variables will contain the tasks and the makespan variables = new IntegerVariable[m*n+1]; variables[m*n] = makespan = new IntegerVariable("makespan", 0, ub); for (int j=0; j0) { // precedence constraints int i0 = getMachine(data, j, k-1); add(new LeqShift(task[i0][j], task[i][j], -task[i0][j].getDuration())); if (k == m-1) { add(new LeqShift(task[i][j], makespan, -task[i][j].getDuration())); } } } } order = new BooleanVariable[m][n*(n-1)/2]; for (int i=0; i