org.cpsolver.studentsct.constraint

## Class DependentCourses

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.model.GlobalConstraint<Request,Enrollment>
    - - org.cpsolver.studentsct.constraint.DependentCourses

- All Implemented Interfaces:
    Comparable<Constraint<Request,Enrollment>>

      public class DependentCourses
      extends GlobalConstraint<Request,Enrollment>

  Global constraint for dependent courses. If a student requests both a course and its parent (identified by `Course.getParent()`), the student cannot get the dependent course without also having the parent course assigned.
  Version:
    StudentSct 1.4 (Student Sectioning)
    Copyright (C) 2007 - 2025 Tomáš Müller
    muller@unitime.org
    http://muller.unitime.org
    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public License along with this library; if not see http://www.gnu.org/licenses/.
  Author:
    Tomáš Müller

- - ### Field Summary

    - ### Fields inherited from class org.cpsolver.ifs.model.Constraint

      `iConstraintListeners, iId`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DependentCourses()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canLeaveUnassigned(Student student, LinkedSections.EnrollmentAssignment assignment, Request parentRequest)` A special check for the branch-and-bound routine (such as `BranchBoundSelection`) which constructs a full schedule for a student.
    `void` | `computeConflicts(Assignment<Request,Enrollment> assignment, Enrollment value, Set<Enrollment> conflicts)` The only method which has to be implemented by any constraint.
    `boolean` | `inConflict(Assignment<Request,Enrollment> assignment, Enrollment value)` Conflict check.
    `boolean` | `isPartialScheduleInConflict(Student student, LinkedSections.EnrollmentAssignment assignment, int index)` A special check for the branch-and-bound routine (such as `BranchBoundSelection`) which constructs a full schedule for a student.

    - ### Methods inherited from class org.cpsolver.ifs.model.GlobalConstraint

      `addVariable, assigned, assignedVariables, countAssignedVariables, getName, removeVariable, toString, unassigned, variables`

    - ### Methods inherited from class org.cpsolver.ifs.model.Constraint

      `addConstraintListener, compareTo, computeConflictsNoForwardCheck, constraintListeners, countVariables, equals, getDescription, getId, getModel, hashCode, isConsistent, isHard, removeConstraintListener, setModel`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### DependentCourses

          public DependentCourses()

  - ### Method Detail

    - #### computeConflicts

          public void computeConflicts(Assignment<Request,Enrollment> assignment,
                                       Enrollment value,
                                       Set<Enrollment> conflicts)

      Description copied from class: `Constraint`
      The only method which has to be implemented by any constraint. It returns the values which needs to be unassigned in order to make this constraint consistent with the given value if it is assigned to its variable. The computed list of conflicting values is added to the given set of conflicts.
      Specified by:
        `computeConflicts` in class `Constraint<Request,Enrollment>`
      Parameters:
        `assignment` - current assignment
        `value` - value to be assigned to its variable
        `conflicts` - resultant set of conflicting values

    - #### inConflict

          public boolean inConflict(Assignment<Request,Enrollment> assignment,
                                    Enrollment value)

      Conflict check. There is a conflict when a student has an assigned course that has a parent course, the student also has the parent course requested, but does not have the parent course assigned.
      Overrides:
        `inConflict` in class `Constraint<Request,Enrollment>`
      Parameters:
        `assignment` - current assignment
        `value` - given value
      Returns:
        true if there is a conflict with other assigned variables of the constraint

    - #### isPartialScheduleInConflict

          public boolean isPartialScheduleInConflict(Student student,
                                                     LinkedSections.EnrollmentAssignment assignment,
                                                     int index)

      A special check for the branch-and-bound routine (such as `BranchBoundSelection`) which constructs a full schedule for a student. There is a conflict when there is a dependent course assigned within the already constructed schedule (up to the given index) and the already constructed schedule also contains the parent course but it is not assigned.
      Parameters:
        `student` - a student
        `assignment` - current assigned up to the given index
        `index` - index of the variable that is being assigned
      Returns:
        true if there is no conflict

    - #### canLeaveUnassigned

          public boolean canLeaveUnassigned(Student student,
                                            LinkedSections.EnrollmentAssignment assignment,
                                            Request parentRequest)

      A special check for the branch-and-bound routine (such as `BranchBoundSelection`) which constructs a full schedule for a student. The parent request cannot be left unassigned if it contains a parent course for any of the already assigned dependent course.
      Parameters:
        `student` - a student
        `assignment` - current assigned up to the given index
        `parentRequest` - parent request (that is being checked if it can be left unassigned)
      Returns:
        true if the parent request can be left unassigned (it is not a parent course for an assigned dependent course)