package samples; import dischoco.Protocols; import kernel.AbstractMaster; import kernel.order.LexicographicAO; import kernel.vars.integer.IntVar; import simple.SimpleAgent; import simulation.DisCPSolver; import simulation.DisProblem; import simulation.DisSolverSimulator; import util.Commands; public class Demo { public static void main(String[] args) { // The GNU GPL copyright notice System.err.println(Commands.copyrightNotice); AbstractMaster master = Protocols.getMaster(Protocols.AFCtree); DisProblem disCSP = new DisProblem("Hello DisChoco", master); SimpleAgent[] agents = new SimpleAgent[3]; IntVar[] variables = new IntVar[3]; // Make agents agents[0] = (SimpleAgent) disCSP.makeAgent("A1", ""); agents[1] = (SimpleAgent) disCSP.makeAgent("A2", ""); agents[2] = (SimpleAgent) disCSP.makeAgent("A3", ""); // Make one single variable for each agent variables[0] = agents[0].makeInternalVar(new Integer[] {1, 2}); // x1 variables[1] = agents[1].makeInternalVar(new Integer[] {1, 2}); // x2 variables[2] = agents[2].makeInternalVar(new Integer[] {2}); // x3 // Make two constraints, we must to create external var on each agent // But each agent must known its constraints // x1!=x2 agents[0].neqY(agents[0].makeExternalVar(variables[1])); agents[1].neqY(agents[1].makeExternalVar(variables[0])); // x2!=x3 agents[1].neqY(agents[1].makeExternalVar(variables[2])); agents[2].neqY(agents[2].makeExternalVar(variables[1])); // Make a simulator to resolve the problem DisCPSolver solver = new DisSolverSimulator(disCSP); solver.setCentralizedAO(new LexicographicAO()); solver.addNCCCMetric(); solver.addCommunicationMetric(); solver.solve(); System.out.println("Problem : " + disCSP.getProblemName()); System.out.println("Solution of the problem using " + disCSP.master.getClass()); System.out.println("-----------------------------------------------------------------------------------"); System.out.println(solver.getGlobalSolution()); System.out.println("-----------------------------------------------------------------------------------"); System.out.println("Statistics :"); System.out.println(solver.getStatistics()); } }