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
A Network consists of a set of links. Each link has, in its turn, a start node and an end node.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 network.
-
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 the network.voidaddGtuType(GTUType gtuType)Add a GTU type to the map.voidaddInvisibleObject(InvisibleObjectInterface object)Add an ObjectInterface implementing object to the Network.voidaddLink(Link link)Register a link in the network.voidaddLinkType(LinkType linkType)Add a Link type to the map.voidaddNode(Node node)Register a node in the network.voidaddObject(ObjectInterface object)Add an ObjectInterface implementing object to the Network.voidaddRoute(GTUType gtuType, Route route)Add a route to the network.voidbuildGraph(GTUType gtuType)(Re)build the underlying graph for the given GTUType.booleancontainsGTU(GTU gtu)Test whether a GTU is registered in the network.booleancontainsGtuId(String gtuId)Test whether a GTU ID is registered in the network.booleancontainsInvisibleObject(String objectId)Test whether an invisible object with the given id is present in the Network.booleancontainsInvisibleObject(InvisibleObjectInterface object)Test whether the invisible object is present in the Network.booleancontainsLink(String linkId)Test whether a link with a given id is present in the network.booleancontainsLink(Link link)Test whether a link is present in the network.booleancontainsNode(String nodeId)Test whether a node with a given id is present in the network.booleancontainsNode(Node node)Test whether a node is present in the network.booleancontainsObject(String objectId)Test whether an object with the given id is present in the Network.booleancontainsObject(ObjectInterface object)Test whether the object is present in the Network.booleancontainsRoute(GTUType gtuType, String routeId)Determine whether a route with the given id exists in the network for the given GTUType.booleancontainsRoute(GTUType gtuType, Route route)Determine whether the provided route exists in the network for the given GTUType.ImmutableMap<String,Route>getDefinedRouteMap(GTUType gtuType)Return an immutable map of routes that exist in the network for the GTUType.Bounds2dgetExtent()Calculate the extent of the network based on the network objects' locations and return the dimensions.GTUgetGTU(String gtuId)Get a GTU in the model.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 the perceivable context (e.g., useful for debugging purposes).ImmutableMap<String,InvisibleObjectInterface>getInvisibleObjectMap()Return an immutable map of all InvisibleObject implementing objects in the Network.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.LinkgetLink(String linkId)Retrieve a node with a given id from the 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 the network.LinkgetLink(Node node1, Node node2)Find a link between node1 and node2 and return it if it exists in the network.ImmutableMap<GTUType,org.jgrapht.graph.SimpleDirectedWeightedGraph<Node,LinkEdge<Link>>>getLinkGraphs()ImmutableMap<String,Link>getLinkMap()Provide an immutable map of link ids to links in the 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 the network, or null if the id cannot be found.ImmutableMap<String,Node>getNodeMap()Provide an immutable map of node ids to nodes in the network.<T extends ObjectInterface>
TgetObject(Class<T> objectType, String objectId)Return object of given type with given id.ImmutableMap<String,ObjectInterface>getObjectMap()Return an immutable map of all ObjectInterface implementing objects in the Network.<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.RoutegetRoute(String routeId)Returns the route with given id ornullif no such route is available.RoutegetRoute(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.ImmutableMap<GTUType,Map<String,Route>>getRouteMap()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.CompleteRoutegetShortestRouteBetween(GTUType gtuType, Node nodeFrom, Node nodeTo, List<Node> nodesVia)Calculate the shortest route between two nodes in the 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 the network, via a list of intermediate nodes.CompleteRoutegetShortestRouteBetween(GTUType gtuType, Node nodeFrom, Node nodeTo, LinkWeight linkWeight)Calculate the shortest route between two nodes in the network.OTSSimulatorInterfacegetSimulator()Return 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 the network.voidremoveInvisibleObject(InvisibleObjectInterface object)Remove an ObjectInterface implementing object form the Network.voidremoveLink(Link link)Unregister a link from the network.voidremoveNode(Node node)Unregister a node from the network.voidremoveObject(ObjectInterface object)Remove an ObjectInterface implementing object form the Network.voidremoveRoute(GTUType gtuType, Route route)Remove the route from the network, e.g.voidsetRawRouteMap(Map<GTUType,Map<String,Route>> newRouteMap)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
-
-
-
-
Field Detail
-
EXTENT_MARGIN
public static final double EXTENT_MARGIN
Extra clearance around boundaries of network as fraction of width and height.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OTSNetwork
public OTSNetwork(String id, boolean addDefaultTypes, OTSSimulatorInterface simulator)
Construction of an empty network.- 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 final String getId()
Get a descriptive Id of the perceivable context (e.g., useful for debugging purposes).- Specified by:
getIdin interfaceIdentifiable- Specified by:
getIdin interfaceNetwork- Specified by:
getIdin interfacePerceivableContext- Returns:
- String; the id
-
getSimulator
public OTSSimulatorInterface getSimulator()
Return the simulator.- Specified by:
getSimulatorin interfaceNetwork- Returns:
- OTSSimulatorInterface; the simulator
-
getNodeMap
public final ImmutableMap<String,Node> getNodeMap()
Provide an immutable map of node ids to nodes in the network.- Specified by:
getNodeMapin interfaceNetwork- Returns:
- an immutable map of nodes.
-
addNode
public final void addNode(Node node) throws NetworkException
Register a node in the network.- Specified by:
addNodein interfaceNetwork- 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
public final void removeNode(Node node) throws NetworkException
Unregister a node from the network.- Specified by:
removeNodein interfaceNetwork- Parameters:
node- Node; the node to remove from the network.- Throws:
NetworkException- if node does not exist in the network.
-
containsNode
public final boolean containsNode(Node node)
Test whether a node is present in the network.- Specified by:
containsNodein interfaceNetwork- Parameters:
node- Node; the node to search for in the network.- Returns:
- whether the node is in this network
-
containsNode
public final boolean containsNode(String nodeId)
Test whether a node with a given id is present in the network.- Specified by:
containsNodein interfaceNetwork- Parameters:
nodeId- String; the id of the node to search for in the network.- Returns:
- whether the node is in this network
-
getNode
public final Node getNode(String nodeId)
Retrieve a node with a given id from the 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 final ImmutableMap<String,Link> getLinkMap()
Provide an immutable map of link ids to links in the network.- Specified by:
getLinkMapin interfaceNetwork- Returns:
- the an immutable map of links.
-
addLink
public final void addLink(Link link) throws NetworkException
Register a link in the network.- Specified by:
addLinkin interfaceNetwork- 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
public final void removeLink(Link link) throws NetworkException
Unregister a link from the network.- Specified by:
removeLinkin interfaceNetwork- Parameters:
link- Link; the link to remove from the network.- Throws:
NetworkException- if link does not exist in the network.
-
getLink
public final 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.
-
getLink
public final 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.- Specified by:
getLinkin interfaceNetwork- Parameters:
nodeId1- String; id of the first nodenodeId2- 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
-
containsLink
public final boolean containsLink(Link link)
Test whether a link is present in the network.- Specified by:
containsLinkin interfaceNetwork- Parameters:
link- Link; the link to search for in the network.- Returns:
- whether the link is in this network
-
containsLink
public final boolean containsLink(String linkId)
Test whether a link with a given id is present in the network.- Specified by:
containsLinkin interfaceNetwork- Parameters:
linkId- String; the id of the link to search for in the network.- Returns:
- whether the link is in this network
-
getLink
public final Link getLink(String linkId)
Retrieve a node with a given id from the network, or null if the id cannot be found.
-
getObjectMap
public final ImmutableMap<String,ObjectInterface> getObjectMap()
Return an immutable map of all ObjectInterface implementing objects in the Network.- Specified by:
getObjectMapin interfaceNetwork- Returns:
- ImmutableMap<String, ObjectInterface>; the immutable map of all ObjectInterface implementing objects in the Network
-
getObjectMap
public final <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.- 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 the Network that are of the type objectType, or any sub type thereof
-
getObject
public final <T extends ObjectInterface> T getObject(Class<T> objectType, String objectId)
Return object of given type with given id.
-
addObject
public final void addObject(ObjectInterface object) throws NetworkException
Add an ObjectInterface implementing object to the Network.- Specified by:
addObjectin interfaceNetwork- 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
public final void removeObject(ObjectInterface object) throws NetworkException
Remove an ObjectInterface implementing object form the Network.- Specified by:
removeObjectin interfaceNetwork- Parameters:
object- ObjectInterface; the object that implements ObjectInterface- Throws:
NetworkException- if the object does not exist in the network.
-
containsObject
public final boolean containsObject(ObjectInterface object)
Test whether the object is present in the Network.- Specified by:
containsObjectin interfaceNetwork- Parameters:
object- ObjectInterface; the object that is tested for presence- Returns:
- boolean; whether the object is present in the Network
-
containsObject
public final boolean containsObject(String objectId)
Test whether an object with the given id is present in the Network.Note that the objectId should be the fullId of the object, including any additions such as lane ids, link ids, etc.
- Specified by:
containsObjectin interfaceNetwork- 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
public final ImmutableMap<String,InvisibleObjectInterface> getInvisibleObjectMap()
Return an immutable map of all InvisibleObject implementing objects in the Network.- Specified by:
getInvisibleObjectMapin interfaceNetwork- Returns:
- ImmutableMap<String, ObjectInterface>; the immutable map of all ObjectInterface implementing objects in the Network
-
getInvisibleObjectMap
public final 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.- 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 final void addInvisibleObject(InvisibleObjectInterface object) throws NetworkException
Add an ObjectInterface implementing object to the Network.- Specified by:
addInvisibleObjectin interfaceNetwork- 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
public final void removeInvisibleObject(InvisibleObjectInterface object) throws NetworkException
Remove an ObjectInterface implementing object form the Network.- Specified by:
removeInvisibleObjectin interfaceNetwork- Parameters:
object- InvisibleObjectInterface; the object that implements ObjectInterface- Throws:
NetworkException- if the object does not exist in the network.
-
containsInvisibleObject
public final boolean containsInvisibleObject(InvisibleObjectInterface object)
Test whether the invisible object is present in the Network.- Specified by:
containsInvisibleObjectin interfaceNetwork- Parameters:
object- InvisibleObjectInterface; the object that is tested for presence- Returns:
- boolean; whether the invisible object is present in the Network
-
containsInvisibleObject
public final boolean containsInvisibleObject(String objectId)
Test whether an invisible object with the given id is present in the Network.Note that the objectId should be the fullId of the object, including any additions such as 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 the Network
-
getDefinedRouteMap
public final ImmutableMap<String,Route> getDefinedRouteMap(GTUType gtuType)
Return an immutable map of routes that exist in the network for the GTUType.- Specified by:
getDefinedRouteMapin interfaceNetwork- 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
public final void addRoute(GTUType gtuType, Route route) throws NetworkException
Add a route to the network.- Specified by:
addRoutein interfaceNetwork- Parameters:
gtuType- GTUType; the GTUType for which to add a routeroute- 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
public final void removeRoute(GTUType gtuType, Route route) throws NetworkException
Remove the route from the 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 the network.- Throws:
NetworkException- if route does not exist in the network.
-
containsRoute
public final boolean containsRoute(GTUType gtuType, Route route)
Determine whether the provided route exists in the 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:
- whether the route exists in the network for the given GTUType
-
containsRoute
public final boolean containsRoute(GTUType gtuType, String routeId)
Determine whether a route with the given id exists in the 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:
- whether a route with the given id exists in the network for the given GTUType
-
getRoute
public final Route getRoute(String routeId)
Returns the route with given id ornullif no such route is available.- Parameters:
routeId- String; route id- Returns:
- route with given id or
nullif no such route is available
-
getRoute
public final 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.
-
getRoutesBetween
public final 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.- 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:
- 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
public final 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 final 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.- Specified by:
getShortestRouteBetweenin interfaceNetwork- Parameters:
gtuType- GTUType; the GTUType for which to calculate the shortest routenodeFrom- 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
public final 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.- Specified by:
getShortestRouteBetweenin interfaceNetwork- Parameters:
gtuType- GTUType; the GTUType for which to calculate the shortest routenodeFrom- 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
public final 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.- Specified by:
getShortestRouteBetweenin interfaceNetwork- Parameters:
gtuType- GTUType; the GTUType for which to calculate the shortest routenodeFrom- 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.
-
getRouteMap
public final ImmutableMap<GTUType,Map<String,Route>> getRouteMap()
- Returns:
- a defensive copy of the routeMap.
-
setRawRouteMap
public final void setRawRouteMap(Map<GTUType,Map<String,Route>> newRouteMap)
- Parameters:
newRouteMap- Map<GTUType,Map<String,Route>>; the routeMap to set, only to be used in the 'network' package for cloning.
-
getLinkGraphs
public final ImmutableMap<GTUType,org.jgrapht.graph.SimpleDirectedWeightedGraph<Node,LinkEdge<Link>>> getLinkGraphs()
- Returns:
- linkGraphs; 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 final void addGTU(GTU gtu)
Add a GTU to the network.- Specified by:
addGTUin interfacePerceivableContext- Parameters:
gtu- GTU; the GTU to add
-
removeGTU
public final void removeGTU(GTU gtu)
Remove a GTU from the network.- Specified by:
removeGTUin interfacePerceivableContext- Parameters:
gtu- GTU; the GTU to remove
-
containsGTU
public final boolean containsGTU(GTU gtu)
Test whether a GTU is registered in the network.- Specified by:
containsGTUin interfacePerceivableContext- Parameters:
gtu- GTU; the GTU to search for- Returns:
- whether the network contains this GTU
-
getGTU
public final GTU getGTU(String gtuId)
Get a GTU in the model.- Specified by:
getGTUin interfacePerceivableContext- Parameters:
gtuId- String; the id of the GTU- Returns:
- a GTU as registered in the current model, or null when the id could not be found.
-
getGTUs
public final Set<GTU> getGTUs()
Get an overview of the GTUs in the model. The set returned is a defensive copy.- Specified by:
getGTUsin interfacePerceivableContext- Returns:
- a set of GTUs as registered in the current model.
-
containsGtuId
public final boolean containsGtuId(String gtuId)
Test whether a GTU ID is registered in the network.- Specified by:
containsGtuIdin interfacePerceivableContext- Parameters:
gtuId- String; the GTU ID to search for- Returns:
- whether the network contains a GTU with this ID
-
getExtent
public Bounds2d getExtent()
Calculate the extent of the network based on the network objects' locations and return the dimensions.- Returns:
- Rectangle2D.Double; the extent of the network
-
getSourceId
public Serializable getSourceId()
- Specified by:
getSourceIdin interfaceEventProducerInterface- Specified by:
getSourceIdin classEventProducer
-
-