001package org.cpsolver.ifs.perturbations;
002
003import java.util.Collection;
004import java.util.Map;
005
006import org.cpsolver.ifs.assignment.Assignment;
007import org.cpsolver.ifs.model.Model;
008import org.cpsolver.ifs.model.Value;
009import org.cpsolver.ifs.model.Variable;
010import org.cpsolver.ifs.solution.Solution;
011import org.cpsolver.ifs.solver.Solver;
012
013
014/**
015 * Counter of perturbation penalty (minimal perturbation problem). <br>
016 * <br>
017 * Many real-life problems are dynamic, with changes in the problem definition
018 * occurring after a solution to the initial formulation has been reached. A
019 * minimal perturbation problem incorporates these changes, along with the
020 * initial solution, as a new problem whose solution must be as close as
021 * possible to the initial solution. The iterative forward search algorithm is
022 * also made to solve minimal perturbation problems. <br>
023 * <br>
024 * To define the minimal perturbation problem, we will consider an initial
025 * (original) problem, its solution, a new problem, and some distance function
026 * which allows us to compare solutions of the initial and the new problem.
027 * Subsequently we look for a solution of the new problem with minimal distance
028 * from the initial solution. This distance is expressed by this
029 * PerturbationCounter
030 * 
031 * @see Solver
032 * @see Solution
033 * @see Variable
034 * 
035 * @author  Tomáš Müller
036 * @version IFS 1.3 (Iterative Forward Search)<br>
037 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
038 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
039 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
040 * <br>
041 *          This library is free software; you can redistribute it and/or modify
042 *          it under the terms of the GNU Lesser General Public License as
043 *          published by the Free Software Foundation; either version 3 of the
044 *          License, or (at your option) any later version. <br>
045 * <br>
046 *          This library is distributed in the hope that it will be useful, but
047 *          WITHOUT ANY WARRANTY; without even the implied warranty of
048 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
049 *          Lesser General Public License for more details. <br>
050 * <br>
051 *          You should have received a copy of the GNU Lesser General Public
052 *          License along with this library; if not see
053 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
054 *
055 * @param <V> Variable
056 * @param <T> Value
057 */
058public interface PerturbationsCounter<V extends Variable<V, T>, T extends Value<V, T>> {
059    /** Initialization 
060     * @param solver current solver
061     **/
062    public void init(Solver<V, T> solver);
063
064    /**
065     * Returns perturbation penalty, i.e., the distance between current solution
066     * and the solution of the initial problem (see
067     * {@link Variable#getInitialAssignment()}).
068     * 
069     * @param assignment current assignment
070     * @param model
071     *            current model
072     * @return penalty 
073     */
074    public double getPerturbationPenalty(Assignment<V, T> assignment, Model<V, T> model);
075
076    /**
077     * Returns perturbation penalty, i.e., the distance between current solution
078     * and the solution of the initial (only include variables from the given
079     * set) problem (see {@link Variable#getInitialAssignment()}).
080     * 
081     * @param assignment current assignment
082     * @param model
083     *            current model
084     * @param variables sub-problem
085     * @return penalty
086     */
087    public double getPerturbationPenalty(Assignment<V, T> assignment, Model<V, T> model, Collection<V> variables);
088
089    /**
090     * Returns perturbation penalty of the solution which become from the
091     * current solution when given conflicting values are unassigned and the
092     * selected value is assigned. Since this penalty is used for comparison of
093     * different candidate values in the value selection criterion, it is fully
094     * acceptable to just return a difference between current and the altered
095     * solution (which might be easied for computation that the whole
096     * perturbation penalty).
097     * 
098     * @param assignment current assignment
099     * @param model
100     *            current model
101     * @param selectedValue
102     *            value to be selected in the next iteration
103     * @param conflicts
104     *            conflicting values to be unassigned in the next iteration
105     * @return penalty
106     */
107    public double getPerturbationPenalty(Assignment<V, T> assignment, Model<V, T> model, T selectedValue, Collection<T> conflicts);
108
109    /**
110     * Some (perturbation) information about the solution might be returned
111     * here.
112     * 
113     * @param assignment current assignment
114     * @param info
115     *            resultant info table
116     * @param model
117     *            current model
118     */
119    public void getInfo(Assignment<V, T> assignment, Model<V, T> model, Map<String, String> info);
120
121    /**
122     * Some (perturbation) information about the solution might be returned here
123     * (only include variables from the given set).
124     * 
125     * @param assignment current assignment
126     * @param info
127     *            resultant info table
128     * @param model
129     *            current model
130     * @param variables sub-problem
131     */
132    public void getInfo(Assignment<V, T> assignment, Model<V, T> model, Map<String, String> info, Collection<V> variables);
133}