Class PDPTWGenerator

java.lang.Object
org.ddolib.examples.layered.pdptw.PDPTWGenerator

public class PDPTWGenerator extends Object
Utility class for generating instances of the Pickup and Delivery Problem with time window (PDPTW) 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. Nodes also have an associated time window. If the vehicle comes too early, it has to wait. If the vehicle comes too late it is a violation.

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:
  • Method Details

    • genInstance

      public static PDPTWProblem genInstance(int n, int unrelated, int maxCapa, Random random, Boolean strengthenTimeWindows)
      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 instance
      unrelated - 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 vehicle
      random - a Random object used for generating coordinates
      strengthenTimeWindows - whether the generated time windows should be strengthened
      Returns:
      a PDPProblem instance representing the generated PDP
    • constructInstanceWithSolution

      public static PDPTWProblem constructInstanceWithSolution(int n, int unrelated, int maxCapa, Random random, Boolean strengthenTimeWindows)
      Generates a PDPTW instance. This method explicitly builds a valid optimal route (respecting capacity and precedence) before computing time windows, ensuring the optimal solution is exact and known.
      Parameters:
      n - total number of nodes
      unrelated - number of unrelated nodes
      maxCapa - maximum capacity of the vehicle
      random - random object for reproducibility
      strengthenTimeWindows - option to strengthen time windows
      Returns:
      the PDPTW problem instance
    • writeInstance

      public void writeInstance(String fileName, int n, int unrelated, int maxCapa, Random random) throws IOException
      Generates a PDPTW 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.
      • The tine window for each node.
      Parameters:
      fileName - the path to the output file
      n - the total number of nodes in the PDP instance
      unrelated - the number of nodes not involved in any pickup-delivery pair
      maxCapa - the maximum vehicle capacity
      random - a Random object used for generating coordinates
      Throws:
      IOException - if an I/O error occurs while writing the file