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 * @author Tomáš Müller 044 * @version IFS 1.3 (Iterative Forward Search)<br> 045 * Copyright (C) 2006 - 2014 Tomáš Müller<br> 046 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 047 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 048 * <br> 049 * This library is free software; you can redistribute it and/or modify 050 * it under the terms of the GNU Lesser General Public License as 051 * published by the Free Software Foundation; either version 3 of the 052 * License, or (at your option) any later version. <br> 053 * <br> 054 * This library is distributed in the hope that it will be useful, but 055 * WITHOUT ANY WARRANTY; without even the implied warranty of 056 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 057 * Lesser General Public License for more details. <br> 058 * <br> 059 * You should have received a copy of the GNU Lesser General Public 060 * License along with this library; if not see <a href='http://www.gnu.org/licenses'>http://www.gnu.org/licenses</a>. 061 * 062 * @param <V> Variable 063 * @param <T> Value 064 **/ 065public interface VariableSelection<V extends Variable<V, T>, T extends Value<V, T>> { 066 /** Initialization 067 * @param solver current solver 068 **/ 069 public void init(Solver<V, T> solver); 070 071 /** 072 * Variable selection 073 * 074 * @param solution 075 * current solution 076 * @return selected variable 077 */ 078 public V selectVariable(Solution<V, T> solution); 079}