001 package net.sf.cpsolver.studentsct.heuristics; 002 003 import java.util.Enumeration; 004 005 import net.sf.cpsolver.ifs.heuristics.BacktrackNeighbourSelection; 006 import net.sf.cpsolver.ifs.model.Variable; 007 import net.sf.cpsolver.ifs.util.DataProperties; 008 import net.sf.cpsolver.studentsct.model.CourseRequest; 009 010 /** 011 * Randomized backtracking-based neighbour selection. 012 * This class extends {@link RandomizedBacktrackNeighbourSelection}, however, 013 * only a randomly selected subset of enrollments of each request is considered 014 * ({@link CourseRequest#computeRandomEnrollments(int)} with the given limit is used). 015 * 016 * <br><br> 017 * Parameters: 018 * <br> 019 * <table border='1'><tr><th>Parameter</th><th>Type</th><th>Comment</th></tr> 020 * <tr><td>Neighbour.MaxValues</td><td>{@link Integer}</td><td>Limit on the number of enrollments to be visited of each {@link CourseRequest}.</td></tr> 021 * </table> 022 * <br><br> 023 * 024 * @version 025 * StudentSct 1.1 (Student Sectioning)<br> 026 * Copyright (C) 2007 Tomáš Müller<br> 027 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 028 * Lazenska 391, 76314 Zlin, Czech Republic<br> 029 * <br> 030 * This library is free software; you can redistribute it and/or 031 * modify it under the terms of the GNU Lesser General Public 032 * License as published by the Free Software Foundation; either 033 * version 2.1 of the License, or (at your option) any later version. 034 * <br><br> 035 * This library is distributed in the hope that it will be useful, 036 * but WITHOUT ANY WARRANTY; without even the implied warranty of 037 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 038 * Lesser General Public License for more details. 039 * <br><br> 040 * You should have received a copy of the GNU Lesser General Public 041 * License along with this library; if not, write to the Free Software 042 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 043 */ 044 public class RandomizedBacktrackNeighbourSelection extends BacktrackNeighbourSelection { 045 private int iMaxValues = 100; 046 047 /** 048 * Constructor 049 * @param properties configuration 050 * @throws Exception 051 */ 052 public RandomizedBacktrackNeighbourSelection(DataProperties properties) throws Exception { 053 super(properties); 054 iMaxValues = properties.getPropertyInt("Neighbour.MaxValues", iMaxValues); 055 } 056 057 /** 058 * List of values of a variable. 059 * {@link CourseRequest#computeRandomEnrollments(int)} with the provided limit is used 060 * for a {@link CourseRequest}. 061 */ 062 protected Enumeration values(Variable variable) { 063 if (iMaxValues>0 && variable instanceof CourseRequest) { 064 return ((CourseRequest)variable).computeRandomEnrollments(iMaxValues).elements(); 065 } 066 return variable.values().elements(); 067 } 068 }