• Keine Ergebnisse gefunden

6.5 the pyd3t library

6.5.2 An example simulation

To finally put the D3T framework and pyd3t into practice, we consider an example D3T model. The transport space is a directed circle—the S1

6.5 the pyd3t library 71

Table 6.13: Example input/output trajectory of a myopic taxi FCFS-nearest trans-porter dispatcher. The jobs are ˜jl= ((∅,#l,∅),({l},l,{l})).

72 modelling and simulating d3t

“sphere”, on which transporters can only travel in one direction. The cir-cumference of the circle is 1. Loads arrive according to a Poisson process with rate1.75in time, with origins and destinations independent and iden-tically distributed uniformly on the circle, such that the average travel time is 12. There are2transporters, starting at the same point. Loads are assigned to transporters according to the Myopic Taxi First-Come-First-Serve Nearest Transporter dispatching policy. We simulate the system for1000 time units.

In the following, we produce the code necessary to define this D3T model with pyd3t, its stock modules, and to run the simulation with pyd3t.

First, import the necessary Python packages:

import numpy as np import pandas as pd

import d3t

from d3t.d3tsystem import D3TSystem

from d3t.dispatchers import MyopicTaxiFCFSNearestTransporterDispatcherModel from d3t.space import DirectedS1

from d3t.observers import RawDataObserver from d3t import statistics

Next, define the D3T model:

def load_generator_directeds1_uniform(rate=1.0):

rng = np.random.RandomState(seed=42) while True:

yield (

rng.exponential(scale=1.0 / rate),

rng.uniform(0.0, 1.0), rng.uniform(0.0, 1.0) )

space = DirectedS1()

representation = d3t.Representation(space=space) observer_models = [

(RawDataObserver, {'space': space}), ]

d3ts = D3TSystem(

space=space,

load_generators=[load_generator_directeds1_uniform(rate=1.75)], transporter_num=2,

transporter_positions=2*[0.0, ],

dispatcher_model=MyopicTaxiFCFSNearestTransporterDispatcherModel, dispatcher_initialization=dict(space=space),

observer_models=observer_models, )

Run the simulation:

until = 1000.0

d3ts.execute_until(until) obs = d3ts._observers[0]

Extract recorded statistics into standard pandas dataframes for further anal-ysis:

6.6 discussion 73

0 2 4 6 8

waiting time 0

50 100 150 200 250 300

Figure 6.14: Histogram of the waiting times of a D3T example simulation.

raw_loads = pd.DataFrame(

data=list(obs._loads.values()), index=list(obs._loads),

columns=obs.LOAD_COLUMNS) raw_transporters = pd.DataFrame(

data=list(obs._transporters.values()), index=list(obs._transporters),

columns=obs.TRANSPORTER_COLUMNS) raw_jobs = pd.DataFrame(

data=list(obs._jobs.values()), index=list(obs._jobs),

columns=obs.JOB_COLUMNS) raw_idleperiods = pd.DataFrame(

data=obs._idleperiods, columns=obs.IDLEPERIOD_COLUMNS)

Compute statistics with pyd3t statistical routines:

loads = statistics.compute_loads(raw_loads, raw_jobs)

Plot a histogram of the waiting times (Figure 6.14), a bar chart of the fre-quencies of the system sizes upon arrivals of requests (Figure6.15), and the total share of time0,1or both transporters are busy (Figure6.16):

loads['waiting time'].hist()

statistics.compute_arrival_system_size_frequencies(loads).plot() statistics.compute_busy_transporter_number_time(

statistics.compute_busy_transporter_number_trajectory(

statistics.compute_transporter_busy_idle_periods(

raw_idleperiods, until), until))

6.6 discussion

In this Chapter, I have introduced a formal domain-specific language to model demand-driven directed transport systems, and a Python package

74 modelling and simulating d3t

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

system size at arrival epoch 0

50 100 150 200 250 300

arrival system size frequency

Figure 6.15: Frequencies of the system sizes at arrival epochs of a D3T example simulation.

0 1 2

busy transporter number 0

100 200 300 400 500 600 700 800

period

Figure 6.16: Total duration of busy transporter number periods in a D3T example simulation.

6.6 discussion 75 to implement and simulate these models. As the underlying discrete-event framework I chose the Discrete-Event System Specification (DEVS) for its formal theory, abstraction, modularity, comprehensiveness and proven and well-tested implementation as a C++ library. There are other frameworks to simulate discrete-event systems, for example, the Python simpy package, that do not offer such a formal background, and are typically implemented in one specific programming language. DEVS is implementation-agnostic and hence provides for specifying D3T models independent of their compu-tational implementation, increasing abstraction and hence, conciseness and robustness of models in separating the different functional layers of formal definition, translation to a algorithmic implementation, and actual execution of the simulation of a model. This enhances reproducibility of computational studies of D3T systems carried out within the D3T framework. It also en-ables the D3T researcher to focus on what matters in their particular study.

For example, if one wants to investigate the effects of different transport geometries or of different spatiotemporal request patterns on D3T system performance, pyd3t already provides the event-based D3T transport mecha-nism and hides all the detail that would amount to a lot of boilerplate code needed to be implemented and tested separately for each study. Abstraction and modularity ensures and enforces that components such as dispatching policies written for one particular study can be reused for other transport spaces. The main reason why the D3T framework seems rather technical is that this is precisely what is was designed for: to encapsule technical detail in a well-defined and well-tested framework, such that the user does not need to bother about it any more in individual computational studies. As we saw in the pyd3t example, just a few lines of code suffice to produce rich dynamics and statistics.

pyd3t is a prototypical implementation of the D3T framework. While it is ready for production, there are caveats that one needs to keep in mind.

For example, the only abstraction the D3T framework and pyd3t provide for the transport space so far is the low-level function of metric distance.

As spatial indexing becomes increasingly imperative for large-scale studies with a large number of pending requests, or a large number of nodes in a network, this is a computational bottleneck. For example, in Euclidian geometries each call to the distance function invokes a square root operation.

A higher-level interface could alleviate this, such as providing an interface to spatial indexing and querying. Each transport space in turn would need to implement that interface, but could always resort to a fall-back dummy implementation that just evokes the distance function.

Both the D3T framework and pyd3t so far do not feature requests with individual time-windows (such as pick-up after a certain time, or delivery before a certain time). Formally, it is easy to extend the request event def-inition with the respective data. It is the dispatching policies that need to process and adher to these time windows.

Typically, the dispatching policy involves the most complicated and tech-nical part of any D3T model implementation. Specifying and implementa-tion dispatching policies comes with a steep learning curve. Compared to a vanilla implementation, the D3T framework surely adds further technical-ities. However, D3T compatibility enables reusability in other D3T models

76 modelling and simulating d3t

and reduces development time—for example, the transporter is already im-plemented in pyd3t, and statistics and visualization also come for free.

7 C O N C L U S I O N

In this Part of my Thesis, I have proposed and detailed a common high-level language to model and simulate demand-driven directed transport sys-tems. The D3T framework and its Python implementation pyd3t encapsule and hide the technicalities of discrete-event systems and the domain-specific logic of D3T models behind a high-level modular interface. This enables focussed and concise computational studies of D3T systems. Furthermore, the common framework and codebase facilitate collaboration and building upon others’ contributions. Perhaps the most immediate illustration of these principles is the fact that Marc Timme’s Network Dynamics Group at MPI for Dynamics and Self-Organization has been assembling a team of domain scientists to both advance the D3T approach and to employ the framework in computational studies of collective mobility systems. To further reinforce this approach, pyd3t is scheduled to be released as free and open source software in due process.

The D3T framework contains basic models for myopic taxi dispatching policies. These policies transport only one load at a time, and they do neither take into account future requests, nor currently busy transporters which will become idle in the near future, when assigning requests to transporters. Fur-ther work needs to be done to implement forward-looking disciplines. For example, these are disciplines that proactively reject requests if the individ-ual service qindivid-uality is projected to be too low. Given the interest in collective mobility and on-demand ride-sharing systems, the immediate task at hand is to implement ride-sharing disciplines such as those proposed by Santi, Resta, Szell, Sobolevsky, Strogatz, and Ratti [34] and, in particular, Alonso-Mora, Samaranayake, Wallar, Frazzoli, and Rus [36]. The D3T team currently implements these dispatching policies in pyd3t extension modules.

Another intriguing extension of the D3T framework and pyd3t that would unlock another avenue of future research is to implement feedback of the transport dynamics onto the transport space. The current specification as-sumes no such interaction. Basically, the nodes and links in a network trans-port space have infinite capacity. In human mobility on street networks, the effect of individual motorized vehicles and the congestion they cause are represented by the average travel time along the respective link. (A first ex-tension of the framework is to allow transport spaces with time-dependent travel times to allow for intraday variation.) A negative feedback could model finite capacities of links when D3T transporters dominate transport along those links. On the other hand, a positive feedback could model rein-forcement, for example, when heavily used transport links get upgraded in man-made or in biological systems (ant trails, slime molds).

To conclude, D3T and pyd3t have already started facilitating reproducible computational studies of collective mobility and transport systems. I

envi-77

78 conclusion

sion them to do even more so in the future, when both pyd3t and the first studies have been published.

Part IV

Temporal Percolation in Critical