public class OTSNetwork extends Object implements Network, PerceivableContext, Serializable
Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
$LastChangedDate: 2016-01-25 07:46:00 +0100 (Mon, 25 Jan 2016) $, @version $Revision: 1708 $, by $Author: averbraeck $,
initial version Jul 22, 2015
| 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.
|
boolean |
containsGTU(GTU gtu)
Test whether a GTU 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.
|
Map<String,Route> |
getDefinedRouteMap(GTUType gtuType)
Return a defensive copy of the defined routes that exist in the network for the GTUType.
|
Set<GTU> |
getGTUs()
Get an overview of the GTUs in the model.
|
String |
getId() |
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.
|
Map<String,Link> |
getLinkMap()
Provide a defensive copy of the 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.
|
Map<String,Node> |
getNodeMap()
Provide a defensive copy of the 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.
|
public OTSNetwork(String id)
id - the network id.public final String getId()
public final Map<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 Map<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 Map<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 Set<GTU> getGTUs()
getGTUs in interface PerceivableContextCopyright © 2014–2016 Delft University of Technology. All rights reserved.