    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 * @version StudentSct 1.3 (Student Sectioning)<br>
    017 *          Copyright (C) 2014 Tomáš Müller<br>
    018 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    019 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    020 * <br>
    021 *          This library is free software; you can redistribute it and/or modify
    022 *          it under the terms of the GNU Lesser General Public License as
    023 *          published by the Free Software Foundation; either version 3 of the
    024 *          License, or (at your option) any later version. <br>
    025 * <br>
    026 *          This library is distributed in the hope that it will be useful, but
    027 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    028 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    029 *          Lesser General Public License for more details. <br>
    030 * <br>
    031 *          You should have received a copy of the GNU Lesser General Public
    032 *          License along with this library; if not see
    033 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    034 */
    035public class StudentNotAvailable extends GlobalConstraint<Request, Enrollment> {
    036
    037    /**
    038     * A given enrollment is conflicting, if the student is not available.
    039     * That is there is at least one unavailability that cannot overlap and that is overlapping with the enrollment.
    040     *
    041     * @param enrollment {@link Enrollment} that is being considered
    042     * @param conflicts all computed conflicting enrollments are added into this set
    043     */
    044    @Override
    045    public void computeConflicts(Assignment<Request, Enrollment> assignment, Enrollment enrollment, Set<Enrollment> conflicts) {
    046        if (inConflict(assignment, enrollment))
    047            conflicts.add(enrollment);
    048    }
    049
    050    /**
    051     * A given enrollment is conflicting, if the student is not available.
    052     * That is there is at least one unavailability that cannot overlap and that is overlapping with the enrollment.
    053     *
    054     * @param enrollment {@link Enrollment} that is being considered
    055     * @return true, if the student is not available during the given enrollment
    056     */
    057    @Override
    058    public boolean inConflict(Assignment<Request, Enrollment> assignment, Enrollment enrollment) {
    059        return !enrollment.getStudent().isAvailable(enrollment);
    060    }
    061
    062    @Override
    063    public String toString() {
    064        return "StudentNotAvailable";
    065    }
    066}