Skip to content

Road Network Loader

smart-fm edited this page Nov 9, 2018 · 15 revisions

The road network is a fundamental input to SimMobility. It is required by both the mid-term and the short-term simulators and, as a result, the NetworkLoader along with the RoadNetwork is a shared component.

RoadNetwork

The SimMobililty road network is made up of multiple components. Details about these can be found here and here. The RoadNetwork class allows us to bring together these components under one roof. It holds containers (maps) for each of the components of the road network, and provides methods to allow addition of the created objects into the respective containers. The main responsibility of this class is to allow easy access to these components when required. As there can be only one road network in use during a simulation, this class is a singleton.

Accessing the RoadNetwork elements

The RoadNetwork class, being a singleton, exposes a static method that returns a pointer to the singleton instance. You may use the following snippet to retrieve the said pointer.

const RoadNetwork *network = RoadNetwork::getInstance();

Using this pointer, one may retrieve constant references to either entire maps of the individual components or retrieve specific objects based on their identifiers as shown below.

//Retrieving the entire map of nodes
const std::map<unsigned int, Node *> &mapOfNodes = network->getMapOfIdvsNodes();

//Retrieving a node with id given by nodeId
const Node *node = network->getById(network->getMapOfIdvsNodes(), nodeId);

Additionally, as the RoadNetwork is designed in a way that it maintains the container/content hierarchy between the elements, one can easily retrieve the contents of a given RoadNetwork component. For example, to retrieve the segments within a link one can use the following:

//Retrieving all RoadSegments within a given link
const std::vector<RoadSegment*> &roadSegments = link->getRoadSegments();

//Retrieving a RoadSegment with a specific index (sequence within a link) within a given link
const RoadSegment *roadSegment = link->getRoadSegment(index);

NetworkLoader

The NetworkLoader class, as the name suggests, is responsible for loading the SimMobility road network. It is a also a singleton. It is the only class with write access to the instance of the RoadNetwork class.
The public method loadNetwork(const string, const map<string, string>) connects to the database using the given connection string and loads the individual components of the network using the map of stored procedures defined in the configuration files.
The network loading process is explained in the below sequence diagram

Sequence Diagam

Clone this wiki locally