001 package ifs.solution;
002
003 import ifs.util.DataProperties;
004
005 /**
006 * General implementation of solution comparator.
007 * <br><br>
008 * The solution is better than the best ever found solution when it has more variables assigned. In the case, when both
009 * solutions have the same number of assigned variables, the better solution is the one with smaller total value, i.e.,
010 * the sum of {@link ifs.model.Value#toInt()} over all assigned variables.
011 *
012 * @see Solution
013 * @see ifs.solver.Solver
014 *
015 * @author <a href="mailto:muller@ktiml.mff.cuni.cz">Tomáš Müller</a>
016 * @version 1.0
017 */
018 public class GeneralSolutionComparator implements SolutionComparator {
019
020 public GeneralSolutionComparator() {}
021 /** No parameters are used so far. */
022 public GeneralSolutionComparator(DataProperties properties) {
023 }
024
025 public boolean isBetterThanBestSolution(Solution currentSolution) {
026 if (currentSolution.getBestInfo()==null) return true;
027 int unassigned = currentSolution.getModel().unassignedVariables().size();
028 if (currentSolution.getModel().getBestUnassignedVariables()!=unassigned)
029 return currentSolution.getModel().getBestUnassignedVariables()>unassigned;
030 return currentSolution.getModel().getTotalValue()<currentSolution.getBestValue();
031 }
032
033 }