001package org.cpsolver.studentsct.constraint; 002 003import java.util.Set; 004 005import org.cpsolver.ifs.assignment.Assignment; 006import org.cpsolver.ifs.model.GlobalConstraint; 007import org.cpsolver.studentsct.model.CourseRequest; 008import org.cpsolver.studentsct.model.Enrollment; 009import org.cpsolver.studentsct.model.Request; 010 011/** 012 * Fixed assignment constraint. This global constraint checks that the 013 * conflicts that have been computed so far (by other global constraints earlier 014 * in the list) do not create a conflict with a fixed assignment. This constraint 015 * is to be used only when there are fixed course requests and it is to be last global constraint 016 * in the list. 017 * 018 * @author Tomáš Müller 019 * @version StudentSct 1.3 (Student Sectioning)<br> 020 * Copyright (C) 2007 - 2015 Tomáš Müller<br> 021 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 022 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 023 * <br> 024 * This library is free software; you can redistribute it and/or modify 025 * it under the terms of the GNU Lesser General Public License as 026 * published by the Free Software Foundation; either version 3 of the 027 * License, or (at your option) any later version. <br> 028 * <br> 029 * This library is distributed in the hope that it will be useful, but 030 * WITHOUT ANY WARRANTY; without even the implied warranty of 031 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 032 * Lesser General Public License for more details. <br> 033 * <br> 034 * You should have received a copy of the GNU Lesser General Public 035 * License along with this library; if not see 036 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 037 */ 038public class FixedAssignments extends GlobalConstraint<Request, Enrollment> { 039 040 /** 041 * If there is a conflict that is fixed (method {@link CourseRequest#isFixed()} returns true) 042 * and equal to the initial assignment (returned by {@link CourseRequest#getFixedValue()}), 043 * the given enrollment is put into the conflicts. 044 */ 045 @Override 046 public void computeConflicts(Assignment<Request, Enrollment> assignment, Enrollment enrollment, Set<Enrollment> conflicts) { 047 for (Enrollment conflict: conflicts) { 048 if (conflict.getRequest() instanceof CourseRequest) { 049 CourseRequest cr = (CourseRequest)conflict.getRequest(); 050 if (cr.isFixed() && conflict.equals(cr.getFixedValue())) { 051 conflicts.add(enrollment); 052 return; 053 } 054 } 055 } 056 } 057}