/*
* Copyright 2002, 2003, 2004, 2005 - Koalog
*/
package com.koalog.jcs.examples;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Category;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;
import com.koalog.jcs.variable.BooleanVariable;
import com.koalog.jcs.variable.IntegerVariable;
import com.koalog.jcs.constraint.BaseProblem;
import com.koalog.jcs.constraint.arithmetic.Atmost;
import com.koalog.jcs.constraint.arithmetic.Atleast;
import com.koalog.jcs.constraint.arithmetic.Exactly_SPARSE;
import com.koalog.jcs.constraint.arithmetic.Element;
import com.koalog.jcs.domain.SparseDomain;
/**
* The cars sequencing problem (problem prob001 in CSPLIB).
*
*
Cars have to be scheduled on a production line.
* The cars differ by their options
* (the set of options of a car defines its type/class).
* Options are installed by stations:
* for each block of b consecutive cars,
* each station can handle at most s cars
* (s and b depend on the option/station).
*
*
The problem has been shown to be NP-complete (Gent 1999).
*
* @author Yan Georget
*/
public class CarsSequencingProblem extends BaseProblem {
//------------------------------------------------------------------------
// PROPERTIES
//------------------------------------------------------------------------
/**
* The problem data:
*
* - First line: number of cars; number of options; number of types.
*
- Second line: for each option,
* the maximum number of cars (s) with that option in a block.
*
- Third line: for each option,
* the block size (b) to which the maximum number refers;
* then for each type: index; number of cars in this type;
* for each option, whether or not this type requires it (1 or 0).
*
*/
int[][] data;
/** A map mapping a variable to an array of costs. */
Map costs;
//------------------------------------------------------------------------
// CONSTRUCTOR
//------------------------------------------------------------------------
/**
* Sole constructor.
* @param data the problem data
*/
public CarsSequencingProblem(int[][] data) {
super();
this.data = data;
int carsNb = data[0][0];
int optionsNb = data[0][1];
int typesNb = data[0][2];
IntegerVariable[] type = new IntegerVariable[carsNb];
for (int i=0; i 0) {
int length = carsNb-b*t;
BooleanVariable[] pf = new BooleanVariable[length];
System.arraycopy(o[j], 0, pf, 0, length);
add(new Atleast(using[j]-s*t, pf, 1));
// useless with the variable heuristic chosen
// BooleanVariable[] pl = new BooleanVariable[length];
// System.arraycopy(o[j], carsNb-length, pl, 0, length);
// internalAdd(new Atleast(using[j]-s*t, pl, 1));
}
}
}
setVariables(type);
// an array of pairs (option index, option utilization)
// as an array of arrays
int[][] optionUtilization = new int[optionsNb][2];
for (int j=0; j