java.lang.Object
org.opentrafficsim.core.network.route.Route
All Implemented Interfaces:
Identifiable

public class Route extends Object implements Identifiable
A route is defined as a series of nodes. Each pair of consecutive nodes should have a link valid for the given direction and GTU type.

Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Constructor Details

    • Route

      public Route(String id, GtuType gtuType)
      Create an empty route for the given GtuType.
      Parameters:
      id - the name of the route
      gtuType - the GtuType for which this is a route
    • Route

      public Route(String id, GtuType gtuType, List<Node> nodes) throws NetworkException
      Create a route based on an initial list of nodes.
      This constructor makes a defensive copy of the provided List.
      Parameters:
      id - the name of the route.
      gtuType - the GtuType for which this is a route
      nodes - the initial list of nodes.
      Throws:
      NetworkException - if intermediate nodes are missing in the route.
  • Method Details

    • verify

      public void verify() throws NetworkException
      Verify that there are normal (non Connectors) between adjacent nodes, except at start and end (where Connectors are OK.
      Throws:
      NetworkException - checks links between adjacent nodes.
    • addNode

      public final Route addNode(Node node) throws NetworkException
      Add a node to the end of the node list.
      Parameters:
      node - the node to add.
      Returns:
      this route for method chaining
      Throws:
      NetworkException - in case node could not be added to the route.
    • getNodes

      public final List<Node> getNodes()
      Returns nodes.
      Returns:
      nodes.
    • getNode

      public final Node getNode(int i) throws NetworkException
      Returns node at index.
      Parameters:
      i - the index of the node to obtain
      Returns:
      node i.
      Throws:
      NetworkException - if i < 0 or i > size
    • originNode

      public final Node originNode() throws NetworkException
      Returns origin node.
      Returns:
      the first node of the route.
      Throws:
      NetworkException - when the list has no nodes.
    • size

      public final int size()
      Returns size.
      Returns:
      the number of nodes in the list. If the list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
    • destinationNode

      public final Node destinationNode() throws NetworkException
      Returns destination node.
      Returns:
      the last node of the route.
      Throws:
      NetworkException - when the list has no nodes.
    • indexOf

      public final int indexOf(Node node)
      Return the index of a Node in this Route, or -1 if this Route does not contain the specified Node.
      If this route contains the Node more than once, the index of the first is returned.
      Parameters:
      node - the Node to find
      Returns:
      returns index of node.
    • contains

      public final boolean contains(Node node)
      Returns whether the node is contained.
      Parameters:
      node - the Node to find
      Returns:
      whether the route contains this node (quick using LinkedHashSet);
    • getId

      public final String getId()
      Specified by:
      getId in interface Identifiable
      Returns:
      name.
    • containsLink

      public final boolean containsLink(Link link)
      Determine if this Route contains the specified Link.
      Parameters:
      link - the link to check in the route.
      Returns:
      whether the link is part of the route or not.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object