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