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