    001package org.cpsolver.ifs.heuristics;
    002
    003import org.cpsolver.ifs.model.Value;
    004import org.cpsolver.ifs.model.Variable;
    005import org.cpsolver.ifs.solution.Solution;
    006import org.cpsolver.ifs.solver.Solver;
    007
    008/**
    009 * Variable selection criterion. <br>
    010 * <br>
    011 * The IFS algorithm requires a function that selects a variable to be
    012 * (re)assigned during the current iteration step. This problem is equivalent to
    013 * a variable selection criterion in constraint programming. There are several
    014 * guidelines for selecting a variable. In local search, the variable
    015 * participating in the largest number of violations is usually selected first.
    016 * In backtracking-based algorithms, the first-fail principle is often used,
    017 * i.e., a variable whose instantiation is most complicated is selected first.
    018 * This could be the variable involved in the largest set of constraints or the
    019 * variable with the smallest domain, etc. <br>
    020 * <br>
    021 * We can split the variable selection criterion into two cases. If some
    022 * variables remain unassigned, the "worst" variable among them is selected,
    023 * i.e., first-fail principle is applied. This may, for example, be the variable
    024 * with the smallest domain or with the highest number of hard and/or soft
    025 * constraints. <br>
    026 * <br>
    027 * The second case occurs when all variables are assigned. Because the algorithm
    028 * does not need to stop when a complete feasible solution is found, the
    029 * variable selection criterion for such case has to be considered as well. Here
    030 * all variables are assigned but the solution is not good enough, e.g., in the
    031 * sense of violated soft constraints. We choose a variable whose change of a
    032 * value can introduce the best improvement of the solution. It may, for
    033 * example, be a variable whose value violates the highest number of soft
    034 * constraints. <br>
    035 * <br>
    036 * It is possible for the solution to become incomplete again after such an
    037 * iteration because a value which is not consistent with all hard constraints
    038 * can be selected in the value selection criterion. This can also be taken into
    039 * account in the variable selection heuristics.
    040 *
    041 * @see Solver
    042 *
    043 * @version IFS 1.3 (Iterative Forward Search)<br>
    044 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    045 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    046 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    047 * <br>
    048 *          This library is free software; you can redistribute it and/or modify
    049 *          it under the terms of the GNU Lesser General Public License as
    050 *          published by the Free Software Foundation; either version 3 of the
    051 *          License, or (at your option) any later version. <br>
    052 * <br>
    053 *          This library is distributed in the hope that it will be useful, but
    054 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    055 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    056 *          Lesser General Public License for more details. <br>
    057 * <br>
    058 *          You should have received a copy of the GNU Lesser General Public
    059 *          License along with this library; if not see <a href='http://www.gnu.org/licenses'>http://www.gnu.org/licenses</a>.
    060 *
    061 * @param <V> Variable
    062 * @param <T> Value
    063 **/
    064public interface VariableSelection<V extends Variable<V, T>, T extends Value<V, T>> {
    065    /** Initialization
    066     * @param solver current solver
    067     **/
    068    public void init(Solver<V, T> solver);
    069
    070    /**
    071     * Variable selection
    072     *
    073     * @param solution
    074     *            current solution
    075     * @return selected variable
    076     */
    077    public V selectVariable(Solution<V, T> solution);
    078}