/** * The factory method: builds the solver needed to solve the problem (an optimization solver if a * variable should be minimized or maximized, a classical solver (mac-dbt) for constraint * problems, or a path-repair or decision-repair solver if explanations should be kept. */ public void generateSearchSolver() { if (null == objective) { // MAC-DBT strategy = new PalmGlobalSearchStrategy(this); } else // MAC-DBT + Dynamic Cuts if (objective instanceof IntDomainVar) strategy = new PalmBranchAndBound(this, (IntDomainVar) objective, doMaximize); else if (objective instanceof RealVar) strategy = new PalmRealBranchAndBound(this, (RealVar) objective, doMaximize); if (prSize >= 0) { // Decision repair if (repair == null) repair = new PalmUnsureRepair(); NogoodSConstraint ng = new NogoodSConstraint(intVars.toArray()); post(ng); if (learn == null) { learn = new PathRepairLearn(prSize, ng); } else { ((PathRepairLearn) learn).setMemory(ng); } } // Classical solver tools if (state == null) state = new PalmState((PalmExplanation) makeExplanation()); if (repair == null) repair = new PalmRepair(); if (learn == null) learn = new PalmLearn(); if (extend == null) extend = new PalmExtend(); // Classical limits strategy.limits.add(new PalmTimeLimit(strategy, timeLimit)); strategy.limits.add(new NodeLimit(strategy, nodeLimit)); // TODO : limits.add(new relaxLimit()); // Solver should stop at first solution ? TODO : see if useful ! strategy.stopAtFirstSol = firstSolution; // Attach solver tools ((PalmGlobalSearchStrategy) strategy).attachPalmState(state); ((PalmGlobalSearchStrategy) strategy).attachPalmExtend(extend); ((PalmGlobalSearchStrategy) strategy).attachPalmLearn(learn); ((PalmGlobalSearchStrategy) strategy).attachPalmRepair(repair); // Attach branchings (with a default one if needed if (branchings.size() == 0) { if (varIntSelector == null) varIntSelector = new MinDomain(this); if (valIntIterator == null && valIntSelector == null) valIntIterator = new IncreasingDomain(); if (prSize < 0) if (valIntIterator != null) branchings.add(new PalmAssignVar(varIntSelector, valIntIterator)); else branchings.add(new PalmAssignVar(varIntSelector, valIntSelector)); else if (valIntIterator != null) branchings.add(new PathRepairAssignVar(varIntSelector, valIntIterator)); else System.err.println("Path repair cannot use valSelector"); } ((PalmGlobalSearchStrategy) strategy).attachPalmBranchings(branchings); }
/** * Posts and propagates several decision constraints (that is decisions taken by the solver). * * @param constraints The constraints to post. * @throws ContradictionException */ public void propagateAllDecisionsConstraints(List constraints) throws ContradictionException { // this.palmSolver.incRuntimeStatistic(EXT, 1); move in explore for (Iterator iterator = constraints.iterator(); iterator.hasNext(); ) { AbstractSConstraint constraint = (AbstractSConstraint) iterator.next(); this.post( constraint, 0); // Avant la mise a jour de l'etat sinon la contrainte n'existe pas encore !! ((PalmGlobalSearchStrategy) strategy).getState().addDecision(constraint); this.propagate(); } }
/** * Tries to repair the problem after a PalmContradiction thanks to removing a responsible * constraint (that is a constraint in the explain of the contradiction). * * @throws ContradictionException */ public void repair() throws ContradictionException { ((PalmGlobalSearchStrategy) strategy).repair(); }