LARGE-SCALE PARALLEL GRAPH-BASED SIMULATIONS - MATSim
LARGE-SCALE PARALLEL GRAPH-BASED SIMULATIONS - MATSim
LARGE-SCALE PARALLEL GRAPH-BASED SIMULATIONS - MATSim
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
¡<br />
t y p e d e f map- Id , Node Nodes ;<br />
t y p e d e f N o d e s : : i t e r a t o r N o d e s I t e r a t o r ;<br />
Nodes nodes ;<br />
[ . . . ]<br />
r e a d a node i n f o r m a t i o n ;<br />
n o d e s . i n s e r t ( m a k e p a i r ( nodeId , node ) ) ;<br />
[ . . . ]<br />
/ / go through a l l nodes and do something with them:<br />
f o r ( N o d e s I t e r a t o r i t = n o d e s . b e g i n ( ) ;<br />
i t != n o d e s . e n d ( ) ; + + i t )<br />
Node node = i t second ;<br />
node doSomethingWithIt ( ) ;<br />
[ . . . ]<br />
/ / f i n d a node by I d :<br />
Node node = nodes [ t h e I d ] ;<br />
Figure 3.2: The STL-map for the graph data<br />
0 1<br />
2 3 4 5 6<br />
O13 O2 O48 O9 O26 O33 O14<br />
BEFORE CALLING INSERT(3,O19)<br />
0 1 2 3 4 5 6 7<br />
O13 O2 O48 O19 O9 O26 O33 O14<br />
AFTER CALLING INSERT(3,O19)<br />
Figure 3.3: Insertion in the middle of an STL-vector. insert(position,object) is<br />
a method defined on the STL-vector. The elements behind the insertion position are shifted<br />
when insert command is used.<br />
In general, the performance of the insertion into any container depends on the type of container<br />
and where the insertion takes place. In particular, insertion at the end of an STL-vector is<br />
very fast.<br />
Some code elements to use an STL-vector for nodes (once more, links are analogous)<br />
look as in Figure 3.4. The insert of the map is replaced by a push back, which means that<br />
the new node pointer is just added at the end of the STL-vector. The iterator is essentially<br />
the same as before, except that one does not need the second because the element that is<br />
retrieved by it is no longer a (pointer to a) pair, but a (pointer to a) node.<br />
An issue with an STL-vector data structure is now searching for a key, for example to<br />
find the pointer to a node that is denoted by an ID number. A naive solution would be a linear<br />
search, the rough code is shown in Figure 3.5.<br />
21