    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 * @version IFS 1.3 (Iterative Forward Search)<br>
    036 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    037 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    038 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    039 * <br>
    040 *          This library is free software; you can redistribute it and/or modify
    041 *          it under the terms of the GNU Lesser General Public License as
    042 *          published by the Free Software Foundation; either version 3 of the
    043 *          License, or (at your option) any later version. <br>
    044 * <br>
    045 *          This library is distributed in the hope that it will be useful, but
    046 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    047 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    048 *          Lesser General Public License for more details. <br>
    049 * <br>
    050 *          You should have received a copy of the GNU Lesser General Public
    051 *          License along with this library; if not see
    052 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    053 *
    054 * @param <V> Variable
    055 * @param <T> Value
    056 */
    057public interface PerturbationsCounter<V extends Variable<V, T>, T extends Value<V, T>> {
    058    /** Initialization
    059     * @param solver current solver
    060     **/
    061    public void init(Solver<V, T> solver);
    062
    063    /**
    064     * Returns perturbation penalty, i.e., the distance between current solution
    065     * and the solution of the initial problem (see
    066     * {@link Variable#getInitialAssignment()}).
    067     *
    068     * @param assignment current assignment
    069     * @param model
    070     *            current model
    071     * @return penalty
    072     */
    073    public double getPerturbationPenalty(Assignment<V, T> assignment, Model<V, T> model);
    074
    075    /**
    076     * Returns perturbation penalty, i.e., the distance between current solution
    077     * and the solution of the initial (only include variables from the given
    078     * set) problem (see {@link Variable#getInitialAssignment()}).
    079     *
    080     * @param assignment current assignment
    081     * @param model
    082     *            current model
    083     * @param variables sub-problem
    084     * @return penalty
    085     */
    086    public double getPerturbationPenalty(Assignment<V, T> assignment, Model<V, T> model, Collection<V> variables);
    087
    088    /**
    089     * Returns perturbation penalty of the solution which become from the
    090     * current solution when given conflicting values are unassigned and the
    091     * selected value is assigned. Since this penalty is used for comparison of
    092     * different candidate values in the value selection criterion, it is fully
    093     * acceptable to just return a difference between current and the altered
    094     * solution (which might be easied for computation that the whole
    095     * perturbation penalty).
    096     *
    097     * @param assignment current assignment
    098     * @param model
    099     *            current model
    100     * @param selectedValue
    101     *            value to be selected in the next iteration
    102     * @param conflicts
    103     *            conflicting values to be unassigned in the next iteration
    104     * @return penalty
    105     */
    106    public double getPerturbationPenalty(Assignment<V, T> assignment, Model<V, T> model, T selectedValue, Collection<T> conflicts);
    107
    108    /**
    109     * Some (perturbation) information about the solution might be returned
    110     * here.
    111     *
    112     * @param assignment current assignment
    113     * @param info
    114     *            resultant info table
    115     * @param model
    116     *            current model
    117     */
    118    public void getInfo(Assignment<V, T> assignment, Model<V, T> model, Map<String, String> info);
    119
    120    /**
    121     * Some (perturbation) information about the solution might be returned here
    122     * (only include variables from the given set).
    123     *
    124     * @param assignment current assignment
    125     * @param info
    126     *            resultant info table
    127     * @param model
    128     *            current model
    129     * @param variables sub-problem
    130     */
    131    public void getInfo(Assignment<V, T> assignment, Model<V, T> model, Map<String, String> info, Collection<V> variables);
    132}