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