Class TSProblem
java.lang.Object
org.ddolib.examples.talentscheduling.TSProblem
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the domain of possible values for a given variable when applied to a specific state.doubleevaluate(int[] solution) Given a solution such thatsolution[i]is the value of the variablex_i, returns the value of this solution and checks if the solution respects the problem's constraints.Returns the initial state of the problem.doubleReturns the initial objective value associated with the initial state.intnbVars()onLocationActors(BitSet remainingScenes, BitSet maybeScenes) 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.Returns the known optimal value of the problem, if available.intsceneCost(int scene) toString()transition(TSState state, Decision decision) Applies a decision to a state, computing the next state according to the problem's transition function.doubletransitionCost(TSState state, Decision decision) Computes the change in objective value resulting from applying a decision to a given state.
-
Field Details
-
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
Constructs a TSP instance by reading a file in the standard dataset format.- Parameters:
fname- Path to the input file.- Throws:
IOException- If an I/O error occurs while reading the file.
-
-
Method Details
-
nbVars
public int nbVars() -
initialState
Description copied from interface:ProblemReturns the initial state of the problem.- Specified by:
initialStatein interfaceProblem<TSState>- Returns:
- the state representing the starting point of the optimization
-
initialValue
public double initialValue()Description copied from interface:ProblemReturns the initial objective value associated with the initial state.- Specified by:
initialValuein interfaceProblem<TSState>- Returns:
- the starting value of the objective function
-
domain
Description copied from interface:ProblemReturns the domain of possible values for a given variable when applied to a specific state. -
transition
Description copied from interface:ProblemApplies a decision to a state, computing the next state according to the problem's transition function.- Specified by:
transitionin interfaceProblem<TSState>- Parameters:
state- the state from which the transition originatesdecision- the decision to apply- Returns:
- the resulting state after applying the decision
-
transitionCost
Description copied from interface:ProblemComputes the change in objective value resulting from applying a decision to a given state.- Specified by:
transitionCostin interfaceProblem<TSState>- Parameters:
state- the state from which the transition originatesdecision- the decision to apply- Returns:
- the incremental objective cost/value associated with this decision
-
optimalValue
Description copied from interface:ProblemReturns 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:
optimalValuein interfaceProblem<TSState>- Returns:
- an
Optionalcontaining the known optimal value, or empty if unknown
-
evaluate
Description copied from interface:ProblemGiven a solution such thatsolution[i]is the value of the variablex_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:
evaluatein interfaceProblem<TSState>- Parameters:
solution- A solution of the problem.- Returns:
- The value of the input solution
- Throws:
InvalidSolutionException- If the solution does not respect problem's constraints.
-
sceneCost
public int sceneCost(int scene) -
onLocationActors
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
-
toString
-