org.cpsolver.coursett.constraint

## Class RoomConstraint

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.assignment.context.ConstraintWithContext<Lecture,Placement,RoomConstraint.RoomConstraintContext>
    - - org.cpsolver.coursett.constraint.RoomConstraint

- All Implemented Interfaces:
    Comparable<Constraint<Lecture,Placement>>, CanHoldContext, HasAssignmentContext<Lecture,Placement,RoomConstraint.RoomConstraintContext>
  Direct Known Subclasses:
    DiscouragedRoomConstraint

      public class RoomConstraint
      extends ConstraintWithContext<Lecture,Placement,RoomConstraint.RoomConstraintContext>

  Room constraint.
  Classes with the same room can not overlap in time.
  Version:
    CourseTT 1.3 (University Course Timetabling)
    Copyright (C) 2006 - 2014 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/.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `RoomConstraint.RoomConstraintContext`

  - ### Field Summary

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

      `iConstraintListeners, iId`

    - ### Fields inherited from interface org.cpsolver.ifs.assignment.context.CanHoldContext

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RoomConstraint(Long id, String name, Long buildingId, int capacity, RoomSharingModel roomSharingModel, Double x, Double y, boolean ignoreTooFar, boolean constraint)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `assigned(Assignment<Lecture,Placement> assignment, long iteration, Placement placement)` Given value is to be assigned to its variable.
    `void` | `computeConflicts(Assignment<Lecture,Placement> assignment, Placement placement, Set<Placement> conflicts)` The only method which has to be implemented by any constraint.
    `RoomConstraint.RoomConstraintContext` | `createAssignmentContext(Assignment<Lecture,Placement> assignment)` Create a new assignment context for the given assignment.
    `List<Placement>[]` | `getAvailableArray()`
    `Long` | `getBuildingId()` Building id
    `int` | `getCapacity()` Capacity
    `boolean` | `getConstraint()`
    `boolean` | `getIgnoreTooFar()`
    `String` | `getName()` Room name
    `Double` | `getPosX()` X-position of the building
    `Double` | `getPosY()` Y-position of the building
    `List<Placement>` | `getResource(Assignment<Lecture,Placement> assignment, int slot)` Lookup table getResource()[slot] → lecture using this room placed in the given time slot (null if empty)
    `Long` | `getResourceId()` Room id
    `Placement[]` | `getResourceOfWeek(Assignment<Lecture,Placement> assignment, int startDay)`
    `String` | `getRoomName()`
    `RoomSharingModel` | `getSharingModel()`
    `Long` | `getType()`
    `boolean` | `checkRoomSize(Placement placement, Collection<Placement> other)`
    `boolean` | `checkRoomSize(Placement placement, Collection<Placement> other, Placement extra)`
    `boolean` | `inConflict(Assignment<Lecture,Placement> assignment, Placement placement)` Returns true if the given assignment is inconsistent with the existing assignments respecting this constraint.
    `boolean` | `isAvailable(int slot)`
    `boolean` | `isAvailable(Lecture lecture, TimeLocation time, Long scheduler)`
    `boolean` | `isConsistent(Placement p1, Placement p2)` Returns true if the given assignments are consistent respecting this constraint.
    `void` | `setCoordinates(Double x, Double y)` Position of the building
    `void` | `setModel(Model<Lecture,Placement> model)` Sets the model which the constraint belongs to
    `void` | `setNotAvailable(Placement placement)`
    `void` | `setType(Long type)`
    `String` | `toString()`
    `void` | `unassigned(Assignment<Lecture,Placement> assignment, long iteration, Placement placement)` Given value is unassigned from its variable.

    - ### Methods inherited from class org.cpsolver.ifs.assignment.context.ConstraintWithContext

      `getAssignmentContextReference, getContext, getContext, setAssignmentContextReference`

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

      `addConstraintListener, addVariable, assignedVariables, compareTo, computeConflictsNoForwardCheck, constraintListeners, countAssignedVariables, countVariables, equals, getDescription, getId, getModel, hashCode, isHard, removeConstraintListener, removeVariable, variables`

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

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

- - ### Constructor Detail

    - #### RoomConstraint

          public RoomConstraint(Long id,
                                String name,
                                Long buildingId,
                                int capacity,
                                RoomSharingModel roomSharingModel,
                                Double x,
                                Double y,
                                boolean ignoreTooFar,
                                boolean constraint)

      Constructor
      Parameters:
        `id` - room unique id
        `name` - room name
        `buildingId` - building unique id
        `capacity` - room size
        `roomSharingModel` - room sharing model
        `x` - X-coordinate (latitude)
        `y` - Y-coordinate (longitude)
        `ignoreTooFar` - ignore distances if set to true
        `constraint` - hard constraint if true (classes cannot overlap in this room)

  - ### Method Detail

    - #### setModel

          public void setModel(Model<Lecture,Placement> model)

      Description copied from class: `Constraint`
      Sets the model which the constraint belongs to
      Overrides:
        `setModel` in class `ConstraintWithContext<Lecture,Placement,RoomConstraint.RoomConstraintContext>`
      Parameters:
        `model` - problem model

    - #### setNotAvailable

          public void setNotAvailable(Placement placement)

    - #### isAvailable

          public boolean isAvailable(int slot)

    - #### isAvailable

          public boolean isAvailable(Lecture lecture,
                                     TimeLocation time,
                                     Long scheduler)

    - #### getAvailableArray

          public List<Placement>[] getAvailableArray()

    - #### getSharingModel

          public RoomSharingModel getSharingModel()

    - #### getResourceId

          public Long getResourceId()

      Room id
      Returns:
        room unique id

    - #### getBuildingId

          public Long getBuildingId()

      Building id
      Returns:
        building unique id

    - #### getName

          public String getName()

      Room name
      Overrides:
        `getName` in class `Constraint<Lecture,Placement>`
      Returns:
        constraint name

    - #### getRoomName

          public String getRoomName()

    - #### getCapacity

          public int getCapacity()

      Capacity
      Returns:
        room size

    - #### computeConflicts

          public void computeConflicts(Assignment<Lecture,Placement> assignment,
                                       Placement placement,
                                       Set<Placement> 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<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `placement` - value to be assigned to its variable
        `conflicts` - resultant set of conflicting values

    - #### checkRoomSize

          public boolean checkRoomSize(Placement placement,
                                       Collection<Placement> other,
                                       Placement extra)

    - #### checkRoomSize

          public boolean checkRoomSize(Placement placement,
                                       Collection<Placement> other)

    - #### inConflict

          public boolean inConflict(Assignment<Lecture,Placement> assignment,
                                    Placement placement)

      Description copied from class: `Constraint`
      Returns true if the given assignment is inconsistent with the existing assignments respecting this constraint. This method is used by MAC (see `MacPropagation`).
      Overrides:
        `inConflict` in class `Constraint<Lecture,Placement>`
      Parameters:
        `assignment` - current assignment
        `placement` - given value
      Returns:
        true if there is a conflict with other assigned variables of the constraint

    - #### isConsistent

          public boolean isConsistent(Placement p1,
                                      Placement p2)

      Description copied from class: `Constraint`
      Returns true if the given assignments are consistent respecting this constraint. This method is used by MAC (see `MacPropagation`).
      Overrides:
        `isConsistent` in class `Constraint<Lecture,Placement>`
      Parameters:
        `p1` - a value
        `p2` - a value
      Returns:
        true if the constraint is ok with the assignment

    - #### assigned

          public void assigned(Assignment<Lecture,Placement> assignment,
                               long iteration,
                               Placement placement)

      Description copied from class: `Constraint`
      Given value is to be assigned to its variable. In this method, the constraint should unassigns all variables which are in conflict with the given assignment because of this constraint.
      Overrides:
        `assigned` in class `ConstraintWithContext<Lecture,Placement,RoomConstraint.RoomConstraintContext>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `placement` - assigned value

    - #### unassigned

          public void unassigned(Assignment<Lecture,Placement> assignment,
                                 long iteration,
                                 Placement placement)

      Description copied from class: `Constraint`
      Given value is unassigned from its variable.
      Overrides:
        `unassigned` in class `ConstraintWithContext<Lecture,Placement,RoomConstraint.RoomConstraintContext>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `placement` - unassigned value

    - #### getResource

          public List<Placement> getResource(Assignment<Lecture,Placement> assignment,
                                             int slot)

      Lookup table getResource()[slot] → lecture using this room placed in the given time slot (null if empty)
      Parameters:
        `assignment` - current assignment
        `slot` - time slot
      Returns:
        list of placements in the room in the given time

    - #### getResourceOfWeek

          public Placement[] getResourceOfWeek(Assignment<Lecture,Placement> assignment,
                                               int startDay)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### setCoordinates

          public void setCoordinates(Double x,
                                     Double y)

      Position of the building
      Parameters:
        `x` - X-coordinate (latitude)
        `y` - Y-coordinate (longitude)

    - #### getPosX

          public Double getPosX()

      X-position of the building
      Returns:
        X-coordinate (latitude)

    - #### getPosY

          public Double getPosY()

      Y-position of the building
      Returns:
        Y-coordinate (longitude)

    - #### getIgnoreTooFar

          public boolean getIgnoreTooFar()

    - #### getConstraint

          public boolean getConstraint()

    - #### getType

          public Long getType()

    - #### setType

          public void setType(Long type)

    - #### createAssignmentContext

          public RoomConstraint.RoomConstraintContext createAssignmentContext(Assignment<Lecture,Placement> assignment)

      Description copied from interface: `HasAssignmentContext`
      Create a new assignment context for the given assignment. If there are already some variables assigned in the value, the method should make sure that the context is appropriately initialized.
      Parameters:
        `assignment` - an assignment for which there needs to be an assignment context
      Returns:
        a new instance of the assignment context, filled according to the given assignment