01.01.2015 Views

LARGE-SCALE PARALLEL GRAPH-BASED SIMULATIONS - MATSim

LARGE-SCALE PARALLEL GRAPH-BASED SIMULATIONS - MATSim

LARGE-SCALE PARALLEL GRAPH-BASED SIMULATIONS - MATSim

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

In this section, two STL functions will be tested, namely, list and deque. Because of the<br />

low performance they involve, in addition a user-defined data structure Ring is implemented<br />

and tested.<br />

List<br />

The STL-list is a doubly linked list. With the STL-list, insertion anywhere is fast but<br />

it provides only sequential access. Since random access is not needed, this should in theory<br />

be a fast data structure for the purpose here. Unfortunately, the STL-list comes with high<br />

overhead as explained below.<br />

Deque<br />

The STL-deque (double-ended queue) is similar in usage and syntax to the STL-vector.<br />

It allows random access and inserts elements fast at either end. Therefore the STL-deque<br />

is the data structure of choice when most insertions and deletions take place at the beginning<br />

or at the end of a container. The STL-deque is different from the STL-vector in terms<br />

of memory management. When resizing is necessary, the STL-deque allocates memory in<br />

chunks as it grows, with room for a fixed number of elements in each reallocation. In other<br />

words, the STL-deque uses a series of smaller blocks of memory. The STL-vector, on the<br />

other hand, allocates its memory in a contiguous block, i.e., the STL-vector is represented<br />

by one long block of memory.<br />

Self-implemented Ring data structure<br />

To overcome the inefficiencies of the STL-list and the STL-deque, a new data structure,<br />

Ring is implemented. Ring is a circular vector. Removal is at the beginning and insertion<br />

is at the end. Removing from the beginning of the STL-vector is a costly operation since<br />

it includes the forward movement of all the remaining elements. In order to get rid of this<br />

difficulty, supplementary pointers are used to keep track of the head and the tail of the data<br />

structure. Hence, with this new structure, only head/tail pointers move back and forth, not the<br />

elements as in the STL-vector container. The same pointers are also used for insertion.<br />

Figure 3.11(a) shows how insertion takes place at the end of Ring structure. The supplementary<br />

pointers head and tail are used to keep track of elements. The maximum size of the<br />

structure is 8 in the example. When the size is 0, the head and the tail point to NIL. Then, an<br />

object, O1, is requested to be inserted. A pointer to the object is placed in the first cell of the<br />

structure. Both the head and the tail point to this cell (accordingly O1) after the insertion. Then<br />

another object, O2, is to be inserted. Since the call is push back, it is placed at the end, i.e.,<br />

the next cell after the last item (O1). The tail pointer is advanced. Now, the head points to O1<br />

and the tail points to O2. The current size becomes 2.<br />

Figure 3.11(b) illustrates deletion from the beginning, by using pop front. The structure<br />

is full, i.e., the size is 8. The head points to the first element(O1) and the tail points the last<br />

element (O8). After deletion, the tail remains the same, but the head is advanced to the next<br />

object (O2) from O1. If further deletion is requested, the head is moved one more cell (to O3).<br />

After two deletions, the size becomes 6.<br />

It is important to note that this works because of the fixed maximum size. This corresponds<br />

to the maximum number of vehicles on the link.<br />

27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!