import java.io.*; import java.util.*; import java.util.Arrays; import java.util.Collections; import org.chocosolver.solver.*; import org.chocosolver.solver.variables.*; import org.chocosolver.solver.constraints.*; import org.chocosolver.solver.search.strategy.*; public class BinPack { private int[] data; // the data to be packed private Solver solver; // a solver object, to attach variables and constraints private IntVar inBin[][]; // inBin[i][j] = 1 iff jth number is in ith bin private IntVar inBinT[][]; // transpose of inBin[i][j], used for summing columns! private IntVar load[]; // load[i] is sum of the numbers in ith bin private IntVar binUsed[]; // binUsed[i] = 1 iff load[i] > 0 private IntVar totBinsUsed; // total number of bins used private int c; // the capacity of each bin private int n; // number of items to pack private int m; // number of bins you have private String id; // an identification for the problem public BinPack(String fname,int numberOfItems,int numberOfBins,int capacity) throws Exception { n = numberOfItems; m = numberOfBins; c = capacity; id = fname; data = new int[n]; solver = new Solver(id); inBin = VF.enumeratedMatrix("inBin",m,n,0,1,solver); inBinT = new IntVar[n][m]; load = VF.enumeratedArray("load",m,0,c,solver); binUsed = VF.enumeratedArray("binUsed",m,0,1,solver); totBinsUsed = VF.enumerated("totBinsUsed",0,m,solver); for (int i=0;i",0); Constraint c2 = ICF.arithm(binUsed[i],"=",1); LCF.ifThen(c1,c2); LCF.ifThen(c2,c1); } // // constrain binUsed[i] to be 1 if and only if there are some // items stacked in the ith bin, i.e. load[i] > 0 // IntVar ONE = VF.fixed("one",1,solver); for (int i=0;i=",load[i+1])); // // symmetry breaking consistent with first fit decreasing // heaviest bins are low index // // EDIT //for (int i=0;i