org.cpsolver.exam.heuristics

## Class ExamConstruction

- java.lang.Object
- - org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext<Exam,ExamPlacement,ExamConstruction.Context>
  - - org.cpsolver.exam.heuristics.ExamConstruction

- All Implemented Interfaces:
    CanHoldContext, HasAssignmentContext<Exam,ExamPlacement,ExamConstruction.Context>, NeighbourSelection<Exam,ExamPlacement>

      public class ExamConstruction
      extends NeighbourSelectionWithContext<Exam,ExamPlacement,ExamConstruction.Context>

  Initial solution construction heuristics.
  While there are exams that are still not assigned:
  - The worst unassigned exam is selected (using `Exam.compareTo(Exam)`)
  - The best period that does not break any hard constraint and for which there is a room assignment available is selected together with the set the best available rooms for the exam in the best period (computed using `Exam.findBestAvailableRooms(Assignment, ExamPeriodPlacement)`).
  If problem property ExamConstruction.CheckLocalOptimality is true, local (time) optimality is enforced at the end of this phase. During this procedure, for each exam, it tries to change the period of the exam so that the time cost is lower (see `ExamPlacement.getTimeCost(Assignment)`), but no hard constraint is violated. The problem is considered locally optimal if there is no such move.
  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` | `ExamConstruction.Context`

  - ### Field Summary

    - ### Fields inherited from class org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext

      `iContextOverride`

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

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExamConstruction(DataProperties properties)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Neighbour<Exam,ExamPlacement>` | `checkLocalOptimality(Assignment<Exam,ExamPlacement> assignment, ExamModel model)` Find a new assignment of one of the assigned exams that improves the time cost `ExamPlacement.getTimeCost(Assignment)` and for which there is a set of available rooms `Exam.findBestAvailableRooms(Assignment, ExamPeriodPlacement)`.
    `ExamConstruction.Context` | `createAssignmentContext(Assignment<Exam,ExamPlacement> assignment)` Create a new assignment context for the given assignment.
    `void` | `init(Solver<Exam,ExamPlacement> solver)` Initialization
    `Neighbour<Exam,ExamPlacement>` | `selectNeighbour(Solution<Exam,ExamPlacement> solution)` Select a neighbour.

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

      `getAssignmentContextReference, getContext, getContext, hasContextOverride, isSingleContextSolver, setAssignmentContextReference`

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ExamConstruction

          public ExamConstruction(DataProperties properties)

      Constructor
      Parameters:
        `properties` - problem properties

  - ### Method Detail

    - #### init

          public void init(Solver<Exam,ExamPlacement> solver)

      Initialization
      Specified by:
        `init` in interface `NeighbourSelection<Exam,ExamPlacement>`
      Overrides:
        `init` in class `NeighbourSelectionWithContext<Exam,ExamPlacement,ExamConstruction.Context>`
      Parameters:
        `solver` - current solver

    - #### checkLocalOptimality

          public Neighbour<Exam,ExamPlacement> checkLocalOptimality(Assignment<Exam,ExamPlacement> assignment,
                                                                    ExamModel model)

      Find a new assignment of one of the assigned exams that improves the time cost `ExamPlacement.getTimeCost(Assignment)` and for which there is a set of available rooms `Exam.findBestAvailableRooms(Assignment, ExamPeriodPlacement)`. Return null, if there is no such assignment (the problem is considered locally optimal).
      Parameters:
        `assignment` - current assignment
        `model` - problem model
      Returns:
        a neighbour to assign or null if none was found

    - #### selectNeighbour

          public Neighbour<Exam,ExamPlacement> selectNeighbour(Solution<Exam,ExamPlacement> solution)

      Select a neighbour. While there are exams that are still not assigned:
      - The worst unassigned exam is selected (using `Exam.compareTo(Exam)`)
      - The best period that does not break any hard constraint and for which there is a room assignment available is selected together with the set the best available rooms for the exam in the best period (computed using `Exam.findBestAvailableRooms(Assignment, ExamPeriodPlacement)`).
      Return null when done (all variables are assigned and the problem is locally optimal).
      Parameters:
        `solution` - given solution
      Returns:
        a neighbour assignment

    - #### createAssignmentContext

          public ExamConstruction.Context 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