Package org.ddolib.examples.pdp
Class PDPGenerator
java.lang.Object
org.ddolib.examples.pdp.PDPGenerator
Utility class for generating instances of the Pickup and Delivery Problem (PDP)
with a single vehicle.
This generator creates a TSP-like problem where nodes are grouped into pickup-delivery pairs. In each pair, the pickup node must be visited before its associated delivery node. Additionally, the problem can include "unrelated nodes" that are not part of any pickup-delivery pair.
Features:
- Generates random coordinates for all nodes and computes Euclidean distances between them.
- Automatically creates pickup-delivery pairs based on the number of unrelated nodes.
- Supports defining a vehicle capacity for the PDP instance.
- Can write generated instances to a file in a human-readable format.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intdist(int dx, int dy) Computes the Euclidean distance between two points.static PDPProblemgenInstance(int n, int unrelated, int maxCapa, Random random) Generates a random PDP instance with the given parameters.voidwriteInstance(String fileName, int n, int unrelated, int maxCapa, Random random) Generates a PDP instance and writes it to a file in a human-readable format.
-
Constructor Details
-
PDPGenerator
public PDPGenerator()
-
-
Method Details
-
genInstance
Generates a random PDP instance with the given parameters.Nodes are grouped into pickup-delivery pairs. Any remaining nodes are treated as unrelated nodes. The distance between nodes is computed using Euclidean distance.
- Parameters:
n- the total number of nodes in the PDP instanceunrelated- the number of nodes that are not part of any pickup-delivery pair (there may be one more unrelated node than specified)maxCapa- the maximum capacity of the vehiclerandom- aRandomobject used for generating coordinates- Returns:
- a
PDPProbleminstance representing the generated PDP
-
dist
public static int dist(int dx, int dy) Computes the Euclidean distance between two points.- Parameters:
dx- the difference in x-coordinatesdy- the difference in y-coordinates- Returns:
- the Euclidean distance as an integer
-
writeInstance
public void writeInstance(String fileName, int n, int unrelated, int maxCapa, Random random) throws IOException Generates a PDP instance and writes it to a file in a human-readable format.The file includes:
- The total number of nodes.
- The distance matrix between all nodes.
- The mapping of pickup nodes to their associated delivery nodes.
- Parameters:
fileName- the path to the output filen- the total number of nodes in the PDP instanceunrelated- the number of nodes not involved in any pickup-delivery pairmaxCapa- the maximum vehicle capacityrandom- aRandomobject used for generating coordinates- Throws:
IOException- if an I/O error occurs while writing the file
-