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;
009import org.cpsolver.studentsct.model.Student;
010
011/**
012 * Student not available. This global constraint ensures that all students are available
013 * during their enrollments. That is the student does not have any overlapping unavailabilities
014 * that do not allow for overlap. Function {@link Student#isAvailable(Enrollment)} is used.
015 * 
016 * @author  Tomáš Müller
017 * @version StudentSct 1.3 (Student Sectioning)<br>
018 *          Copyright (C) 2014 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 StudentNotAvailable extends GlobalConstraint<Request, Enrollment> {
037    
038    /**
039     * A given enrollment is conflicting, if the student is not available.
040     * That is there is at least one unavailability that cannot overlap and that is overlapping with the enrollment.
041     * 
042     * @param enrollment {@link Enrollment} that is being considered
043     * @param conflicts all computed conflicting enrollments are added into this set
044     */
045    @Override
046    public void computeConflicts(Assignment<Request, Enrollment> assignment, Enrollment enrollment, Set<Enrollment> conflicts) {
047        if (inConflict(assignment, enrollment))
048            conflicts.add(enrollment);
049    }
050    
051    /**
052     * A given enrollment is conflicting, if the student is not available.
053     * That is there is at least one unavailability that cannot overlap and that is overlapping with the enrollment.
054     * 
055     * @param enrollment {@link Enrollment} that is being considered
056     * @return true, if the student is not available during the given enrollment 
057     */
058    @Override
059    public boolean inConflict(Assignment<Request, Enrollment> assignment, Enrollment enrollment) {
060        return !enrollment.getStudent().isAvailable(enrollment);
061    }
062    
063    @Override
064    public String toString() {
065        return "StudentNotAvailable";
066    }
067}