java.lang.Object
org.ddolib.examples.layered.talentscheduling.TSProblem
All Implemented Interfaces:
Problem<TSState>

public class TSProblem extends Object implements Problem<TSState>
The Talent Scheduling Problem (TSP) instance.

In the Talent Scheduling Problem, we have a set of scenes to shoot, each requiring a subset of actors, and each actor has an associated cost per day. The objective is to schedule the scenes to minimize the total cost of actors while respecting scene requirements.

This class implements the Problem interface for use with search algorithms (ACS, A*, DDO, etc.). It provides methods to get the initial state, compute transition costs, and define the domain for each state variable.

The problem can be constructed either:

  • From explicit data arrays (number of scenes, number of actors, actor costs, scene durations, and actor requirements),
  • Or by reading a data file in the format used in the Talent Scheduling Problem dataset (source).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The optimal solution value if known (optional, used for testing and benchmarking).
  • Constructor Summary

    Constructors
    Constructor
    Description
    TSProblem(int nbScene, int nbActors, int[] costs, int[] duration, BitSet[] actors, Optional<Double> optimal)
    Constructs a TSP instance from explicit parameters.
    Constructs a TSP instance by reading a file in the standard dataset format.
  • Method Summary

    Modifier and Type
    Method
    Description
    domain(TSState state, int var)
    Returns the domain of possible values for a given variable when applied to a specific state.
    double
    evaluate(int[] solution)
    Given a solution such that solution[i] is the value of the variable x_i, returns the value of this solution and checks if the solution respects the problem's constraints.
    Returns the initial state of the problem.
    double
    Returns the initial objective value associated with the initial state.
    int
    Returns the total number of decision variables in this problem.
    onLocationActors(BitSet remainingScenes, BitSet maybeScenes)
    Returns the set of actors already present on location, i.e., actors involved in past scenes and needed for future scenes, given explicit remaining and maybe scene sets.
    Returns the set of actors already present on location at the current state, i.e., actors involved in past scenes and needed for future scenes.
    Returns the known optimal value of the problem, if available.
    int
    sceneCost(int scene)
    Computes the total cost per day of all actors required to perform a given scene.
     
    transition(TSState state, Decision decision)
    Applies a decision to a state, computing the next state according to the problem's transition function.
    double
    transitionCost(TSState state, Decision decision)
    Computes the change in objective value resulting from applying a decision to a given state.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface org.ddolib.layered.modeling.Problem

    hasNonNegativeCosts
  • Field Details

    • optimal

      public final Optional<Double> optimal
      The optimal solution value if known (optional, used for testing and benchmarking).
  • Constructor Details

    • TSProblem

      public TSProblem(int nbScene, int nbActors, int[] costs, int[] duration, BitSet[] actors, Optional<Double> optimal)
      Constructs a TSP instance from explicit parameters.
      Parameters:
      nbScene - number of scenes
      nbActors - number of actors
      costs - array containing the cost of each actor per day
      duration - array containing the duration of each scene
      actors - array of BitSets representing the actors required for each scene
      optimal - Optional value of the optimal solution, if known
    • TSProblem

      public TSProblem(String fname) throws IOException
      Constructs a TSP instance by reading a file in the standard dataset format.

      The first line gives the name of the instance, optionally followed by two tokens, the last one being the optimal value. The rest of the file is read as a sequence of integers separated by any whitespace, so that the line breaks, the blank lines and the leading spaces do not matter: the number of scenes and the number of actors (on one line or on two lines, both forms are used by the datasets), then for each actor one 0/1 value per scene followed by the cost of the actor, then the duration of each scene.

      Parameters:
      fname - path to the input file
      Throws:
      IOException - if an I/O error occurs while reading the file, or if the file does not contain the expected numbers
  • Method Details

    • nbVars

      public int nbVars()
      Description copied from interface: Problem
      Returns the total number of decision variables in this problem.
      Specified by:
      nbVars in interface Problem<TSState>
      Returns:
      the total number of decision variables in this problem
    • initialState

      public TSState initialState()
      Description copied from interface: Problem
      Returns the initial state of the problem.
      Specified by:
      initialState in interface Problem<TSState>
      Returns:
      the state representing the starting point of the optimization
    • initialValue

      public double initialValue()
      Description copied from interface: Problem
      Returns the initial objective value associated with the initial state.
      Specified by:
      initialValue in interface Problem<TSState>
      Returns:
      the starting value of the objective function
    • domain

      public Iterator<Integer> domain(TSState state, int var)
      Description copied from interface: Problem
      Returns the domain of possible values for a given variable when applied to a specific state.
      Specified by:
      domain in interface Problem<TSState>
      Parameters:
      state - the current state
      var - the variable index whose domain is queried
      Returns:
      an iterator over all feasible values for the variable in this state
    • transition

      public TSState transition(TSState state, Decision decision)
      Description copied from interface: Problem
      Applies a decision to a state, computing the next state according to the problem's transition function.
      Specified by:
      transition in interface Problem<TSState>
      Parameters:
      state - the state from which the transition originates
      decision - the decision to apply
      Returns:
      the resulting state after applying the decision
    • transitionCost

      public double transitionCost(TSState state, Decision decision)
      Description copied from interface: Problem
      Computes the change in objective value resulting from applying a decision to a given state.
      Specified by:
      transitionCost in interface Problem<TSState>
      Parameters:
      state - the state from which the transition originates
      decision - the decision to apply
      Returns:
      the incremental objective cost/value associated with this decision
    • optimalValue

      public Optional<Double> optimalValue()
      Description copied from interface: Problem
      Returns the known optimal value of the problem, if available.

      Note: This value should correspond to the expected output of the solver. For maximization problems, be careful with negative values.

      Specified by:
      optimalValue in interface Problem<TSState>
      Returns:
      an Optional containing the known optimal value, or empty if unknown
    • evaluate

      public double evaluate(int[] solution) throws InvalidSolutionException
      Description copied from interface: Problem
      Given a solution such that solution[i] is the value of the variable x_i, returns the value of this solution and checks if the solution respects the problem's constraints.

      Note: For maximization problems, the returned value is minus the computed value.

      Specified by:
      evaluate in interface Problem<TSState>
      Parameters:
      solution - a solution of the problem
      Returns:
      the value of the input solution
      Throws:
      InvalidSolutionException - if the solution does not respect the problem's constraints
    • sceneCost

      public int sceneCost(int scene)
      Computes the total cost per day of all actors required to perform a given scene.
      Parameters:
      scene - the index of the scene
      Returns:
      the sum of the daily costs of the actors involved in scene
    • onLocationActors

      public BitSet onLocationActors(TSState state)
      Returns the set of actors already present on location at the current state, i.e., actors involved in past scenes and needed for future scenes.
      Parameters:
      state - current state of the MDD
      Returns:
      BitSet of actors currently on location
    • onLocationActors

      public BitSet onLocationActors(BitSet remainingScenes, BitSet maybeScenes)
      Returns the set of actors already present on location, i.e., actors involved in past scenes and needed for future scenes, given explicit remaining and maybe scene sets.
      Parameters:
      remainingScenes - the scenes that still need to be scheduled
      maybeScenes - the scenes that may or may not still need to be scheduled
      Returns:
      the BitSet of actors currently on location
    • toString

      public String toString()
      Overrides:
      toString in class Object