001package org.cpsolver.coursett.criteria; 002 003import org.cpsolver.coursett.heuristics.PlacementSelection; 004import org.cpsolver.coursett.model.Lecture; 005import org.cpsolver.coursett.model.Placement; 006import org.cpsolver.ifs.criteria.AbstractCriterion; 007import org.cpsolver.ifs.util.DataProperties; 008 009/** 010 * Abstract class for all timetabling criteria. On top of the {@link AbstractCriterion}, it provides 011 * weights for the {@link PlacementSelection} heuristics. 012 * <br> 013 * 014 * @author Tomáš Müller 015 * @version CourseTT 1.3 (University Course Timetabling)<br> 016 * Copyright (C) 2006 - 2014 Tomáš Müller<br> 017 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 018 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 019 * <br> 020 * This library is free software; you can redistribute it and/or modify 021 * it under the terms of the GNU Lesser General Public License as 022 * published by the Free Software Foundation; either version 3 of the 023 * License, or (at your option) any later version. <br> 024 * <br> 025 * This library is distributed in the hope that it will be useful, but 026 * WITHOUT ANY WARRANTY; without even the implied warranty of 027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 028 * Lesser General Public License for more details. <br> 029 * <br> 030 * You should have received a copy of the GNU Lesser General Public 031 * License along with this library; if not see 032 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 033 */ 034public abstract class TimetablingCriterion extends AbstractCriterion<Lecture, Placement> { 035 private double[] iPlacementSelectionWeight = null; 036 private Double[][] iPlacementSelectionAdjusts = null; 037 038 @Override 039 public void configure(DataProperties properties) { 040 super.configure(properties); 041 if (getPlacementSelectionWeightName() != null) { 042 iPlacementSelectionWeight = new double[] { 0.0, 0.0, 0.0 }; 043 for (int i = 0; i < 3; i++) 044 iPlacementSelectionWeight[i] = properties.getPropertyDouble(getPlacementSelectionWeightName() + (1 + i), getPlacementSelectionWeightDefault(i)); 045 iPlacementSelectionAdjusts = new Double[][] { null, null, null}; 046 for (int i = 0; i < 3; i++) { 047 iPlacementSelectionAdjusts[i] = properties.getPropertyDoubleArry(getPlacementSelectionAdjustmentsName() + (1 + i), properties.getPropertyDoubleArry(getPlacementSelectionAdjustmentsName(), null)); 048 } 049 } 050 } 051 052 public String getPlacementSelectionWeightName() { 053 return "Placement." + getClass().getName().substring(1 + getClass().getName().lastIndexOf('.')) + "Weight"; 054 } 055 056 public String getPlacementSelectionAdjustmentsName() { 057 return getPlacementSelectionWeightName() + "Adjustments"; 058 } 059 060 public double getPlacementSelectionWeight(int level, int idx) { 061 double w = (iPlacementSelectionWeight == null ? 0.0 : iPlacementSelectionWeight[level]); 062 if (idx < 0 || iPlacementSelectionAdjusts == null || iPlacementSelectionAdjusts[level] == null || idx >= iPlacementSelectionAdjusts[level].length || iPlacementSelectionAdjusts[level][idx] == null) return w; 063 return w * iPlacementSelectionAdjusts[level][idx]; 064 } 065 066 public double getPlacementSelectionWeightDefault(int level) { 067 return (level <= 1 ? getWeight() : 0.0); 068 } 069}