001 package net.sf.cpsolver.studentsct.heuristics.selection; 002 003 import org.apache.log4j.Logger; 004 005 import net.sf.cpsolver.ifs.model.Neighbour; 006 import net.sf.cpsolver.ifs.solution.Solution; 007 import net.sf.cpsolver.ifs.solver.Solver; 008 import net.sf.cpsolver.ifs.util.DataProperties; 009 import net.sf.cpsolver.ifs.util.Progress; 010 import net.sf.cpsolver.studentsct.heuristics.studentord.StudentOrder; 011 import net.sf.cpsolver.studentsct.heuristics.studentord.StudentRandomOrder; 012 import net.sf.cpsolver.studentsct.model.Student; 013 014 /** 015 * Resection incomplete studends. 016 * An extension of {@link BranchBoundSelection}, where only students that are 017 * not complete ({@link Student#isComplete()} is false) and that are sectioned 018 * somewhere ({@link Student#nrAssignedRequests()} is greater then zero) are 019 * resectioned. 020 * 021 * <br><br> 022 * 023 * @version 024 * StudentSct 1.1 (Student Sectioning)<br> 025 * Copyright (C) 2007 Tomáš Müller<br> 026 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 027 * Lazenska 391, 76314 Zlin, Czech Republic<br> 028 * <br> 029 * This library is free software; you can redistribute it and/or 030 * modify it under the terms of the GNU Lesser General Public 031 * License as published by the Free Software Foundation; either 032 * version 2.1 of the License, or (at your option) any later version. 033 * <br><br> 034 * This library is distributed in the hope that it will be useful, 035 * but WITHOUT ANY WARRANTY; without even the implied warranty of 036 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 037 * Lesser General Public License for more details. 038 * <br><br> 039 * You should have received a copy of the GNU Lesser General Public 040 * License along with this library; if not, write to the Free Software 041 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 042 */ 043 044 public class ResectionIncompleteStudentsSelection extends BranchBoundSelection { 045 private static Logger sLog = Logger.getLogger(ResectionIncompleteStudentsSelection.class); 046 047 public ResectionIncompleteStudentsSelection(DataProperties properties) { 048 super(properties); 049 iOrder = new StudentRandomOrder(properties); 050 if (properties.getProperty("Neighbour.ResectionIncompleteStudentsOrder")!=null) { 051 try { 052 iOrder = (StudentOrder)Class.forName(properties.getProperty("Neighbour.ResectionIncompleteStudentsOrder")). 053 getConstructor(new Class[] {DataProperties.class}). 054 newInstance(new Object[] {properties}); 055 } catch (Exception e) { 056 sLog.error("Unable to set student order, reason:"+e.getMessage(),e); 057 } 058 } 059 } 060 061 public void init(Solver solver) { 062 init(solver, "Resection incomplete students..."); 063 } 064 065 066 /** 067 * Select neighbour. All students with an incomplete and non-empty schedule are taken, 068 * one by one in a random order. For each student a branch & bound search is employed. 069 */ 070 public Neighbour selectNeighbour(Solution solution) { 071 while (iStudentsEnumeration.hasMoreElements()) { 072 Student student = (Student)iStudentsEnumeration.nextElement(); 073 Progress.getInstance(solution.getModel()).incProgress(); 074 if (student.nrAssignedRequests()==0 || student.isComplete()) continue; 075 Neighbour neighbour = getSelection(student).select(); 076 if (neighbour!=null) return neighbour; 077 } 078 return null; 079 } 080 081 }