import java.io.*; import java.util.*; import java.util.Arrays; import org.chocosolver.util.tools.ArrayUtils; import org.chocosolver.solver.Model; import org.chocosolver.solver.Solver; import org.chocosolver.solver.variables.IntVar; import org.chocosolver.solver.constraints.IIntConstraintFactory.*; //import org.chocosolver.solver.constraints.Constraint; import org.chocosolver.solver.search.strategy.Search; public class Allocate { Person person[]; // the employees to be allocated to cost centres int salary[]; // salary[i] of ith person Model model; // the model Solver solver; // the solver object IntVar inCentre[][]; // inCentre[i][j] = 1 iff jth person works in ith cost centre IntVar centreSalary[]; // centreSalaries[i] is sum of the salaries in the ith cost centre int budget; // the budget for each cost centre int n; // number of employees int m; // number of cost centres String id; // an identification for the problem public Allocate(String fname,int numberOfPeople,int numberOfCostCentres,int budget) throws Exception { n = numberOfPeople; m = numberOfCostCentres; this.budget = budget; id = fname; person = new Person[n]; salary = new int[n]; model = new Model(id); solver = model.getSolver(); inCentre = model.intVarMatrix("inCentre",m,n,0,1); centreSalary = model.intVarArray("centre salaries",m,0,budget); Scanner sc = new Scanner(new File(fname)); for (int i=0;i=",centreSalary[i+1]).post(); // // symmetry breaking consistent with first fit decreasing // costliest cost centres have low index // // EDIT for (int centre=0;centre= inCentre[i+1] // } // solve using value ordering over decision variables boolean solve(){ //solver.setSearch(Search.minDomLBSearch(ArrayUtils.flatten(inCentre))); solver.setSearch(Search.minDomUBSearch(ArrayUtils.flatten(inCentre))); return solver.solve(); } public String toString(){ String s = id + " " + " #employees: " + n + " #centres: " + m + " budget: " + budget + "\n"; for (int i=0;i