org.cpsolver.exam.model

## Class ExamRoom

- java.lang.Object
- - org.cpsolver.ifs.model.Constraint<V,T>
  - - org.cpsolver.ifs.assignment.context.ConstraintWithContext<Exam,ExamPlacement,ExamRoom.ExamRoomContext>
    - - org.cpsolver.exam.model.ExamRoom

- All Implemented Interfaces:
    Comparable<Constraint<Exam,ExamPlacement>>, CanHoldContext, HasAssignmentContext<Exam,ExamPlacement,ExamRoom.ExamRoomContext>

      public class ExamRoom
      extends ConstraintWithContext<Exam,ExamPlacement,ExamRoom.ExamRoomContext>

  A room. Only one exam can use a room at a time (period).
  Version:
    ExamTT 1.3 (Examination Timetabling)
    Copyright (C) 2008 - 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/.
  Author:
    Tomáš Müller

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `ExamRoom.ExamRoomContext`

  - ### 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
    `ExamRoom(ExamModel model, long id, String name, int size, int altSize, Double coordX, Double coordY)` Constructor

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addPartition(ExamRoom room)` Add partition of this room.
    `void` | `assigned(Assignment<Exam,ExamPlacement> assignment, long iteration, ExamPlacement p)` An exam was assigned, update room assignment table
    `static boolean` | `checkParents(Collection<ExamRoomPlacement> roomsSoFar, ExamRoomPlacement room)` Check that the room and its parent are not used at the same time
    `int` | `compareTo(Constraint<Exam,ExamPlacement> o)` Compare two rooms (by unique id)
    `void` | `computeConflicts(Assignment<Exam,ExamPlacement> assignment, Exam exam, ExamPeriod period, Set<ExamPlacement> conflicts)` Compute conflicts if the given exam is assigned in this room and the given period
    `void` | `computeConflicts(Assignment<Exam,ExamPlacement> assignment, ExamPlacement p, Set<ExamPlacement> conflicts)` Compute conflicts between the given assignment of an exam and all the current assignments (of this room)
    `ExamRoom.ExamRoomContext` | `createAssignmentContext(Assignment<Exam,ExamPlacement> assignment)` Create a new assignment context for the given assignment.
    `boolean` | `equals(Object o)` Checks two rooms for equality
    `int` | `getAltSize()` Alternating seating capacity (to be used when `Exam.hasAltSeating()` is true)
    `Double` | `getCoordX()` X coordinate
    `Double` | `getCoordY()` Y coordinate
    `double` | `getDistanceInMeters(ExamRoom other)` Distance between two rooms.
    `String` | `getName()` Room name
    `ExamRoom` | `getParentRoom()` If this room is a partition of some other room, returns the parent room (which is partitioned).
    `List<ExamRoom>` | `getPartitions()` If this room is partitioned into multiple rooms, return room partitions
    `int` | `getPenalty(ExamPeriod period)` Return room penalty for given period
    `int` | `getPenalty(int period)`
    `List<ExamPlacement>` | `getPlacements(Assignment<Exam,ExamPlacement> assignment, ExamPeriod period)` Exams placed at the given period
    `ExamRoomSharing` | `getRoomSharing()`
    `int` | `getSize()` Normal seating capacity (to be used when `Exam.hasAltSeating()` is false)
    `int` | `hashCode()` Hash code
    `boolean` | `hasName()` Room name
    `boolean` | `inConflict(Assignment<Exam,ExamPlacement> assignment, Exam exam, ExamPeriod period)` Check for conflicts if the given exam is assigned in this room and the given period
    `boolean` | `inConflict(Assignment<Exam,ExamPlacement> assignment, ExamPlacement p)` Checks whether there is a conflict between the given assignment of an exam and all the current assignments (of this room)
    `boolean` | `isAvailable()` True if the room is available during at least one period,
    `boolean` | `isAvailable(ExamPeriod period)` True if the room is available (for examination timetabling) during the given period
    `boolean` | `isAvailable(int period)`
    `boolean` | `isConsistent(ExamPlacement p1, ExamPlacement p2)` False if the given two assignments are using this room at the same period
    `boolean` | `isHard()` Returns true if the constraint is hard.
    `void` | `setAvailable(ExamPeriod period, boolean available)` Set whether the room is available (for examination timetabling) during the given period
    `void` | `setAvailable(int period, boolean available)`
    `void` | `setHard(boolean hard)`
    `void` | `setPenalty(ExamPeriod period, int penalty)` Set room penalty for given period
    `void` | `setPenalty(int period, int penalty)`
    `String` | `toString()` Room unique id
    `void` | `unassigned(Assignment<Exam,ExamPlacement> assignment, long iteration, ExamPlacement p)` An exam was unassigned, update room assignment table

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

      `getAssignmentContextReference, getContext, getContext, setAssignmentContextReference, setModel`

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

      `addConstraintListener, addVariable, assignedVariables, computeConflictsNoForwardCheck, constraintListeners, countAssignedVariables, countVariables, getDescription, getId, getModel, removeConstraintListener, removeVariable, variables`

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

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

- - ### Constructor Detail

    - #### ExamRoom

          public ExamRoom(ExamModel model,
                          long id,
                          String name,
                          int size,
                          int altSize,
                          Double coordX,
                          Double coordY)

      Constructor
      Parameters:
        `model` - examination timetabling model
        `id` - unique id
        `name` - room name
        `size` - room (normal) seating capacity
        `altSize` - room alternating seating capacity (to be used when `Exam.hasAltSeating()` is true)
        `coordX` - x coordinate
        `coordY` - y coordinate

  - ### Method Detail

    - #### setHard

          public void setHard(boolean hard)

    - #### isHard

          public boolean isHard()

      Description copied from class: `Constraint`
      Returns true if the constraint is hard. Only hard constraints are allowed to unassign a variable when there is a conflict with a value that is being assigned
      Overrides:
        `isHard` in class `Constraint<Exam,ExamPlacement>`
      Returns:
        true if the constraint is hard

    - #### getDistanceInMeters

          public double getDistanceInMeters(ExamRoom other)

      Distance between two rooms. See `DistanceMetric`
      Parameters:
        `other` - another room
      Returns:
        distance between this and the given room

    - #### getSize

          public int getSize()

      Normal seating capacity (to be used when `Exam.hasAltSeating()` is false)
      Returns:
        room normal seating capacity

    - #### getAltSize

          public int getAltSize()

      Alternating seating capacity (to be used when `Exam.hasAltSeating()` is true)
      Returns:
        room examination seating capacity

    - #### getCoordX

          public Double getCoordX()

      X coordinate
      Returns:
        X-coordinate (latitude)

    - #### getCoordY

          public Double getCoordY()

      Y coordinate
      Returns:
        Y-coordinate (longitude)

    - #### getPlacements

          public List<ExamPlacement> getPlacements(Assignment<Exam,ExamPlacement> assignment,
                                                   ExamPeriod period)

      Exams placed at the given period
      Parameters:
        `assignment` - current assignment
        `period` - a period
      Returns:
        a placement of an exam in this room at the given period, null if unused (multiple placements can be returned if the room is shared between two or more exams)

    - #### isAvailable

          public boolean isAvailable(ExamPeriod period)

      True if the room is available (for examination timetabling) during the given period
      Parameters:
        `period` - a period
      Returns:
        true if an exam can be scheduled into this room at the given period, false if otherwise

    - #### isAvailable

          public boolean isAvailable(int period)

    - #### isAvailable

          public boolean isAvailable()

      True if the room is available during at least one period,
      Returns:
        true if there is an examination period at which the room is available

    - #### setAvailable

          public void setAvailable(ExamPeriod period,
                                   boolean available)

      Set whether the room is available (for examination timetabling) during the given period
      Parameters:
        `period` - a period
        `available` - true if an exam can be scheduled into this room at the given period, false if otherwise

    - #### setAvailable

          public void setAvailable(int period,
                                   boolean available)

    - #### getPenalty

          public int getPenalty(ExamPeriod period)

      Return room penalty for given period
      Parameters:
        `period` - given period
      Returns:
        room penalty for the given period

    - #### getPenalty

          public int getPenalty(int period)

    - #### setPenalty

          public void setPenalty(ExamPeriod period,
                                 int penalty)

      Set room penalty for given period
      Parameters:
        `period` - given period
        `penalty` - penalty for the given period

    - #### setPenalty

          public void setPenalty(int period,
                                 int penalty)

    - #### getRoomSharing

          public ExamRoomSharing getRoomSharing()

    - #### computeConflicts

          public void computeConflicts(Assignment<Exam,ExamPlacement> assignment,
                                       Exam exam,
                                       ExamPeriod period,
                                       Set<ExamPlacement> conflicts)

      Compute conflicts if the given exam is assigned in this room and the given period

    - #### inConflict

          public boolean inConflict(Assignment<Exam,ExamPlacement> assignment,
                                    Exam exam,
                                    ExamPeriod period)

      Check for conflicts if the given exam is assigned in this room and the given period

    - #### computeConflicts

          public void computeConflicts(Assignment<Exam,ExamPlacement> assignment,
                                       ExamPlacement p,
                                       Set<ExamPlacement> conflicts)

      Compute conflicts between the given assignment of an exam and all the current assignments (of this room)
      Specified by:
        `computeConflicts` in class `Constraint<Exam,ExamPlacement>`
      Parameters:
        `assignment` - current assignment
        `p` - value to be assigned to its variable
        `conflicts` - resultant set of conflicting values

    - #### inConflict

          public boolean inConflict(Assignment<Exam,ExamPlacement> assignment,
                                    ExamPlacement p)

      Checks whether there is a conflict between the given assignment of an exam and all the current assignments (of this room)
      Overrides:
        `inConflict` in class `Constraint<Exam,ExamPlacement>`
      Parameters:
        `assignment` - current assignment
        `p` - given value
      Returns:
        true if there is a conflict with other assigned variables of the constraint

    - #### isConsistent

          public boolean isConsistent(ExamPlacement p1,
                                      ExamPlacement p2)

      False if the given two assignments are using this room at the same period
      Overrides:
        `isConsistent` in class `Constraint<Exam,ExamPlacement>`
      Parameters:
        `p1` - a value
        `p2` - a value
      Returns:
        true if the constraint is ok with the assignment

    - #### assigned

          public void assigned(Assignment<Exam,ExamPlacement> assignment,
                               long iteration,
                               ExamPlacement p)

      An exam was assigned, update room assignment table
      Overrides:
        `assigned` in class `ConstraintWithContext<Exam,ExamPlacement,ExamRoom.ExamRoomContext>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `p` - assigned value

    - #### unassigned

          public void unassigned(Assignment<Exam,ExamPlacement> assignment,
                                 long iteration,
                                 ExamPlacement p)

      An exam was unassigned, update room assignment table
      Overrides:
        `unassigned` in class `ConstraintWithContext<Exam,ExamPlacement,ExamRoom.ExamRoomContext>`
      Parameters:
        `assignment` - current assignment
        `iteration` - current iteration
        `p` - unassigned value

    - #### equals

          public boolean equals(Object o)

      Checks two rooms for equality
      Overrides:
        `equals` in class `Constraint<Exam,ExamPlacement>`

    - #### hashCode

          public int hashCode()

      Hash code
      Overrides:
        `hashCode` in class `Constraint<Exam,ExamPlacement>`

    - #### getName

          public String getName()

      Room name
      Overrides:
        `getName` in class `Constraint<Exam,ExamPlacement>`
      Returns:
        constraint name

    - #### hasName

          public boolean hasName()

      Room name
      Returns:
        true if the room name is set and not empty

    - #### toString

          public String toString()

      Room unique id
      Overrides:
        `toString` in class `Object`

    - #### addPartition

          public void addPartition(ExamRoom room)

      Add partition of this room. This room is unavailable at a time when one of the partition is not available and vice versa.
      Parameters:
        `room` - room partition

    - #### getParentRoom

          public ExamRoom getParentRoom()

      If this room is a partition of some other room, returns the parent room (which is partitioned).
      Returns:
        parent room

    - #### getPartitions

          public List<ExamRoom> getPartitions()

      If this room is partitioned into multiple rooms, return room partitions
      Returns:
        room partitions

    - #### compareTo

          public int compareTo(Constraint<Exam,ExamPlacement> o)

      Compare two rooms (by unique id)
      Specified by:
        `compareTo` in interface `Comparable<Constraint<Exam,ExamPlacement>>`
      Overrides:
        `compareTo` in class `Constraint<Exam,ExamPlacement>`

    - #### createAssignmentContext

          public ExamRoom.ExamRoomContext createAssignmentContext(Assignment<Exam,ExamPlacement> 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

    - #### checkParents

          public static boolean checkParents(Collection<ExamRoomPlacement> roomsSoFar,
                                             ExamRoomPlacement room)

      Check that the room and its parent are not used at the same time