public class OTSNetwork extends nl.tudelft.simulation.event.EventProducer implements Network, PerceivableContext, Serializable
Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
$LastChangedDate: 2016-12-11 14:07:37 +0100 (Sun, 11 Dec 2016) $, @version $Revision: 2838 $, by $Author: averbraeck $,
initial version Jul 22, 2015
GTU_ADD_EVENT, GTU_REMOVE_EVENT, LINK_ADD_EVENT, LINK_REMOVE_EVENT, NODE_ADD_EVENT, NODE_REMOVE_EVENT, ROUTE_ADD_EVENT, ROUTE_REMOVE_EVENT| Constructor and Description |
|---|
OTSNetwork(String id)
Construction of an empty network.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addGTU(GTU gtu)
Add a GTU to the network.
|
void |
addLink(Link link)
Register a link in the network.
|
void |
addNode(Node node)
Register a node in 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.
|
OTSNetwork |
clone(String newId,
OTSSimulatorInterface newSimulator,
boolean animation)
Clone the OTSNetwork.
|
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 |
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 |
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.
|
GTU |
getGTU(String gtuId)
Get a GTU in the model.
|
Set<GTU> |
getGTUs()
Get an overview of the GTUs in the model.
|
String |
getId()
Get a descriptive Id of the perceivable context (e.g., useful for debugging purposes).
|
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<String,Link> |
getLinkMap()
Provide an immutable map of link ids to links in the 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.
|
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.
|
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)
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.
|
void |
removeGTU(GTU gtu)
Remove a GTU from the network.
|
void |
removeLink(Link link)
Unregister a link from the network.
|
void |
removeNode(Node node)
Unregister a node from the network.
|
void |
removeRoute(GTUType gtuType,
Route route)
Remove the route from the network, e.g.
|
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, removeListenerpublic OTSNetwork(String id)
id - the network id.public final String getId()
getId in interface NetworkgetId in interface PerceivableContextpublic final ImmutableMap<String,Node> getNodeMap()
getNodeMap in interface Networkpublic final void addNode(Node node) throws NetworkException
addNode in interface Networknode - 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 Networknode - 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 Networknode - the node to search for in the network.public final boolean containsNode(String nodeId)
containsNode in interface NetworknodeId - 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 Networkpublic final void addLink(Link link) throws NetworkException
addLink in interface Networklink - 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 Networklink - 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 NetworknodeId1 - id of the first nodenodeId2 - id of the second nodeNetworkException - if the node(s) cannot be found by their idpublic final boolean containsLink(Link link)
containsLink in interface Networklink - the link to search for in the network.public final boolean containsLink(String linkId)
containsLink in interface NetworklinkId - the id of the link to search for in the network.public final Link getLink(String linkId)
public final ImmutableMap<String,Route> getDefinedRouteMap(GTUType gtuType)
getDefinedRouteMap in interface NetworkgtuType - the GTUType for which to retrieve the defined routespublic final void addRoute(GTUType gtuType, Route route) throws NetworkException
addRoute in interface NetworkgtuType - the GTUType for which to add a routeroute - 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 NetworkgtuType - the GTUType for which to remove a routeroute - 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 NetworkgtuType - the GTUType for which to check whether the route existsroute - the route to check forpublic final boolean containsRoute(GTUType gtuType, String routeId)
containsRoute in interface NetworkgtuType - the GTUType for which to check whether the route existsrouteId - the id of the route to check forpublic final Route getRoute(GTUType gtuType, String routeId)
public final Set<Route> getRoutesBetween(GTUType gtuType, Node nodeFrom, Node nodeTo)
getRoutesBetween in interface NetworkgtuType - the GTUType for which to retrieve the defined routesnodeFrom - the start node.nodeTo - the end node.public final void buildGraph(GTUType gtuType)
buildGraph in interface NetworkgtuType - the GTUType for which to (re)build the graphpublic final CompleteRoute getShortestRouteBetween(GTUType gtuType, Node nodeFrom, Node nodeTo) throws NetworkException
getShortestRouteBetween in interface NetworkgtuType - the GTUType for which to calculate the shortest routenodeFrom - the start node.nodeTo - the end node.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 NetworkgtuType - the GTUType for which to calculate the shortest routenodeFrom - the start node.nodeTo - the end node.nodesVia - 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 void addGTU(GTU gtu)
addGTU in interface PerceivableContextgtu - the GTU to addpublic final void removeGTU(GTU gtu)
removeGTU in interface PerceivableContextgtu - the GTU to removepublic final boolean containsGTU(GTU gtu)
containsGTU in interface PerceivableContextgtu - the GTU to search forpublic final GTU getGTU(String gtuId)
getGTU in interface PerceivableContextgtuId - the id of the GTUpublic final Set<GTU> getGTUs()
getGTUs in interface PerceivableContextpublic final boolean containsGtuId(String gtuId)
containsGtuId in interface PerceivableContextgtuId - the GTU ID to search forpublic OTSNetwork clone(String newId, OTSSimulatorInterface newSimulator, boolean animation) throws NetworkException
newId - the new id of the networknewSimulator - the new simulator for this networkanimation - whether to (re)create animation or notNetworkException - in case the cloning failsCopyright © 2014–2017 Delft University of Technology. All rights reserved.