    001package org.cpsolver.coursett.criteria;
    002
    003import java.util.Collection;
    004import java.util.Set;
    005
    006import org.cpsolver.coursett.model.Lecture;
    007import org.cpsolver.coursett.model.Placement;
    008import org.cpsolver.ifs.assignment.Assignment;
    009import org.cpsolver.ifs.perturbations.PerturbationsCounter;
    010import org.cpsolver.ifs.solver.Solver;
    011import org.cpsolver.ifs.util.DataProperties;
    012
    013
    014/**
    015 * Perturbations. This criterion counts differences (perturbations) between initial and the current
    016 * solution. It is based on {@link PerturbationsCounter}.
    017 * <br>
    018 *
    019 * @version CourseTT 1.3 (University Course Timetabling)<br>
    020 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    021 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    022 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    023 * <br>
    024 *          This library is free software; you can redistribute it and/or modify
    025 *          it under the terms of the GNU Lesser General Public License as
    026 *          published by the Free Software Foundation; either version 3 of the
    027 *          License, or (at your option) any later version. <br>
    028 * <br>
    029 *          This library is distributed in the hope that it will be useful, but
    030 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    031 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    032 *          Lesser General Public License for more details. <br>
    033 * <br>
    034 *          You should have received a copy of the GNU Lesser General Public
    035 *          License along with this library; if not see
    036 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    037 */
    038
    039public class Perturbations extends TimetablingCriterion {
    040    private PerturbationsCounter<Lecture, Placement> iPerturbationsCounter = null;
    041
    042    public Perturbations() {
    043        setValueUpdateType(ValueUpdateType.NoUpdate);
    044    }
    045
    046    @Override
    047    public String getPlacementSelectionWeightName() {
    048        return "Placement.MPP_DeltaInitialAssignmentWeight";
    049    }
    050
    051    @Override
    052    public boolean init(Solver<Lecture, Placement> solver) {
    053        iPerturbationsCounter = solver.getPerturbationsCounter();
    054        return super.init(solver);
    055    }
    056
    057    @Override
    058    public double getWeightDefault(DataProperties config) {
    059        return config.getPropertyDouble("Comparator.PerturbationPenaltyWeight", 1.0);
    060    }
    061
    062    public PerturbationsCounter<Lecture, Placement> getPerturbationsCounter() {
    063        return iPerturbationsCounter;
    064    }
    065
    066    @Override
    067    public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
    068        return getPerturbationsCounter().getPerturbationPenalty(assignment, getModel(), value, conflicts);
    069    }
    070
    071    @Override
    072    public double getValue(Assignment<Lecture, Placement> assignment) {
    073        return getPerturbationsCounter().getPerturbationPenalty(assignment, getModel());
    074    }
    075
    076    @Override
    077    public double getValue(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    078        return getPerturbationsCounter().getPerturbationPenalty(assignment, getModel(), variables);
    079    }
    080
    081    @Override
    082    public double[] getBounds(Assignment<Lecture, Placement> assignment) {
    083        return new double[] { 0.0, 0.0 };
    084    }
    085
    086    @Override
    087    public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    088        return new double[] { 0.0, 0.0 };
    089    }
    090}