Package org.opentrafficsim.core.network
Class OTSNetwork
- java.lang.Object
-
- org.djutils.event.EventProducer
-
- org.opentrafficsim.core.network.OTSNetwork
-
- All Implemented Interfaces:
Serializable,EventProducerInterface,Identifiable,Definitions,Network,PerceivableContext
- Direct Known Subclasses:
ExpansionNetwork
public class OTSNetwork extends EventProducer implements Network, PerceivableContext, Serializable
An OTSNetwork consists of a set of Nodes, Links, Objects, etc..Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
$LastChangedDate: 2020-05-14 13:12:03 +0200 (Thu, 14 May 2020) $, @version $Revision: 6470 $, by $Author: pknoppers $, initial version Jul 22, 2015
BSD-style license. See OpenTrafficSim License.- Author:
- Alexander Verbraeck, Peter Knoppers, Guus Tamminga
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static doubleEXTENT_MARGINExtra clearance around boundaries of network as fraction of width and height.-
Fields inherited from class org.djutils.event.EventProducer
eventProducerImpl
-
Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION
-
Fields inherited from interface org.opentrafficsim.core.network.Network
ANIMATION_GENERATOR_ADD_EVENT, ANIMATION_GENERATOR_REMOVE_EVENT, ANIMATION_GTU_ADD_EVENT, ANIMATION_GTU_REMOVE_EVENT, ANIMATION_INVISIBLE_OBJECT_ADD_EVENT, ANIMATION_INVISIBLE_OBJECT_REMOVE_EVENT, ANIMATION_LINK_ADD_EVENT, ANIMATION_LINK_REMOVE_EVENT, ANIMATION_NODE_ADD_EVENT, ANIMATION_NODE_REMOVE_EVENT, ANIMATION_OBJECT_ADD_EVENT, ANIMATION_OBJECT_REMOVE_EVENT, ANIMATION_ROUTE_ADD_EVENT, ANIMATION_ROUTE_REMOVE_EVENT, GENERATOR_ADD_EVENT, GENERATOR_REMOVE_EVENT, GTU_ADD_EVENT, GTU_REMOVE_EVENT, INVISIBLE_OBJECT_ADD_EVENT, INVISIBLE_OBJECT_REMOVE_EVENT, LINK_ADD_EVENT, LINK_REMOVE_EVENT, NODE_ADD_EVENT, NODE_REMOVE_EVENT, OBJECT_ADD_EVENT, OBJECT_REMOVE_EVENT, ROUTE_ADD_EVENT, ROUTE_REMOVE_EVENT
-
-
Constructor Summary
Constructors Constructor Description OTSNetwork(String id, boolean addDefaultTypes, OTSSimulatorInterface simulator)Construction of an empty OTSNetwork.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDefaultGtuTypes()Add the default GTU Types that have been defined in the enum GTUType.DEFAULTS to the network.voidaddDefaultLinkTypes()Add the default LinkTypes that have been defined in the enum LinkType.DEFAULTS to the network.voidaddGtu(Gtu gtu)Add a GTU to this PerceivableContext.voidaddGtuType(GtuType gtuType)Add a GTU type to the map.voidaddInvisibleObject(InvisibleObjectInterface object)Add an ObjectInterface implementing object to this Network.voidaddLink(Link link)Register a link in this Network.voidaddLinkType(LinkType linkType)Add a Link type to the map.voidaddNode(Node node)Register a node in this Network.voidaddObject(ObjectInterface object)Add an ObjectInterface implementing object to this Network.voidaddRoute(GtuType gtuType, Route route)Add a route to this Network.voidbuildGraph(GtuType gtuType)(Re)build the underlying graph for the given GTUType.booleancontainsGtu(Gtu gtu)Test whether a GTU is registered in this PerceivableContext.booleancontainsGtuId(String gtuId)Test whether a GTU with a specific id is registered in this PerceivableContext.booleancontainsInvisibleObject(String objectId)Test whether an invisible object with the given id is present in this Network.booleancontainsInvisibleObject(InvisibleObjectInterface object)Test whether the invisible object is present in this Network.booleancontainsLink(String linkId)Test whether a link with a given id is present in this Network.booleancontainsLink(Link link)Test whether a link is present in this Network.booleancontainsNode(String nodeId)Test whether a node with a given id is present in this Network.booleancontainsNode(Node node)Test whether a node is present in this Network.booleancontainsObject(String objectId)Test whether an object with the given id is present in this Network.booleancontainsObject(ObjectInterface object)Test whether the object is present in this Network.booleancontainsRoute(GtuType gtuType, String routeId)Determine whether a route with the given id exists in this Network for the given GTUType.booleancontainsRoute(GtuType gtuType, Route route)Determine whether the provided route exists in this Network for the given GTUType.Iterator<ObjectInterface>findObjects(Bounds3d bounds)Construct an Iterator<ObjectInterface> that will yield all ObjectInterface objects with Bounds that intersect the given Bounds3d.ImmutableMap<String,Route>getDefinedRouteMap(GtuType gtuType)Return an immutable map of routes that exist in this Network for the GTUType.Bounds2dgetExtent()Calculate the extent of the network based on the network objects' locations and return the dimensions.GtugetGtu(String gtuId)Retrieve a GTU with a specific id from this PerceivableContext.Set<Gtu>getGtus()Get an overview of the GTUs in the model.GtuTypegetGtuType(String gtuId)Retrieve a defined GTUType based on its id.GtuTypegetGtuType(GtuType.DEFAULTS gtuEnum)Retrieve a defined default GTUType based on its enum.ImmutableMap<String,GtuType>getGtuTypes()Retrieve a safe copy of the map of defined GTUTypes in this network.StringgetId()Get a descriptive Id of this PerceivableContext (useful for debugging purposes).ImmutableMap<String,InvisibleObjectInterface>getInvisibleObjectMap()Return an immutable map of all InvisibleObject implementing objects in this Network.ImmutableMap<String,InvisibleObjectInterface>getInvisibleObjectMap(Class<InvisibleObjectInterface> objectType)Return an immutable map of all InvisibleObject implementing objects in this Network that are of type objectType, or any sub type thereof.LinkgetLink(String linkId)Retrieve a node with a given id from this Network, or null if the id cannot be found.LinkgetLink(String nodeId1, String nodeId2)Find a link between node1 and node2 and return it if it exists in this Network.LinkgetLink(Node node1, Node node2)Find a link between node1 and node2 and return it if it exists in this Network.ImmutableMap<GtuType,org.jgrapht.graph.SimpleDirectedWeightedGraph<Node,LinkEdge<Link>>>getLinkGraphs()Get an immutable graph map.ImmutableMap<String,Link>getLinkMap()Provide an immutable map of link ids to links in this Network.LinkTypegetLinkType(String linkId)Retrieve a defined LinkType based on its id.LinkTypegetLinkType(LinkType.DEFAULTS linkEnum)Retrieve a defined default LinkType based on its enum.ImmutableMap<String,LinkType>getLinkTypes()Retrieve a safe copy of the map of defined LinkTypes in this network.NodegetNode(String nodeId)Retrieve a node with a given id from this Network, or null if the id cannot be found.ImmutableMap<String,Node>getNodeMap()Return an immutable map of node ids to nodes in this Network.longgetNumberOfObjects()Report how many ObjectInterface objects have been registered (the result includes objects that have subsequently been removed).<T extends ObjectInterface>
TgetObject(Class<T> objectType, String objectId)Retrieve the object of a specific type with a specific id.ImmutableMap<String,ObjectInterface>getObjectMap()Return an immutable map of all ObjectInterface implementing objects in this Network.<T extends ObjectInterface>
ImmutableMap<String,T>getObjectMap(Class<T> objectType)Return an immutable map of all ObjectInterface implementing objects in this Network that are of type objectType, or any sub type thereof.RoutegetRoute(String routeId)Retrieve the route with a specific id ornullif no such route is known in this OTSNetwork.RoutegetRoute(GtuType gtuType, String routeId)Return the route with a specific id for a specific GTUType, or null if no route with that id for that GTUType exists in this Network.ImmutableMap<GtuType,Map<String,Route>>getRouteMap()Get an immutable route map.Set<Route>getRoutesBetween(GtuType gtuType, Node nodeFrom, Node nodeTo)Return the the shortest route for a specific GTUType between two nodes in this Network, via a list of intermediate nodes.CompleteRoutegetShortestRouteBetween(GtuType gtuType, Node nodeFrom, Node nodeTo, List<Node> nodesVia)Calculate the shortest route between two nodes in this Network, via a list of intermediate nodes.CompleteRoutegetShortestRouteBetween(GtuType gtuType, Node nodeFrom, Node nodeTo, List<Node> nodesVia, LinkWeight linkWeight)Calculate the shortest route between two nodes in this Network, via a list of intermediate nodes.CompleteRoutegetShortestRouteBetween(GtuType gtuType, Node nodeFrom, Node nodeTo, LinkWeight linkWeight)Calculate the shortest route between two nodes in this Network.OTSSimulatorInterfacegetSimulator()Retrieve the simulator.SerializablegetSourceId()List<Node>getUnbalancedCentroids(GtuType gtuType)Return a list of Centroid nodes that have incoming connectors without corresponding outgoing connectors to the same node or vice versa (which can be fully okay, especially when the lanes are a dead end, or when lanes / links only go in a single direction).voidremoveGtu(Gtu gtu)Remove a GTU from this PerceivableContext.voidremoveInvisibleObject(InvisibleObjectInterface object)Remove an ObjectInterface implementing object form this Network.voidremoveLink(Link link)Unregister a link from this Network.voidremoveNode(Node node)Unregister a node from this Network.voidremoveObject(ObjectInterface object)Remove an ObjectInterface implementing object form this Network.voidremoveRoute(GtuType gtuType, Route route)Remove the route from this Network, e.g.voidsetRawRouteMap(Map<GtuType,Map<String,Route>> newRouteMap)Replace the internal Route Map.StringtoString()-
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.event.EventProducerInterface
addListener, addListener, addListener, addListener, getEventTypesWithListeners, hasListeners, numberOfListeners, removeListener
-
Methods inherited from interface org.opentrafficsim.core.network.Network
getShortestRouteBetween
-
-
-
-
Constructor Detail
-
OTSNetwork
public OTSNetwork(String id, boolean addDefaultTypes, OTSSimulatorInterface simulator)
Construction of an empty OTSNetwork.- Parameters:
id- String; the network id.addDefaultTypes- boolean; add the default GTUTypes and LinkTypes, or notsimulator- OTSSimulatorInterface; the DSOL simulator engine
-
-
Method Detail
-
getId
public String getId()
Get a descriptive Id of this PerceivableContext (useful for debugging purposes).- Specified by:
getIdin interfaceIdentifiable- Specified by:
getIdin interfacePerceivableContext- Returns:
- String; the id of this PerceivableContext
-
getSimulator
public OTSSimulatorInterface getSimulator()
Retrieve the simulator.- Specified by:
getSimulatorin interfaceNetwork- Returns:
- OTSSimulatorInterface; the simulator
-
getNodeMap
public ImmutableMap<String,Node> getNodeMap()
Return an immutable map of node ids to nodes in this Network.- Specified by:
getNodeMapin interfaceNetwork- Returns:
- ImmutableMap<String>; an immutable map of nodes
-
addNode
public void addNode(Node node) throws NetworkException
Register a node in this Network.- Specified by:
addNodein interfaceNetwork- Parameters:
node- Node; the node to add to this Network.- Throws:
NetworkException- if node already exists in this Network, or if name of the node is not unique
-
removeNode
public void removeNode(Node node) throws NetworkException
Unregister a node from this Network.- Specified by:
removeNodein interfaceNetwork- Parameters:
node- Node; the node to remove from this Network.- Throws:
NetworkException- if node does not exist in this Network.
-
containsNode
public boolean containsNode(Node node)
Test whether a node is present in this Network.- Specified by:
containsNodein interfaceNetwork- Parameters:
node- Node; the node to search for in this Network- Returns:
- boolean; true if the node is registered in this Network; false if the node is not registered in this Network
-
containsNode
public boolean containsNode(String nodeId)
Test whether a node with a given id is present in this Network.- Specified by:
containsNodein interfaceNetwork- Parameters:
nodeId- String; the id of the node to search for in this Network- Returns:
- boolean; true if a node with the given id exists in this Network; false if no node with the given id exists in this Network
-
getNode
public Node getNode(String nodeId)
Retrieve a node with a given id from this Network, or null if the id cannot be found.
-
getUnbalancedCentroids
public List<Node> getUnbalancedCentroids(GtuType gtuType)
Return a list of Centroid nodes that have incoming connectors without corresponding outgoing connectors to the same node or vice versa (which can be fully okay, especially when the lanes are a dead end, or when lanes / links only go in a single direction).- Parameters:
gtuType- GtuType; the GTU type for which to check the connectors- Returns:
- List<Node>; a list of Centroid nodes that have incoming connectors without corresponding outgoing connectors to the same node or vice versa.
-
getLinkMap
public ImmutableMap<String,Link> getLinkMap()
Provide an immutable map of link ids to links in this Network.- Specified by:
getLinkMapin interfaceNetwork- Returns:
- ImmutableMap<String>; the an immutable map of links
-
addLink
public void addLink(Link link) throws NetworkException
Register a link in this Network.- Specified by:
addLinkin interfaceNetwork- Parameters:
link- Link; the link to add to this Network- Throws:
NetworkException- if link already exists in this 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 this Network.
-
removeLink
public void removeLink(Link link) throws NetworkException
Unregister a link from this Network.- Specified by:
removeLinkin interfaceNetwork- Parameters:
link- Link; the link to remove from this Network- Throws:
NetworkException- if link does not exist in this Network.
-
getLink
public Link getLink(Node node1, Node node2)
Find a link between node1 and node2 and return it if it exists in this Network. If not, return null.
-
getLink
public Link getLink(String nodeId1, String nodeId2) throws NetworkException
Find a link between node1 and node2 and return it if it exists in this Network. If not, return null.- Specified by:
getLinkin interfaceNetwork- Parameters:
nodeId1- String; id of the first nodenodeId2- String; id of the second node- Returns:
- Link; the link between node1 and node2 in this Network or null if no such link exists in this Network
- Throws:
NetworkException- if the node(s) cannot be found by their id
-
containsLink
public boolean containsLink(Link link)
Test whether a link is present in this Network.- Specified by:
containsLinkin interfaceNetwork- Parameters:
link- Link; the link to search for in this Network- Returns:
- boolean; true if the link is in this Network; false if the link is not in this Network
-
containsLink
public boolean containsLink(String linkId)
Test whether a link with a given id is present in this Network.- Specified by:
containsLinkin interfaceNetwork- Parameters:
linkId- String; the id of the link to search for in this Network- Returns:
- boolean; true if a link with the given id exists in this Network; false if no link with the given id exists in this Network
-
getLink
public Link getLink(String linkId)
Retrieve a node with a given id from this Network, or null if the id cannot be found.
-
getObjectMap
public ImmutableMap<String,ObjectInterface> getObjectMap()
Return an immutable map of all ObjectInterface implementing objects in this Network.- Specified by:
getObjectMapin interfaceNetwork- Returns:
- ImmutableMap<String, ObjectInterface>; the immutable map of all ObjectInterface implementing objects in the Network
-
getObjectMap
public <T extends ObjectInterface> ImmutableMap<String,T> getObjectMap(Class<T> objectType)
Return an immutable map of all ObjectInterface implementing objects in this Network that are of type objectType, or any sub type thereof.- Specified by:
getObjectMapin interfaceNetwork- 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 this Network that are of the type objectType, or any sub-type thereof
-
getObject
public <T extends ObjectInterface> T getObject(Class<T> objectType, String objectId)
Retrieve the object of a specific type with a specific id.
-
addObject
public void addObject(ObjectInterface object) throws NetworkException
Add an ObjectInterface implementing object to this Network.- Specified by:
addObjectin interfaceNetwork- Parameters:
object- ObjectInterface; the object that implements ObjectInterface- Throws:
NetworkException- if the object already exists in this Network, or the name of the object is not unique.
-
removeObject
public void removeObject(ObjectInterface object) throws NetworkException
Remove an ObjectInterface implementing object form this Network.- Specified by:
removeObjectin interfaceNetwork- Parameters:
object- ObjectInterface; the object that implements ObjectInterface- Throws:
NetworkException- if the object does not exist in this Network.
-
findObjects
public Iterator<ObjectInterface> findObjects(Bounds3d bounds)
Construct an Iterator<ObjectInterface> that will yield all ObjectInterface objects with Bounds that intersect the given Bounds3d.- Parameters:
bounds- Bounds3d; the 3D search area- Returns:
- Iterator<ObjectInterface>; that will yield all ObjectInterface objects that intersect the given Bounds3d.
-
getNumberOfObjects
public long getNumberOfObjects()
Report how many ObjectInterface objects have been registered (the result includes objects that have subsequently been removed).- Returns:
- long; the total number of ObjectInterface objects that have been registered
-
containsObject
public boolean containsObject(ObjectInterface object)
Test whether the object is present in this Network.- Specified by:
containsObjectin interfaceNetwork- Parameters:
object- ObjectInterface; the object that is tested for presence- Returns:
- boolean; true if the object is present in this Network; false if the object is not present in this Network
-
containsObject
public boolean containsObject(String objectId)
Test whether an object with the given id is present in this Network. Note that the objectId should be the fullId of the object. E.g., for lanes this means prefixing link id, etc.- Specified by:
containsObjectin interfaceNetwork- Parameters:
objectId- String; the id that is tested for presence- Returns:
- boolean; true if an object with the given id is present in this Network; false if no object with the given id is present in this Network
-
getInvisibleObjectMap
public ImmutableMap<String,InvisibleObjectInterface> getInvisibleObjectMap()
Return an immutable map of all InvisibleObject implementing objects in this Network.- Specified by:
getInvisibleObjectMapin interfaceNetwork- Returns:
- ImmutableMap<String, ObjectInterface>; the immutable map of all ObjectInterface implementing objects in the Network
-
getInvisibleObjectMap
public ImmutableMap<String,InvisibleObjectInterface> getInvisibleObjectMap(Class<InvisibleObjectInterface> objectType)
Return an immutable map of all InvisibleObject implementing objects in this Network that are of type objectType, or any sub type thereof.- Specified by:
getInvisibleObjectMapin interfaceNetwork- 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
public void addInvisibleObject(InvisibleObjectInterface object) throws NetworkException
Add an ObjectInterface implementing object to this Network.- Specified by:
addInvisibleObjectin interfaceNetwork- Parameters:
object- InvisibleObjectInterface; the object that implements ObjectInterface- Throws:
NetworkException- if link already exists in this Network, if name of the object is not unique.
-
removeInvisibleObject
public void removeInvisibleObject(InvisibleObjectInterface object) throws NetworkException
Remove an ObjectInterface implementing object form this Network.- Specified by:
removeInvisibleObjectin interfaceNetwork- Parameters:
object- InvisibleObjectInterface; the object that implements ObjectInterface- Throws:
NetworkException- if the object does not exist in this Network.
-
containsInvisibleObject
public boolean containsInvisibleObject(InvisibleObjectInterface object)
Test whether the invisible object is present in this Network.- Specified by:
containsInvisibleObjectin interfaceNetwork- Parameters:
object- InvisibleObjectInterface; the object that is tested for presence- Returns:
- boolean; whether the invisible object is present in this Network
-
containsInvisibleObject
public boolean containsInvisibleObject(String objectId)
Test whether an invisible object with the given id is present in this Network. Note that the objectId should be the fullId of the object; including lane ids, link ids, etc.- Specified by:
containsInvisibleObjectin interfaceNetwork- Parameters:
objectId- String; the id that is tested for presence- Returns:
- boolean; whether an invisible object with the given id is present in this Network
-
getDefinedRouteMap
public ImmutableMap<String,Route> getDefinedRouteMap(GtuType gtuType)
Return an immutable map of routes that exist in this Network for the GTUType.- Specified by:
getDefinedRouteMapin interfaceNetwork- Parameters:
gtuType- GtuType; the GTUType for which to retrieve the defined routes- Returns:
- ImmutableMap<String, Route>; an immutable map of routes in this Network for the given GTUType, or an empty ImmutableMap if no routes are defined for the given GTUType.
-
addRoute
public void addRoute(GtuType gtuType, Route route) throws NetworkException
Add a route to this Network.- Specified by:
addRoutein interfaceNetwork- Parameters:
gtuType- GtuType; the GTUType for which to add a routeroute- Route; the route to add to this Network.- Throws:
NetworkException- if route already exists in this Network, or if name of the route is not unique, or if one of the nodes of the route is not registered in this Network.
-
removeRoute
public void removeRoute(GtuType gtuType, Route route) throws NetworkException
Remove the route from this Network, e.g. because of road maintenance.- Specified by:
removeRoutein interfaceNetwork- Parameters:
gtuType- GtuType; the GTUType for which to remove a routeroute- Route; the route to remove from this Network.- Throws:
NetworkException- if route does not exist in this Network.
-
containsRoute
public boolean containsRoute(GtuType gtuType, Route route)
Determine whether the provided route exists in this Network for the given GTUType.- Specified by:
containsRoutein interfaceNetwork- Parameters:
gtuType- GtuType; the GTUType for which to check whether the route existsroute- Route; the route to check for- Returns:
- boolean; true if the route exists in this Network for the given GTUType, or false if no such route exists in this Network
-
containsRoute
public boolean containsRoute(GtuType gtuType, String routeId)
Determine whether a route with the given id exists in this Network for the given GTUType.- Specified by:
containsRoutein interfaceNetwork- Parameters:
gtuType- GtuType; the GTUType for which to check whether the route existsrouteId- String; the id of the route to check for- Returns:
- boolean; true if a route with the given id exists in this Network for the given GTUType; false if no such route exists in this Network
-
getRoute
public Route getRoute(String routeId)
Retrieve the route with a specific id ornullif no such route is known in this OTSNetwork.- Parameters:
routeId- String; route id- Returns:
- Route; route with specified id or
nullif no such route is known in this OTSNetwork
-
getRoute
public Route getRoute(GtuType gtuType, String routeId)
Return the route with a specific id for a specific GTUType, or null if no route with that id for that GTUType exists in this Network.
-
getRoutesBetween
public Set<Route> getRoutesBetween(GtuType gtuType, Node nodeFrom, Node nodeTo)
Return the the shortest route for a specific GTUType between two nodes in this Network, via a list of intermediate nodes. If no path exists from the start node to the end node via the intermediate nodes in this Network, null is returned.- Specified by:
getRoutesBetweenin interfaceNetwork- Parameters:
gtuType- GtuType; the GTUType for which to retrieve the defined routesnodeFrom- Node; the start node.nodeTo- Node; the end node.- Returns:
- Set<Route>; a set with routes from the start Node to the end Node in this Network for the specified GTUType; if no route can be found, an empty set is returned.
-
buildGraph
public void buildGraph(GtuType gtuType)
(Re)build the underlying graph for the given GTUType.- Specified by:
buildGraphin interfaceNetwork- Parameters:
gtuType- GtuType; the GTUType for which to (re)build the graph
-
getShortestRouteBetween
public CompleteRoute getShortestRouteBetween(GtuType gtuType, Node nodeFrom, Node nodeTo, LinkWeight linkWeight) throws NetworkException
Calculate the shortest route between two nodes in this Network. If no path exists from the start node to the end node in this Network, null is returned. This method returns a CompleteRoute, which includes all nodes to get from start to end. This method recalculates the graph.- Specified by:
getShortestRouteBetweenin interfaceNetwork- Parameters:
gtuType- GtuType; the GTUType for which to calculate the shortest routenodeFrom- Node; the start nodenodeTo- Node; the end nodelinkWeight- LinkWeight; link weight- Returns:
- CompleteRoute; the shortest route from nodeFrom to nodeTo in this Network for the specified GTUType. If no path exists in this Network from the start node to the end node for the GTUType, 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 this Network have changed, but the graph has not been rebuilt. TODO ensure that that NetworkException cannot happen by clearing the graph when the network is changed.
-
getShortestRouteBetween
public CompleteRoute getShortestRouteBetween(GtuType gtuType, Node nodeFrom, Node nodeTo, List<Node> nodesVia) throws NetworkException
Calculate the shortest route between two nodes in this Network, via a list of intermediate nodes. If no path exists from the start node to the end node via the intermediate nodes in this 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.- Specified by:
getShortestRouteBetweenin interfaceNetwork- Parameters:
gtuType- GtuType; the GTUType for which to calculate the shortest routenodeFrom- Node; the start nodenodeTo- Node; the end nodenodesVia- List<Node>; a number of nodes that the GTU has to pass between nodeFrom and nodeTo in the given order- Returns:
- CompleteRoute; the shortest route between two nodes in this Network, via the intermediate nodes. If no path exists from nodeFrom to nodeTo via nodesVia in this 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 this Network have changed, but the graph has not been rebuilt. TODO ensure that that NetworkException cannot happen by clearing the graph when the network is changed.
-
getShortestRouteBetween
public CompleteRoute getShortestRouteBetween(GtuType gtuType, Node nodeFrom, Node nodeTo, List<Node> nodesVia, LinkWeight linkWeight) throws NetworkException
Calculate the shortest route between two nodes in this Network, via a list of intermediate nodes. If no path exists from the start node to the end node via the intermediate nodes in this Network, null is returned. This method returns a CompleteRoute, which includes all nodes to get from start to end. This method recalculates the graph.- Specified by:
getShortestRouteBetweenin interfaceNetwork- Parameters:
gtuType- GtuType; the GTUType for which to calculate the shortest routenodeFrom- Node; the start nodenodeTo- Node; the end nodenodesVia- List<Node>; a number of nodes that the GTU has to pass between nodeFrom and nodeTo in the given orderlinkWeight- LinkWeight; link weight- Returns:
- CompleteRoute; the shortest route between two nodes in this Network, via the intermediate nodes. If no path exists from the start node to the end node via the intermediate nodes in this 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 this Network have changed, but the graph has not been rebuilt. TODO explain how that is possible if this method recalculates the graph.
-
getRouteMap
public ImmutableMap<GtuType,Map<String,Route>> getRouteMap()
Get an immutable route map. TODO verify that the internal maps (from String to Route) are also immutable).- Returns:
- ImmutableMap<GTUType, Map<String, Route>>; immutable route map
-
setRawRouteMap
public void setRawRouteMap(Map<GtuType,Map<String,Route>> newRouteMap)
Replace the internal Route Map. Should only be called fro the network package when cloning a network.- Parameters:
newRouteMap- Map<GtuType, Map<String, Route>>; the routeMap to set, only to be used in the 'network' package for cloning.
-
getLinkGraphs
public ImmutableMap<GtuType,org.jgrapht.graph.SimpleDirectedWeightedGraph<Node,LinkEdge<Link>>> getLinkGraphs()
Get an immutable graph map.- Returns:
- ImmutableHashMap<GTUType, SimpleDirectedWeightedGraph<Node, LinkEdge<Link>>>; only to be used in the 'network' package for cloning.
-
addDefaultLinkTypes
public void addDefaultLinkTypes()
Add the default LinkTypes that have been defined in the enum LinkType.DEFAULTS to the network. It is not necessary to call this method on every network; when the LinkTypes are for instance defined in an XML file, adding the default types might not be needed.- Specified by:
addDefaultLinkTypesin interfaceDefinitions
-
addLinkType
public void addLinkType(LinkType linkType)
Add a Link type to the map. This method is automatically called from the LinkType constructor.- Specified by:
addLinkTypein interfaceDefinitions- Parameters:
linkType- LinkType; the LinkType to add
-
getLinkType
public LinkType getLinkType(String linkId)
Retrieve a defined LinkType based on its id.- Specified by:
getLinkTypein interfaceDefinitions- Parameters:
linkId- String; the id to search for- Returns:
- the LinkType or null in case it could not be found
-
getLinkType
public LinkType getLinkType(LinkType.DEFAULTS linkEnum)
Retrieve a defined default LinkType based on its enum.- Specified by:
getLinkTypein interfaceDefinitions- Parameters:
linkEnum- LinkType.DEFAULTS; the enum to search for- Returns:
- the LinkType or null in case it could not be found
-
getLinkTypes
public ImmutableMap<String,LinkType> getLinkTypes()
Retrieve a safe copy of the map of defined LinkTypes in this network.- Specified by:
getLinkTypesin interfaceDefinitions- Returns:
- the map of defined LinkTypes
-
addDefaultGtuTypes
public void addDefaultGtuTypes()
Add the default GTU Types that have been defined in the enum GTUType.DEFAULTS to the network. It is not necessary to call this method on every network; when the GTUTypes are for instance defined in an XML file, adding the default types might not be needed.- Specified by:
addDefaultGtuTypesin interfaceDefinitions
-
addGtuType
public void addGtuType(GtuType gtuType)
Add a GTU type to the map. This method is automatically called from the GTUType constructor.- Specified by:
addGtuTypein interfaceDefinitions- Parameters:
gtuType- GtuType; the GTUType to add
-
getGtuType
public GtuType getGtuType(String gtuId)
Retrieve a defined GTUType based on its id.- Specified by:
getGtuTypein interfaceDefinitions- Parameters:
gtuId- String; the id to search for- Returns:
- the GTUType or null in case it could not be found
-
getGtuType
public GtuType getGtuType(GtuType.DEFAULTS gtuEnum)
Retrieve a defined default GTUType based on its enum.- Specified by:
getGtuTypein interfaceDefinitions- Parameters:
gtuEnum- GtuType.DEFAULTS; the enum to search for- Returns:
- the GTUType or null in case it could not be found
-
getGtuTypes
public ImmutableMap<String,GtuType> getGtuTypes()
Retrieve a safe copy of the map of defined GTUTypes in this network.- Specified by:
getGtuTypesin interfaceDefinitions- Returns:
- the map of defined GTUTypes
-
addGtu
public void addGtu(Gtu gtu)
Add a GTU to this PerceivableContext.- Specified by:
addGtuin interfacePerceivableContext- Parameters:
gtu- Gtu; the GTU to add
-
removeGtu
public void removeGtu(Gtu gtu)
Remove a GTU from this PerceivableContext. TODO should probably throw an exception if the GTU is not in this PerceivableContext.- Specified by:
removeGtuin interfacePerceivableContext- Parameters:
gtu- Gtu; the GTU to remove
-
containsGtu
public boolean containsGtu(Gtu gtu)
Test whether a GTU is registered in this PerceivableContext.- Specified by:
containsGtuin interfacePerceivableContext- Parameters:
gtu- Gtu; the GTU to search for- Returns:
- boolean; true if the network contains the GTU; false if this PerceivableContext does not contain the GTU
-
getGtu
public Gtu getGtu(String gtuId)
Retrieve a GTU with a specific id from this PerceivableContext.- Specified by:
getGtuin interfacePerceivableContext- Parameters:
gtuId- String; the id of the GTU- Returns:
- GTU; a GTU as registered in the current model, or null when no GTU with the specified id could be found.
-
getGtus
public Set<Gtu> getGtus()
Get an overview of the GTUs in the model. The set returned is a defensive copy that may be modified by the caller.- Specified by:
getGtusin interfacePerceivableContext- Returns:
- Set<GTU>; a set of GTUs as registered in the current model.
-
containsGtuId
public boolean containsGtuId(String gtuId)
Test whether a GTU with a specific id is registered in this PerceivableContext.- Specified by:
containsGtuIdin interfacePerceivableContext- Parameters:
gtuId- String; the GTU id to search for- Returns:
- boolean; true if the network contains a GTU with this id; false if this PerceivableContext does not contain a GTU with the specified id
-
getExtent
public Bounds2d getExtent()
Calculate the extent of the network based on the network objects' locations and return the dimensions.- Returns:
- Bounds2d; the extent of the network
-
getSourceId
public Serializable getSourceId()
- Specified by:
getSourceIdin interfaceEventProducerInterface- Specified by:
getSourceIdin classEventProducer
-
-