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