Class PDPTWProblem
java.lang.Object
org.ddolib.examples.layered.pdptw.PDPTWProblem
- All Implemented Interfaces:
Problem<PDPTWState>
Represents a Pickup and Delivery Problem (PDP) instance with a single vehicle.
In this problem:
- Nodes may be grouped into pickup-delivery pairs, where a pickup node must be visited before its associated delivery node.
- There may also be unrelated nodes that are not part of any pair.
- The vehicle has a capacity limit that restricts how many pickups can be carried simultaneously.
- The problem is represented as a TSP-like graph with distances between nodes.
The class implements the Problem interface, providing methods for:
- Number of variables
nbVars() - Initial state
initialState() - Transition function
transition(PDPTWState, Decision) - Transition cost
transitionCost(PDPTWState, Decision) - Domain of possible decisions
domain(PDPTWState, int)
States are represented by PDPTWState, including:
- The set of currently visited nodes
- The set of nodes still to visit
- The current vehicle load
-
Field Summary
FieldsModifier and TypeFieldDescriptionMap of delivery nodes to their associated pickup nodes.final intMaximum capacity of the vehicle.final intNumber of nodes in the problem.Map of pickup nodes to their associated delivery nodes.final double[][]Distance matrix between all nodes.final TimeWindow[]Time window associated to each node.Set of nodes that are not part of any pickup-delivery pair. -
Constructor Summary
ConstructorsConstructorDescriptionPDPTWProblem(double[][] timeMatrix, HashMap<Integer, Integer> pickupToAssociatedDelivery, int maxCapa, TimeWindow[] timeWindows, Optional<Double> knownSolutionValue, Boolean strengthenTimeWindows) Constructs a PDPTWProblem from a distance matrix, a map of pickup-delivery pairs, and a maximum vehicle capacity.PDPTWProblem(String fname) Constructs a PDPProblem by reading an instance from a file. -
Method Summary
Modifier and TypeMethodDescriptiondomain(PDPTWState state, int var) Returns 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()Returns the number of variables (decisions) in the problem.Returns the known optimal value of the problem, if available.voidsaveToFile(String fname) Saves this PDPTW instance to a file in the format expected byPDPTWProblem(String).singleton(int singletonValue) Builds a singletonBitSetcontaining only the given value.voidStrengthens the time windows of pickup and delivery nodes using the precedence and travel time relations between each pickup and its associated delivery.toString()transition(PDPTWState state, Decision decision) Applies a decision to a state, computing the next state according to the problem's transition function.doubletransitionCost(PDPTWState 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, waitMethods inherited from interface org.ddolib.layered.modeling.Problem
hasNonNegativeCosts
-
Field Details
-
n
public final int nNumber of nodes in the problem. -
timeMatrix
public final double[][] timeMatrixDistance matrix between all nodes. -
maxCapa
public final int maxCapaMaximum capacity of the vehicle. -
pickupToAssociatedDelivery
Map of pickup nodes to their associated delivery nodes. -
deliveryToAssociatedPickup
Map of delivery nodes to their associated pickup nodes. -
timeWindows
Time window associated to each node.
-
-
Constructor Details
-
PDPTWProblem
public PDPTWProblem(double[][] timeMatrix, HashMap<Integer, Integer> pickupToAssociatedDelivery, int maxCapa, TimeWindow[] timeWindows, Optional<Double> knownSolutionValue, Boolean strengthenTimeWindows) Constructs a PDPTWProblem from a distance matrix, a map of pickup-delivery pairs, and a maximum vehicle capacity.- Parameters:
timeMatrix- distance matrix between all nodespickupToAssociatedDelivery- mapping from pickup nodes to delivery nodesmaxCapa- maximum capacity of the vehicletimeWindows- the time window associated to each nodeknownSolutionValue- an optional known solution value of the instancestrengthenTimeWindows- whether the time windows should be strengthened at construction time
-
PDPTWProblem
Constructs a PDPProblem by reading an instance from a file.The file format should include:
- The number of nodes and optionally the optimal value.
- The distance matrix between nodes.
- The pickup-delivery pairs.
- Parameters:
fname- path to the instance file- Throws:
IOException- if the file cannot be read
-
-
Method Details
-
strengthenTimeWindows
public void strengthenTimeWindows()Strengthens the time windows of pickup and delivery nodes using the precedence and travel time relations between each pickup and its associated delivery. -
saveToFile
Saves this PDPTW instance to a file in the format expected byPDPTWProblem(String).- Parameters:
fname- the path to the output file- Throws:
IOException- if an I/O error occurs while writing the file
-
nbVars
public int nbVars()Returns the number of variables (decisions) in the problem.Note: the last decision corresponds to returning to the depot (node 0).
- Specified by:
nbVarsin interfaceProblem<PDPTWState>- Returns:
- number of variables
-
initialState
Description copied from interface:ProblemReturns the initial state of the problem.- Specified by:
initialStatein interfaceProblem<PDPTWState>- Returns:
- the state representing the starting point of the optimization
-
singleton
Builds a singletonBitSetcontaining only the given value.- Parameters:
singletonValue- the value to set in the returned set- Returns:
- a new
BitSetwith onlysingletonValueset
-
initialValue
public double initialValue()Description copied from interface:ProblemReturns the initial objective value associated with the initial state.- Specified by:
initialValuein interfaceProblem<PDPTWState>- Returns:
- the starting value of the objective function
-
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<PDPTWState>- Returns:
- an
Optionalcontaining the known optimal value, or empty if unknown
-
domain
Description copied from interface:ProblemReturns the domain of possible values for a given variable when applied to a specific state.- Specified by:
domainin interfaceProblem<PDPTWState>- Parameters:
state- the current statevar- the variable index whose domain is queried- Returns:
- an iterator over all feasible values for the variable in this 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<PDPTWState>- 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<PDPTWState>- Parameters:
state- the state from which the transition originatesdecision- the decision to apply- Returns:
- the incremental objective cost/value associated with this decision
-
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<PDPTWState>- 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
-
toString
-