001 package net.sf.cpsolver.studentsct.heuristics;
002
003 import java.util.ArrayList;
004 import java.util.Iterator;
005
006 import net.sf.cpsolver.ifs.heuristics.BacktrackNeighbourSelection;
007 import net.sf.cpsolver.ifs.util.DataProperties;
008 import net.sf.cpsolver.studentsct.model.CourseRequest;
009 import net.sf.cpsolver.studentsct.model.Enrollment;
010 import net.sf.cpsolver.studentsct.model.Request;
011
012 /**
013 * Randomized backtracking-based neighbour selection. This class extends
014 * {@link RandomizedBacktrackNeighbourSelection}, however, only a randomly
015 * selected subset of enrollments of each request is considered (
016 * {@link CourseRequest#computeRandomEnrollments(int)} with the given limit is
017 * used).
018 *
019 * <br>
020 * <br>
021 * Parameters: <br>
022 * <table border='1'>
023 * <tr>
024 * <th>Parameter</th>
025 * <th>Type</th>
026 * <th>Comment</th>
027 * </tr>
028 * <tr>
029 * <td>Neighbour.MaxValues</td>
030 * <td>{@link Integer}</td>
031 * <td>Limit on the number of enrollments to be visited of each
032 * {@link CourseRequest}.</td>
033 * </tr>
034 * </table>
035 * <br>
036 * <br>
037 *
038 * @version StudentSct 1.2 (Student Sectioning)<br>
039 * Copyright (C) 2007 - 2010 Tomas Muller<br>
040 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
041 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
042 * <br>
043 * This library is free software; you can redistribute it and/or modify
044 * it under the terms of the GNU Lesser General Public License as
045 * published by the Free Software Foundation; either version 3 of the
046 * License, or (at your option) any later version. <br>
047 * <br>
048 * This library is distributed in the hope that it will be useful, but
049 * WITHOUT ANY WARRANTY; without even the implied warranty of
050 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
051 * Lesser General Public License for more details. <br>
052 * <br>
053 * You should have received a copy of the GNU Lesser General Public
054 * License along with this library; if not see
055 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
056 */
057 public class RandomizedBacktrackNeighbourSelection extends BacktrackNeighbourSelection<Request, Enrollment> {
058 private int iMaxValues = 100;
059
060 /**
061 * Constructor
062 *
063 * @param properties
064 * configuration
065 * @throws Exception
066 */
067 public RandomizedBacktrackNeighbourSelection(DataProperties properties) throws Exception {
068 super(properties);
069 iMaxValues = properties.getPropertyInt("Neighbour.MaxValues", iMaxValues);
070 }
071
072 /**
073 * List of values of a variable.
074 * {@link CourseRequest#computeRandomEnrollments(int)} with the provided
075 * limit is used for a {@link CourseRequest}.
076 */
077 @Override
078 protected Iterator<Enrollment> values(Request variable) {
079 if (iMaxValues > 0 && variable instanceof CourseRequest) {
080 return new ArrayList<Enrollment>(((CourseRequest) variable).computeRandomEnrollments(iMaxValues))
081 .iterator();
082 }
083 return variable.values().iterator();
084 }
085 }