@Override public boolean init() { boolean init = super.init(); ObjectiveManager<IntVar, Integer> om = mSolver.getObjectiveManager(); this.objectiveManager = om; if (objectiveManager.getPolicy() == ResolutionPolicy.SATISFACTION) { throw new UnsupportedOperationException("HBFS is not adapted to satisfaction problems."); } isMinimization = objectiveManager.getPolicy() == ResolutionPolicy.MINIMIZE; return init; }
/** * Extract the open right branches from the current path until it reaches the i^th decision of * _unkopen * * @param searchLoop the search loop * @param i the index of the decision, in _unkopen, that stops the loop */ private void extractOB(SearchLoop searchLoop, int i) { Decision stopAt = _unkopen.get(i).getPrevious(); // then, goes up in the search tree, and detect open nodes searchLoop.mSolver.getEnvironment().worldPop(); Decision decision = searchLoop.decision; int bound; while (decision != stopAt) { bound = isMinimization ? objectiveManager.getObjective().getLB() : objectiveManager.getObjective().getUB(); if (decision.hasNext() && isValid(bound)) { opens.add(new Open(decision, bound, isMinimization)); } searchLoop.decision = searchLoop.decision.getPrevious(); decision.free(); decision = searchLoop.decision; searchLoop.mSolver.getEnvironment().worldPop(); } }
/** * If the bound of an O.R.B exceed the best known so far, it returns false. * * @param bound the current bound of an O.R.B. * @return true if bound is valid wrt the best known so far. */ private boolean isValid(int bound) { return isMinimization ? bound < objectiveManager.getBestUB() : bound > objectiveManager.getBestLB(); }