Class PDPGenerator

java.lang.Object
org.ddolib.examples.pdp.PDPGenerator

public class PDPGenerator extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    dist(int dx, int dy)
    Computes the Euclidean distance between two points.
    static PDPProblem
    genInstance(int n, int unrelated, int maxCapa, Random random)
    Generates a random PDP instance with the given parameters.
    void
    writeInstance(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PDPGenerator

      public PDPGenerator()
  • Method Details

    • genInstance

      public static PDPProblem genInstance(int n, int unrelated, int maxCapa, Random random)
      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
      Returns:
      a PDPProblem instance 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-coordinates
      dy - 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 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