Interface Network

All Superinterfaces:
Definitions, EventProducerInterface, Identifiable
All Known Implementing Classes:
ExpansionNetwork, OTSNetwork

public interface Network
extends Definitions, EventProducerInterface, Identifiable
Interface that defines what information a network should be able to provide about Nodes, Links and Routes.

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

$LastChangedDate: 2019-03-17 22:16:44 +0100 (Sun, 17 Mar 2019) $, @version $Revision: 5158 $, by $Author: averbraeck $, initial version Jul 22, 2015

Author:
Alexander Verbraeck, Peter Knoppers, Guus Tamminga
  • Field Details

    • ANIMATION_NODE_ADD_EVENT

      static final EventType ANIMATION_NODE_ADD_EVENT
      The timed event type for pub/sub indicating the addition of a Node.
      Payload: Node node (not an array, just an Object)
    • ANIMATION_NODE_REMOVE_EVENT

      static final EventType ANIMATION_NODE_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of a Node.
      Payload: Node node (not an array, just an Object)
    • ANIMATION_LINK_ADD_EVENT

      static final EventType ANIMATION_LINK_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of a Link.
      Payload: Link link (not an array, just an Object)
    • ANIMATION_LINK_REMOVE_EVENT

      static final EventType ANIMATION_LINK_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of a Link.
      Payload: Link link (not an array, just an Object)
    • ANIMATION_OBJECT_ADD_EVENT

      static final EventType ANIMATION_OBJECT_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of an ObjectInterface implementing object.
      Payload: StaticObject object (not an array, just an Object)
    • ANIMATION_OBJECT_REMOVE_EVENT

      static final EventType ANIMATION_OBJECT_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of an ObjectInterface implementing object.
      Payload: StaticObject object (not an array, just an Object)
    • ANIMATION_INVISIBLE_OBJECT_ADD_EVENT

      static final EventType ANIMATION_INVISIBLE_OBJECT_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of an InvisibleObjectInterface implementing object.
      Payload: InvisibleObject object (not an array, just an Object)
    • ANIMATION_INVISIBLE_OBJECT_REMOVE_EVENT

      static final EventType ANIMATION_INVISIBLE_OBJECT_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of an InvisibleObjectInterface implementing object.
      Payload: InvisibleObject object (not an array, just an Object)
    • ANIMATION_ROUTE_ADD_EVENT

      static final EventType ANIMATION_ROUTE_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of a Route for a gtuType.
      Payload: [GTUType gtuType, Route route]
    • ANIMATION_ROUTE_REMOVE_EVENT

      static final EventType ANIMATION_ROUTE_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of a Route for a gtuType.
      Payload: [GTUType gtuType, Route route]
    • ANIMATION_GTU_ADD_EVENT

      static final EventType ANIMATION_GTU_ADD_EVENT
      The timed event type for pub/sub indicating the addition of a GTU to the network.
      Payload: GTU gtu (not an array, just an Object)
    • ANIMATION_GTU_REMOVE_EVENT

      static final EventType ANIMATION_GTU_REMOVE_EVENT
      The timed event type for pub/sub indicating the removal of a GTU from the network.
      Payload: GTU gtu (not an array, just an Object)
    • ANIMATION_GENERATOR_ADD_EVENT

      static final EventType ANIMATION_GENERATOR_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of an GTUGenerator implementing object.
      Payload: AbstractGTUGenerator object (not an array, just an Object)
    • ANIMATION_GENERATOR_REMOVE_EVENT

      static final EventType ANIMATION_GENERATOR_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of an GTUGenerator implementing object.
      Payload: AbstractGTUGenerator object (not an array, just an Object)
    • NODE_ADD_EVENT

      static final EventType NODE_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of a Node.
      Payload: String nodeId (not an array, just a String)
    • NODE_REMOVE_EVENT

      static final EventType NODE_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of a Node.
      Payload: String nodeId (not an array, just a String)
    • LINK_ADD_EVENT

      static final EventType LINK_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of a Link.
      Payload: String linkId (not an array, just a String)
    • LINK_REMOVE_EVENT

      static final EventType LINK_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of a Link.
      Payload: String linkId (not an array, just a String)
    • OBJECT_ADD_EVENT

      static final EventType OBJECT_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of an ObjectInterface implementing object.
      Payload: String ObjectId (not an array, just a String)
    • OBJECT_REMOVE_EVENT

      static final EventType OBJECT_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of an ObjectInterface implementing object.
      Payload: String objectId (not an array, just a String)
    • INVISIBLE_OBJECT_ADD_EVENT

      static final EventType INVISIBLE_OBJECT_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of an InvisibleObjectInterface implementing object.
      Payload: String ObjectId (not an array, just a String)
    • INVISIBLE_OBJECT_REMOVE_EVENT

      static final EventType INVISIBLE_OBJECT_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of an InvisibleObjectInterface implementing object.
      Payload: String objectId (not an array, just a String)
    • ROUTE_ADD_EVENT

      static final EventType ROUTE_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of a Route for a gtuType.
      Payload: [String gtuTypeId, String routeId]
    • ROUTE_REMOVE_EVENT

      static final EventType ROUTE_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of a Route for a gtuType.
      Payload: [String gtuTypeId, String routeId]
    • GTU_ADD_EVENT

      static final EventType GTU_ADD_EVENT
      The timed event type for pub/sub indicating the addition of a GTU to the network.
      Payload: String gtuId (not an array, just a String)
    • GTU_REMOVE_EVENT

      static final EventType GTU_REMOVE_EVENT
      The timed event type for pub/sub indicating the removal of a GTU from the network.
      Payload: String gtuId (not an array, just a String)
    • GENERATOR_ADD_EVENT

      static final EventType GENERATOR_ADD_EVENT
      The timed event type for pub/sub indicating the addition of a GTUGenerator to the network.
      Payload: String generatorName (not an array, just a String)
    • GENERATOR_REMOVE_EVENT

      static final EventType GENERATOR_REMOVE_EVENT
      The timed event type for pub/sub indicating the removal of a GTUGenerator from the network.
      Payload: String generatorName (not an array, just a String)
  • Method Details

    • getId

      String getId()
      Specified by:
      getId in interface Identifiable
      Returns:
      String; the id
    • getNodeMap

      ImmutableMap<String,​Node> getNodeMap()
      Provide an immutable map of node ids to nodes in the network.
      Returns:
      an immutable map of nodes.
    • addNode

      void addNode​(Node node) throws NetworkException
      Register a node in the network.
      Parameters:
      node - Node; the node to add to the network.
      Throws:
      NetworkException - if node already exists in the network, or if name of the node is not unique.
    • removeNode

      void removeNode​(Node node) throws NetworkException
      Unregister a node from the network.
      Parameters:
      node - Node; the node to remove from the network.
      Throws:
      NetworkException - if node does not exist in the network.
    • containsNode

      boolean containsNode​(Node node)
      Test whether a node is present in the network.
      Parameters:
      node - Node; the node to search for in the network.
      Returns:
      whether the node is in this network
    • containsNode

      boolean containsNode​(String nodeId)
      Test whether a node with a given id is present in the network.
      Parameters:
      nodeId - String; the id of the node to search for in the network.
      Returns:
      whether the node is in this network
    • getNode

      Node getNode​(String nodeId)
      Retrieve a node with a given id from the network, or null if the id cannot be found.
      Parameters:
      nodeId - String; the id of the node to search for in the network.
      Returns:
      the node or null if not present
    • getLinkMap

      ImmutableMap<String,​Link> getLinkMap()
      Provide an immutable map of link ids to links in the network.
      Returns:
      the an immutable map of links.
    • addLink

      void addLink​(Link link) throws NetworkException
      Register a link in the network.
      Parameters:
      link - Link; the link to add to the network.
      Throws:
      NetworkException - if link already exists in the network, if name of the link is not unique, or if the start node or the end node of the link are not registered in the network.
    • removeLink

      void removeLink​(Link link) throws NetworkException
      Unregister a link from the network.
      Parameters:
      link - Link; the link to remove from the network.
      Throws:
      NetworkException - if link does not exist in the network.
    • containsLink

      boolean containsLink​(Link link)
      Test whether a link is present in the network.
      Parameters:
      link - Link; the link to search for in the network.
      Returns:
      whether the link is in this network
    • containsLink

      boolean containsLink​(String link)
      Test whether a link with a given id is present in the network.
      Parameters:
      link - String; the id of the link to search for in the network.
      Returns:
      whether the link is in this network
    • getLink

      Link getLink​(String linkId)
      Retrieve a node with a given id from the network, or null if the id cannot be found.
      Parameters:
      linkId - String; the id of the link to search for in the network.
      Returns:
      the link or null if not present
    • getLink

      Link getLink​(Node node1, Node node2)
      Find a link between node1 and node2 and return it if it exists in the network. If not, return null.
      Parameters:
      node1 - Node; first node
      node2 - Node; second node
      Returns:
      the link between node1 and node2 in the network or null if it does not exist.
    • getLink

      Link getLink​(String nodeId1, String nodeId2) throws NetworkException
      Find a link between node1 and node2 and return it if it exists in the network. If not, return null.
      Parameters:
      nodeId1 - String; id of the first node
      nodeId2 - String; id of the second node
      Returns:
      the link between node1 and node2 in the network or null if it does not exist.
      Throws:
      NetworkException - if the node(s) cannot be found by their id
    • getObjectMap

      ImmutableMap<String,​ObjectInterface> getObjectMap()
      Return an immutable map of all ObjectInterface implementing objects in the Network.
      Returns:
      ImmutableMap<String, ObjectInterface>; the immutable map of all ObjectInterface implementing objects in the Network
    • getObjectMap

      <T extends ObjectInterface> ImmutableMap<String,​T> getObjectMap​(Class<T> objectType)
      Return an immutable map of all ObjectInterface implementing objects in the network that are of type objectType, or any sub type thereof.
      Type Parameters:
      T - type of object
      Parameters:
      objectType - Class<T>; the (sub-)type of ObjectInterface that the returned map is reduced to
      Returns:
      ImmutableMap<String, ObjectInterface>; the immutable map of all ObjectInterface implementing objects in the Network that are of the type objectType, or any sub type thereof
    • getObject

      <T extends ObjectInterface> T getObject​(Class<T> objectType, String objectId)
      Return object of given type with given id.
      Type Parameters:
      T - object type
      Parameters:
      objectType - T; object type class
      objectId - String; id of object
      Returns:
      T; object of given type with given id, null if no such object
    • addObject

      void addObject​(ObjectInterface object) throws NetworkException
      Add an ObjectInterface implementing object to the Network.
      Parameters:
      object - ObjectInterface; the object that implements ObjectInterface
      Throws:
      NetworkException - if link already exists in the network, if name of the object is not unique.
    • removeObject

      void removeObject​(ObjectInterface object) throws NetworkException
      Remove an ObjectInterface implementing object form the Network.
      Parameters:
      object - ObjectInterface; the object that implements ObjectInterface
      Throws:
      NetworkException - if the object does not exist in the network.
    • containsObject

      boolean containsObject​(ObjectInterface object)
      Test whether the object is present in the Network.
      Parameters:
      object - ObjectInterface; the object that is tested for presence
      Returns:
      boolean; whether the object is present in the Network
    • containsObject

      boolean containsObject​(String objectId)
      Test whether an object with the given id is present in the Network.
      Parameters:
      objectId - String; the id that is tested for presence
      Returns:
      boolean; whether an object with the given id is present in the Network
    • getInvisibleObjectMap

      ImmutableMap<String,​InvisibleObjectInterface> getInvisibleObjectMap()
      Return an immutable map of all InvisibleObject implementing objects in the Network.
      Returns:
      ImmutableMap<String, ObjectInterface>; the immutable map of all ObjectInterface implementing objects in the Network
    • getInvisibleObjectMap

      ImmutableMap<String,​InvisibleObjectInterface> getInvisibleObjectMap​(Class<InvisibleObjectInterface> objectType)
      Return an immutable map of all InvisibleObject implementing objects in the network that are of type objectType, or any sub type thereof.
      Parameters:
      objectType - Class<InvisibleObjectInterface>; the (sub-)type of InvisibleObject that the returned map is reduced to
      Returns:
      ImmutableMap<String, InvisibleObject>; the immutable map of all InvisibleObject implementing objects in the Network that are of the type objectType, or any sub type thereof
    • addInvisibleObject

      void addInvisibleObject​(InvisibleObjectInterface object) throws NetworkException
      Add an ObjectInterface implementing object to the Network.
      Parameters:
      object - InvisibleObjectInterface; the object that implements ObjectInterface
      Throws:
      NetworkException - if link already exists in the network, if name of the object is not unique.
    • removeInvisibleObject

      void removeInvisibleObject​(InvisibleObjectInterface object) throws NetworkException
      Remove an ObjectInterface implementing object form the Network.
      Parameters:
      object - InvisibleObjectInterface; the object that implements ObjectInterface
      Throws:
      NetworkException - if the object does not exist in the network.
    • containsInvisibleObject

      boolean containsInvisibleObject​(InvisibleObjectInterface object)
      Test whether the invisible object is present in the Network.
      Parameters:
      object - InvisibleObjectInterface; the object that is tested for presence
      Returns:
      boolean; whether the invisible object is present in the Network
    • containsInvisibleObject

      boolean containsInvisibleObject​(String objectId)
      Test whether an invisible object with the given id is present in the Network.
      Parameters:
      objectId - String; the id that is tested for presence
      Returns:
      boolean; whether an invisible object with the given id is present in the Network
    • getDefinedRouteMap

      ImmutableMap<String,​Route> getDefinedRouteMap​(GTUType gtuType)
      Return an immutable map of routes that exist in the network for the GTUType.
      Parameters:
      gtuType - GTUType; the GTUType for which to retrieve the defined routes
      Returns:
      an immutable map of routes in the network for the given GTUType, or an empty Map if no routes are defined for the given GTUType.
    • addRoute

      void addRoute​(GTUType gtuType, Route route) throws NetworkException
      Add a route to the network.
      Parameters:
      gtuType - GTUType; the GTUType for which to add a route
      route - Route; the route to add to the network.
      Throws:
      NetworkException - if route already exists in the network, if name of the route is not unique, if one of the nodes of the route are not registered in the network.
    • removeRoute

      void removeRoute​(GTUType gtuType, Route route) throws NetworkException
      Remove the route from the network, e.g. because of road maintenance.
      Parameters:
      gtuType - GTUType; the GTUType for which to remove a route
      route - Route; the route to remove from the network.
      Throws:
      NetworkException - if route does not exist in the network.
    • getRoute

      Route getRoute​(GTUType gtuType, String routeId)
      Return the route with the given id in the network for the given GTUType, or null if it the route with the id does not exist.
      Parameters:
      gtuType - GTUType; the GTUType for which to retrieve a route based on its id.
      routeId - String; the route to search for in the network.
      Returns:
      the route or null if not present
    • containsRoute

      boolean containsRoute​(GTUType gtuType, Route route)
      Determine whether the provided route exists in the network for the given GTUType.
      Parameters:
      gtuType - GTUType; the GTUType for which to check whether the route exists
      route - Route; the route to check for
      Returns:
      whether the route exists in the network for the given GTUType
    • containsRoute

      boolean containsRoute​(GTUType gtuType, String routeId)
      Determine whether a route with the given id exists in the network for the given GTUType.
      Parameters:
      gtuType - GTUType; the GTUType for which to check whether the route exists
      routeId - String; the id of the route to check for
      Returns:
      whether a route with the given id exists in the network for the given GTUType
    • getRoutesBetween

      Set<Route> getRoutesBetween​(GTUType gtuType, Node nodeFrom, Node nodeTo)
      Return the the shortest route between two nodes in the network, via a list of intermediate nodes. If no path exists from the start node to the end node via the intermediate nodes in the network, null is returned.
      Parameters:
      gtuType - GTUType; the GTUType for which to retrieve the defined routes
      nodeFrom - Node; the start node.
      nodeTo - Node; the end node.
      Returns:
      a set with routes from the start Node to the end Node in the network; if no route can be found, an empty set is returned.
    • buildGraph

      void buildGraph​(GTUType gtuType)
      (Re)build the underlying graph for the given GTUType.
      Parameters:
      gtuType - GTUType; the GTUType for which to (re)build the graph
    • getShortestRouteBetween

      default CompleteRoute getShortestRouteBetween​(GTUType gtuType, Node nodeFrom, Node nodeTo) throws NetworkException
      Calculate the shortest route between two nodes in the network. If no path exists from the start node to the end node in the network, null is returned. This method returns a CompleteRoute, which includes all nodes to get from start to end. In case the graph for the GTUType has not yet been built, this method will call the buildGraph method.
      Parameters:
      gtuType - GTUType; the GTUType for which to calculate the shortest route
      nodeFrom - Node; the start node.
      nodeTo - Node; the end node.
      Returns:
      the shortest route from the start Node to the end Node in the network. If no path exists from the start node to the end node in the network, null is returned.
      Throws:
      NetworkException - in case nodes cannot be added to the route, e.g. because they are not directly connected. This can be the case when the links in the network have changed, but the graph has not been rebuilt.
    • getShortestRouteBetween

      CompleteRoute getShortestRouteBetween​(GTUType gtuType, Node nodeFrom, Node nodeTo, LinkWeight linkWeight) throws NetworkException
      Calculate the shortest route between two nodes in the network. If no path exists from the start node to the end node in the network, null is returned. This method returns a CompleteRoute, which includes all nodes to get from start to end. This method recalculates the graph.
      Parameters:
      gtuType - GTUType; the GTUType for which to calculate the shortest route
      nodeFrom - Node; the start node.
      nodeTo - Node; the end node.
      linkWeight - LinkWeight; link weight.
      Returns:
      the shortest route from the start Node to the end Node in the network. If no path exists from the start node to the end node in the network, null is returned.
      Throws:
      NetworkException - in case nodes cannot be added to the route, e.g. because they are not directly connected. This can be the case when the links in the network have changed, but the graph has not been rebuilt.
    • getShortestRouteBetween

      default CompleteRoute getShortestRouteBetween​(GTUType gtuType, Node nodeFrom, Node nodeTo, List<Node> nodesVia) throws NetworkException
      Calculate the shortest route between two nodes in the network, via a list of intermediate nodes. If no path exists from the start node to the end node via the intermediate nodes in the network, null is returned. This method returns a CompleteRoute, which includes all nodes to get from start to end. In case the graph for the GTUType has not yet been built, this method will call the buildGraph method.
      Parameters:
      gtuType - GTUType; the GTUType for which to calculate the shortest route
      nodeFrom - Node; the start node.
      nodeTo - Node; the end node.
      nodesVia - List<Node>; a number of nodes that the GTU has to pass between nodeFrom and nodeTo in the given order.
      Returns:
      the shortest route between two nodes in the network, via the intermediate nodes. If no path exists from the start node to the end node via the intermediate nodes in the network, null is returned.
      Throws:
      NetworkException - in case nodes cannot be added to the route, e.g. because they are not directly connected. This can be the case when the links in the network have changed, but the graph has not been rebuilt.
    • getShortestRouteBetween

      CompleteRoute getShortestRouteBetween​(GTUType gtuType, Node nodeFrom, Node nodeTo, List<Node> nodesVia, LinkWeight linkWeight) throws NetworkException
      Calculate the shortest route between two nodes in the network, via a list of intermediate nodes. If no path exists from the start node to the end node via the intermediate nodes in the network, null is returned. This method returns a CompleteRoute, which includes all nodes to get from start to end. This method recalculates the graph.
      Parameters:
      gtuType - GTUType; the GTUType for which to calculate the shortest route
      nodeFrom - Node; the start node.
      nodeTo - Node; the end node.
      nodesVia - List<Node>; a number of nodes that the GTU has to pass between nodeFrom and nodeTo in the given order.
      linkWeight - LinkWeight; link weight.
      Returns:
      the shortest route between two nodes in the network, via the intermediate nodes. If no path exists from the start node to the end node via the intermediate nodes in the network, null is returned.
      Throws:
      NetworkException - in case nodes cannot be added to the route, e.g. because they are not directly connected. This can be the case when the links in the network have changed, but the graph has not been rebuilt.