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