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-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.$LastChangedDate$, @version $Revision$, by $Author$, initial version Jul 22, 2015
- Author:
- Alexander Verbraeck, Peter Knoppers, Guus Tamminga
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static double
EXTENT_MARGIN
Extra 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 void
addDefaultGtuTypes()
Add the default GTU Types that have been defined in the enum GTUType.DEFAULTS to the network.void
addDefaultLinkTypes()
Add the default LinkTypes that have been defined in the enum LinkType.DEFAULTS to the network.void
addGTU(GTU gtu)
Add a GTU to the network.void
addGtuType(GTUType gtuType)
Add a GTU type to the map.void
addInvisibleObject(InvisibleObjectInterface object)
Add an ObjectInterface implementing object to the Network.void
addLink(Link link)
Register a link in the network.void
addLinkType(LinkType linkType)
Add a Link type to the map.void
addNode(Node node)
Register a node in the network.void
addObject(ObjectInterface object)
Add an ObjectInterface implementing object to the Network.void
addRoute(GTUType gtuType, Route route)
Add a route to the network.void
buildGraph(GTUType gtuType)
(Re)build the underlying graph for the given GTUType.boolean
containsGTU(GTU gtu)
Test whether a GTU is registered in the network.boolean
containsGtuId(String gtuId)
Test whether a GTU ID is registered in the network.boolean
containsInvisibleObject(String objectId)
Test whether an invisible object with the given id is present in the Network.boolean
containsInvisibleObject(InvisibleObjectInterface object)
Test whether the invisible object is present in the Network.boolean
containsLink(String linkId)
Test whether a link with a given id is present in the network.boolean
containsLink(Link link)
Test whether a link is present in the network.boolean
containsNode(String nodeId)
Test whether a node with a given id is present in the network.boolean
containsNode(Node node)
Test whether a node is present in the network.boolean
containsObject(String objectId)
Test whether an object with the given id is present in the Network.boolean
containsObject(ObjectInterface object)
Test whether the object is present in the Network.boolean
containsRoute(GTUType gtuType, String routeId)
Determine whether a route with the given id exists in the network for the given GTUType.boolean
containsRoute(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.Rectangle2D.Double
getExtent()
Calculate the extent of the network based on the network objects' locations and return the dimensions.GTU
getGTU(String gtuId)
Get a GTU in the model.Set<GTU>
getGTUs()
Get an overview of the GTUs in the model.GTUType
getGtuType(String gtuId)
Retrieve a defined GTUType based on its id.GTUType
getGtuType(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.String
getId()
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.Link
getLink(String linkId)
Retrieve a node with a given id from the network, or null if the id cannot be found.Link
getLink(String nodeId1, String nodeId2)
Find a link between node1 and node2 and return it if it exists in the network.Link
getLink(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.LinkType
getLinkType(String linkId)
Retrieve a defined LinkType based on its id.LinkType
getLinkType(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.Node
getNode(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.(package private) Map<String,GTU>
getRawGtuMap()
(package private) Map<String,InvisibleObjectInterface>
getRawInvisibleObjectMap()
(package private) Map<GTUType,org.jgrapht.graph.SimpleDirectedWeightedGraph<Node,LinkEdge<Link>>>
getRawLinkGraphs()
(package private) Map<String,Link>
getRawLinkMap()
(package private) Map<String,Node>
getRawNodeMap()
(package private) Map<String,ObjectInterface>
getRawObjectMap()
(package private) Map<GTUType,Map<String,Route>>
getRawRouteMap()
Route
getRoute(String routeId)
Returns the route with given id ornull
if no such route is available.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.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.CompleteRoute
getShortestRouteBetween(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.CompleteRoute
getShortestRouteBetween(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.CompleteRoute
getShortestRouteBetween(GTUType gtuType, Node nodeFrom, Node nodeTo, LinkWeight linkWeight)
Calculate the shortest route between two nodes in the network.OTSSimulatorInterface
getSimulator()
Return the simulator.Serializable
getSourceId()
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).void
removeGTU(GTU gtu)
Remove a GTU from the network.void
removeInvisibleObject(InvisibleObjectInterface object)
Remove an ObjectInterface implementing object form the Network.void
removeLink(Link link)
Unregister a link from the network.void
removeNode(Node node)
Unregister a node from the network.void
removeObject(ObjectInterface object)
Remove an ObjectInterface implementing object form the Network.void
removeRoute(GTUType gtuType, Route route)
Remove the route from the network, e.g.void
setRawRouteMap(Map<GTUType,Map<String,Route>> newRouteMap)
String
toString()
-
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
- 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:
getId
in interfaceIdentifiable
- Specified by:
getId
in interfaceNetwork
- Specified by:
getId
in interfacePerceivableContext
- Returns:
- String; the id
-
getSimulator
public OTSSimulatorInterface getSimulator()
Return the simulator.- Specified by:
getSimulator
in 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:
getNodeMap
in interfaceNetwork
- Returns:
- an immutable map of nodes.
-
getRawNodeMap
final Map<String,Node> getRawNodeMap()
- Returns:
- the original NodeMap; only to be used in the 'network' package for cloning.
-
addNode
public final void addNode(Node node) throws NetworkException
Register a node in the network.- Specified by:
addNode
in 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:
removeNode
in 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:
containsNode
in 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:
containsNode
in 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:
getLinkMap
in interfaceNetwork
- Returns:
- the an immutable map of links.
-
getRawLinkMap
final Map<String,Link> getRawLinkMap()
- Returns:
- the original LinkMap; only to be used in the 'network' package for cloning.
-
addLink
public final void addLink(Link link) throws NetworkException
Register a link in the network.- Specified by:
addLink
in 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:
removeLink
in 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:
getLink
in 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:
containsLink
in 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:
containsLink
in 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:
getObjectMap
in interfaceNetwork
- Returns:
- ImmutableMap<String, ObjectInterface>; the immutable map of all ObjectInterface implementing objects in the Network
-
getRawObjectMap
final Map<String,ObjectInterface> getRawObjectMap()
- Returns:
- the original ObjectMap; only to be used in the 'network' package for cloning.
-
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:
getObjectMap
in 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:
addObject
in 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:
removeObject
in 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:
containsObject
in 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:
containsObject
in 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:
getInvisibleObjectMap
in interfaceNetwork
- Returns:
- ImmutableMap<String, ObjectInterface>; the immutable map of all ObjectInterface implementing objects in the Network
-
getRawInvisibleObjectMap
final Map<String,InvisibleObjectInterface> getRawInvisibleObjectMap()
- Returns:
- the original InvisibleObjectMap; only to be used in the 'network' package for cloning.
-
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:
getInvisibleObjectMap
in 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:
addInvisibleObject
in 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:
removeInvisibleObject
in 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:
containsInvisibleObject
in 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:
containsInvisibleObject
in 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:
getDefinedRouteMap
in 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:
addRoute
in 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:
removeRoute
in 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:
containsRoute
in 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:
containsRoute
in 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 ornull
if no such route is available.- Parameters:
routeId
- String; route id- Returns:
- route with given id or
null
if 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:
getRoutesBetween
in 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:
buildGraph
in 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:
getShortestRouteBetween
in 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:
getShortestRouteBetween
in 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:
getShortestRouteBetween
in 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.
-
getRawRouteMap
final Map<GTUType,Map<String,Route>> getRawRouteMap()
- Returns:
- routeMap; only to be used in the 'network' package for cloning.
-
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.
-
getRawLinkGraphs
final Map<GTUType,org.jgrapht.graph.SimpleDirectedWeightedGraph<Node,LinkEdge<Link>>> getRawLinkGraphs()
- 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:
addDefaultLinkTypes
in 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:
addLinkType
in interfaceDefinitions
- Parameters:
linkType
- the LinkType to add
-
getLinkType
public LinkType getLinkType(String linkId)
Retrieve a defined LinkType based on its id.- Specified by:
getLinkType
in interfaceDefinitions
- Parameters:
linkId
- 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:
getLinkType
in interfaceDefinitions
- Parameters:
linkEnum
- 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:
getLinkTypes
in 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:
addDefaultGtuTypes
in 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:
addGtuType
in interfaceDefinitions
- Parameters:
gtuType
- the GTUType to add
-
getGtuType
public GTUType getGtuType(String gtuId)
Retrieve a defined GTUType based on its id.- Specified by:
getGtuType
in interfaceDefinitions
- Parameters:
gtuId
- 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:
getGtuType
in interfaceDefinitions
- Parameters:
gtuEnum
- 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:
getGtuTypes
in interfaceDefinitions
- Returns:
- the map of defined GTUTypes
-
addGTU
public final void addGTU(GTU gtu)
Add a GTU to the network.- Specified by:
addGTU
in interfacePerceivableContext
- Parameters:
gtu
- GTU; the GTU to add
-
removeGTU
public final void removeGTU(GTU gtu)
Remove a GTU from the network.- Specified by:
removeGTU
in 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:
containsGTU
in 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:
getGTU
in 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:
getGTUs
in 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:
containsGtuId
in interfacePerceivableContext
- Parameters:
gtuId
- String; the GTU ID to search for- Returns:
- whether the network contains a GTU with this ID
-
getExtent
public Rectangle2D.Double 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:
getSourceId
in interfaceEventProducerInterface
- Specified by:
getSourceId
in classEventProducer
-
-