public class OTSNetwork extends EventProducer implements Network, PerceivableContext, Serializable
Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
$LastChangedDate: 2019-03-17 22:16:44 +0100 (Sun, 17 Mar 2019) $, @version $Revision: 5158 $, by $Author: averbraeck $,
initial version Jul 22, 2015
listeners
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
FIRST_POSITION, LAST_POSITION
Constructor and Description |
---|
OTSNetwork(String id,
boolean addDefaultTypes)
Construction of an empty network.
|
Modifier and Type | Method and 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(InvisibleObjectInterface object)
Test whether the invisible object is present in the Network.
|
boolean |
containsInvisibleObject(String objectId)
Test whether an invisible object with the given id is present in the Network.
|
boolean |
containsLink(Link link)
Test whether a link is present in the network.
|
boolean |
containsLink(String linkId)
Test whether a link with a given id is present in the network.
|
boolean |
containsNode(Node node)
Test whether a node is present in the network.
|
boolean |
containsNode(String nodeId)
Test whether a node with a given id is present in the network.
|
boolean |
containsObject(ObjectInterface object)
Test whether the object is present in the Network.
|
boolean |
containsObject(String objectId)
Test whether an object with the given id is present in the Network.
|
boolean |
containsRoute(GTUType gtuType,
Route route)
Determine whether the provided route exists in the network for the given GTUType.
|
boolean |
containsRoute(GTUType gtuType,
String routeId)
Determine whether a route with the given id 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(GTUType.DEFAULTS gtuEnum)
Retrieve a defined default GTUType based on its enum.
|
GTUType |
getGtuType(String gtuId)
Retrieve a defined GTUType based on its id.
|
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(Node node1,
Node node2)
Find a link between node1 and node2 and return it if it exists in the network.
|
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.
|
ImmutableMap<GTUType,SimpleDirectedWeightedGraph<Node,LinkEdge<Link>>> |
getLinkGraphs() |
ImmutableMap<String,Link> |
getLinkMap()
Provide an immutable map of link ids to links in the network.
|
LinkType |
getLinkType(LinkType.DEFAULTS linkEnum)
Retrieve a defined default LinkType based on its enum.
|
LinkType |
getLinkType(String linkId)
Retrieve a defined LinkType based on its id.
|
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> |
getObject(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> |
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.
|
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.
|
Route |
getRoute(String routeId)
Returns the route with given id or
null if no such route is available. |
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,
LinkWeight linkWeight)
Calculate the shortest route between two nodes in the network.
|
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.
|
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() |
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, removeAllListeners, removeAllListeners, removeListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getShortestRouteBetween
addListener, addListener, addListener, addListener, removeListener
public OTSNetwork(String id, boolean addDefaultTypes)
id
- String; the network id.addDefaultTypes
- add the default GTUTypes and LinkTypes, or notpublic final String getId()
getId
in interface Identifiable
getId
in interface Network
getId
in interface PerceivableContext
public final ImmutableMap<String,Node> getNodeMap()
getNodeMap
in interface Network
public final void addNode(Node node) throws NetworkException
addNode
in interface Network
node
- Node; the node to add to the network.NetworkException
- if node already exists in the network, or if name of the node is not unique.public final void removeNode(Node node) throws NetworkException
removeNode
in interface Network
node
- Node; the node to remove from the network.NetworkException
- if node does not exist in the network.public final boolean containsNode(Node node)
containsNode
in interface Network
node
- Node; the node to search for in the network.public final boolean containsNode(String nodeId)
containsNode
in interface Network
nodeId
- String; the id of the node to search for in the network.public final Node getNode(String nodeId)
public final ImmutableMap<String,Link> getLinkMap()
getLinkMap
in interface Network
public final void addLink(Link link) throws NetworkException
addLink
in interface Network
link
- Link; the link to add to the network.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.public final void removeLink(Link link) throws NetworkException
removeLink
in interface Network
link
- Link; the link to remove from the network.NetworkException
- if link does not exist in the network.public final Link getLink(Node node1, Node node2)
public final Link getLink(String nodeId1, String nodeId2) throws NetworkException
getLink
in interface Network
nodeId1
- String; id of the first nodenodeId2
- String; id of the second nodeNetworkException
- if the node(s) cannot be found by their idpublic final boolean containsLink(Link link)
containsLink
in interface Network
link
- Link; the link to search for in the network.public final boolean containsLink(String linkId)
containsLink
in interface Network
linkId
- String; the id of the link to search for in the network.public final Link getLink(String linkId)
public final ImmutableMap<String,ObjectInterface> getObjectMap()
getObjectMap
in interface Network
public final <T extends ObjectInterface> ImmutableMap<String,T> getObjectMap(Class<T> objectType)
getObjectMap
in interface Network
T
- type of objectobjectType
- Class<T>; the (sub-)type of ObjectInterface that the returned map is reduced topublic final <T extends ObjectInterface> T getObject(Class<T> objectType, String objectId)
public final void addObject(ObjectInterface object) throws NetworkException
addObject
in interface Network
object
- ObjectInterface; the object that implements ObjectInterfaceNetworkException
- if link already exists in the network, if name of the object is not unique.public final void removeObject(ObjectInterface object) throws NetworkException
removeObject
in interface Network
object
- ObjectInterface; the object that implements ObjectInterfaceNetworkException
- if the object does not exist in the network.public final boolean containsObject(ObjectInterface object)
containsObject
in interface Network
object
- ObjectInterface; the object that is tested for presencepublic final boolean containsObject(String objectId)
Note that the objectId should be the fullId of the object, including any additions such as lane ids, link ids, etc.
containsObject
in interface Network
objectId
- String; the id that is tested for presencepublic final ImmutableMap<String,InvisibleObjectInterface> getInvisibleObjectMap()
getInvisibleObjectMap
in interface Network
public final ImmutableMap<String,InvisibleObjectInterface> getInvisibleObjectMap(Class<InvisibleObjectInterface> objectType)
getInvisibleObjectMap
in interface Network
objectType
- Class<InvisibleObjectInterface>; the (sub-)type of InvisibleObject that the returned map is
reduced topublic final void addInvisibleObject(InvisibleObjectInterface object) throws NetworkException
addInvisibleObject
in interface Network
object
- InvisibleObjectInterface; the object that implements ObjectInterfaceNetworkException
- if link already exists in the network, if name of the object is not unique.public final void removeInvisibleObject(InvisibleObjectInterface object) throws NetworkException
removeInvisibleObject
in interface Network
object
- InvisibleObjectInterface; the object that implements ObjectInterfaceNetworkException
- if the object does not exist in the network.public final boolean containsInvisibleObject(InvisibleObjectInterface object)
containsInvisibleObject
in interface Network
object
- InvisibleObjectInterface; the object that is tested for presencepublic final boolean containsInvisibleObject(String objectId)
Note that the objectId should be the fullId of the object, including any additions such as lane ids, link ids, etc.
containsInvisibleObject
in interface Network
objectId
- String; the id that is tested for presencepublic final ImmutableMap<String,Route> getDefinedRouteMap(GTUType gtuType)
getDefinedRouteMap
in interface Network
gtuType
- GTUType; the GTUType for which to retrieve the defined routespublic final void addRoute(GTUType gtuType, Route route) throws NetworkException
addRoute
in interface Network
gtuType
- GTUType; the GTUType for which to add a routeroute
- Route; the route to add to the network.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.public final void removeRoute(GTUType gtuType, Route route) throws NetworkException
removeRoute
in interface Network
gtuType
- GTUType; the GTUType for which to remove a routeroute
- Route; the route to remove from the network.NetworkException
- if route does not exist in the network.public final boolean containsRoute(GTUType gtuType, Route route)
containsRoute
in interface Network
gtuType
- GTUType; the GTUType for which to check whether the route existsroute
- Route; the route to check forpublic final boolean containsRoute(GTUType gtuType, String routeId)
containsRoute
in interface Network
gtuType
- GTUType; the GTUType for which to check whether the route existsrouteId
- String; the id of the route to check forpublic final Route getRoute(String routeId)
null
if no such route is available.routeId
- String; route idnull
if no such route is availablepublic final Route getRoute(GTUType gtuType, String routeId)
public final Set<Route> getRoutesBetween(GTUType gtuType, Node nodeFrom, Node nodeTo)
getRoutesBetween
in interface Network
gtuType
- GTUType; the GTUType for which to retrieve the defined routesnodeFrom
- Node; the start node.nodeTo
- Node; the end node.public final void buildGraph(GTUType gtuType)
buildGraph
in interface Network
gtuType
- GTUType; the GTUType for which to (re)build the graphpublic final CompleteRoute getShortestRouteBetween(GTUType gtuType, Node nodeFrom, Node nodeTo, LinkWeight linkWeight) throws NetworkException
getShortestRouteBetween
in interface Network
gtuType
- GTUType; the GTUType for which to calculate the shortest routenodeFrom
- Node; the start node.nodeTo
- Node; the end node.linkWeight
- LinkWeight; link weight.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.public final CompleteRoute getShortestRouteBetween(GTUType gtuType, Node nodeFrom, Node nodeTo, List<Node> nodesVia) throws NetworkException
getShortestRouteBetween
in interface Network
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.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.public final CompleteRoute getShortestRouteBetween(GTUType gtuType, Node nodeFrom, Node nodeTo, List<Node> nodesVia, LinkWeight linkWeight) throws NetworkException
getShortestRouteBetween
in interface Network
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.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.public final ImmutableMap<GTUType,Map<String,Route>> getRouteMap()
public final void setRawRouteMap(Map<GTUType,Map<String,Route>> newRouteMap)
newRouteMap
- Map<GTUType,Map<String,Route>>; the routeMap to set, only to be used in the 'network'
package for cloning.public final ImmutableMap<GTUType,SimpleDirectedWeightedGraph<Node,LinkEdge<Link>>> getLinkGraphs()
public void addDefaultLinkTypes()
addDefaultLinkTypes
in interface Definitions
public void addLinkType(LinkType linkType)
addLinkType
in interface Definitions
linkType
- the LinkType to addpublic LinkType getLinkType(String linkId)
getLinkType
in interface Definitions
linkId
- the id to search forpublic LinkType getLinkType(LinkType.DEFAULTS linkEnum)
getLinkType
in interface Definitions
linkEnum
- the enum to search forpublic ImmutableMap<String,LinkType> getLinkTypes()
getLinkTypes
in interface Definitions
public void addDefaultGtuTypes()
addDefaultGtuTypes
in interface Definitions
public void addGtuType(GTUType gtuType)
addGtuType
in interface Definitions
gtuType
- the GTUType to addpublic GTUType getGtuType(String gtuId)
getGtuType
in interface Definitions
gtuId
- the id to search forpublic GTUType getGtuType(GTUType.DEFAULTS gtuEnum)
getGtuType
in interface Definitions
gtuEnum
- the enum to search forpublic ImmutableMap<String,GTUType> getGtuTypes()
getGtuTypes
in interface Definitions
public final void addGTU(GTU gtu)
addGTU
in interface PerceivableContext
gtu
- GTU; the GTU to addpublic final void removeGTU(GTU gtu)
removeGTU
in interface PerceivableContext
gtu
- GTU; the GTU to removepublic final boolean containsGTU(GTU gtu)
containsGTU
in interface PerceivableContext
gtu
- GTU; the GTU to search forpublic final GTU getGTU(String gtuId)
getGTU
in interface PerceivableContext
gtuId
- String; the id of the GTUpublic final Set<GTU> getGTUs()
getGTUs
in interface PerceivableContext
public final boolean containsGtuId(String gtuId)
containsGtuId
in interface PerceivableContext
gtuId
- String; the GTU ID to search forpublic Rectangle2D.Double getExtent()
Copyright © 2014–2019 Delft University of Technology. All rights reserved.