Skip to content

Pathset generation how to

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

Travel demand data, namely the Day Activity Schedule (DAS) for mid-term and the trip chain data for short-term, typically contains information about origin and destination nodes, departure times and travel mode. In SimMobility mid-term withinday simulation and short-term simulation, an agent who wants to travel from node A to node B is required to select a route to navigate the network from A to B. In order to facilitate this selection of routes, we need to generate a priori a set of route alternatives between all Origin-Destination pairs before running withinday simulation or short-term simulation. The process of generating a set of paths between an origin-destination (OD) pair is what we refer to as pathset generation.

Further, there is a distinction between paths generated for public transit modes like public bus, metro trains etc., and private modes like car, motorcycle etc. For private modes, a path is simply a sequence of links along the road network leading from the origin node to the destination node. However for Public Transit (PT) modes, a path defines the sequence of legs involving an access trip to a PT stop, a journey by a specific PT line from that stop to another specific destination PT stop, zero or more transfers and PT trips on other PT lines, and finally an egress trip from the last PT stop to the destination node. A PT path does not specify any links or road segments in the road network. It only specifies the sequence of edges in the PT graph built solely for the purpose of PT route choice. For more details about PT routechoice, refer here.

For more details about the implementation of path set computation, refer to this page.

Evidently, we use different graphs for generating PT paths and private paths. Therefore, we usually run PT and private pathset generation as separate jobs. Below are the steps involved in the generation of pathsets for ODs in the demand data involving both public and private modes.

Pathset generation steps

The following conceptual steps are accomplished in order to produce the Pathset:

  • The flows of person agents moving from a node to another of the city, based on the activities they have to accomplish, are computed. More precisely, we generate an Origin-Destination matrix based on the Day Activity Schedule. Recall that the sequence of activities that a person decides to accomplish in the day translates into a sequence of trips from an origin node to a destination node. Each trip generate a flow between these nodes, that we add to the Origin-Destination matrix.
  • Each of the trips mentioned above will realized on a path, i.e., a sequence of links that starts at the origin of the trip and terminates at the destination. Therefore, for each trip, we generate a pathset (via specific algorithms),which is the a set of paths connecting the origin to the destination of the trip. When a person agent will actually perform the trip (for example during the next within-day simulation of Mid Term or the Short Term simulation), she will choose one of the path in the pathset.

NOTE: The SQL operations below are not performed by SimMobility. It is up to you to do them.

1. Create OD tables (if required)

As already stated, before generating the pathsets, we need to provide a list of ODs in a table in the simmobility database. There are separate tables to hold the ODs for public transit and private traffic pathset generation. Below are the sql scripts to create the OD tables, in case the OD tables do not already exist in the database.

create table routechoice.pvt_od 
(
  origin integer not null,
  destination integer not null,
  constraint pvt_od_pk primary key (origin, destination) 
);
alter table routechoice.pvt_od owner to postgres; 

create table routechoice.pt_od 
(
  origin integer not null,
  destination integer not null,
  constraint pt_od_pk primary key (origin, destination) 
);
alter table routechoice.pt_od owner to postgres; 

2. Fetch ODs

The following queries extract distinct OD pairs from the Day Activity Schedule (DAS) table for which paths are to be generated. The extracted ODs are also copied into corresponding OD tables. In the code below, <das_table> must be a table like this.

PT
We take all ODs for which there are trips with a public transit mode (bus travel or train).

truncate routechoice.pt_od;
insert into routechoice.pt_od 
(
  select distinct prev_stop_location, stop_location 
    from demand.<das_table_name> 
   where stop_mode in ('BusTravel', 'MRT') 
);

private
We take all ODs for which there are trips without a public transit mode. Note that we will get ODs even for modes like walk, car sharing etc., for which we don't need pathsets. However, there is no harm in generating paths for some additional ODs which may be useful later when re-routing is fully implemented into withinday. If you want ODs just for those trips which involve a private vehicle (car, motorcycle, taxi etc.), you must enumerate those modes in the where clause accordingly.

truncate routechoice.pvt_od;
insert into routechoice.pvt_od 
(
  select distinct prev_stop_location, stop_location 
    from demand.<das_table_name> 
   where stop_mode not in ('BusTravel', 'MRT') 
);

Here we only explains how to extract ODs from the day activity schedule data. The procedure is similar to extract ODs from the trip-chain data for short-term.

3. Filter out ODs for which paths exist in the pathset tables

After extracting the ODs for pathset generation, we need to eliminate from the list of ODs any OD pair for which paths already exist in the respective pathset tables, in case we have already performed the pathset generation before. This step eliminates redundant ODs and saves execution time, and also helps in the easy accumulation of pathsets into the same table.
PT

delete from routechoice.pt_od where exists 
(
  select 1 from routechoice.<pt_pathset_table> 
   where pathset_origin_node = origin
     and pathset_dest_node = destination
);

private

delete from routechoice.pvt_od where exists 
(
  select 1 from routechoice.<pvt_pathset_table> 
   where pathset_origin_node = origin
     and pathset_dest_node = destination
);

Tip: After eliminating the redundant ODs, we can cut the data in these OD tables into multiple mutually exclusive and exhaustive subsets (based on the availability of computational resources), keep those subsets in separate OD tables and generate paths for those subsets in parallel by following the steps below.

4. Configure and run SimMobility for pathset generation

We are ready to generate the pathsets now.

NOTE: When running MidTerm, we set <mid_term_run_mode value="withinday"/> in data/simrun_MidTerm.xml to generate pathsets.

We set <private_pathset enabled="true" mode="generation"> in data/pathset_config.xml or <public_pathset enabled="true" mode="generation">. An example of data/pathset_config.xml follows.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright Singapore-MIT Alliance for Research and Technology -->
<pathset enabled="true">
    <thread_pool size="60"/>
    <private_pathset enabled="true" mode="generation"> <!--"normal" and "generation" are supported modes -->
        <od_source table="routechoice.pvt_od"/>
        <bulk_generation_output_file name="pvt-pathset.csv" />
        <tables historical_traveltime="supply.link_travel_time" default_traveltime="supply.link_default_travel_time"/>
        <functions pathset_without_banned_area="get_path_set_woba"/>
        <recursive_pathset_generation value="false"/>
        <reroute enabled="false" />
        <utility_parameters>
            <highwayBias value="0.5"/>
        </utility_parameters>
        <path_generators max_segment_speed="26.39"> <!--in cm/s--> <!-- 2639cm/s = 95km/hr -->
            <k_shortest_path level="5" />
            <link_elimination types="default,highway" />    <!-- unused for now. only default and highway are used in the code-->
            <random_perturbation modes="time" iterations="100" uniform_range="1,100" /> <!-- for 'modes' attribute, only "time" is supported for now -->
        </path_generators>
    </private_pathset>

    <public_pathset enabled="true" mode="normal"> <!-- "normal" and "generation" modes are supported -->
        <od_source table="routechoice.pt_od"/>
        <bulk_generation_output_file name="pt-pathset.csv" />
        <pathset_generation_algorithms>
            <k_shortest_path level="10" />
            <simulation_approach iterations="100"/>
        </pathset_generation_algorithms>
    </public_pathset>
</pathset>

If you want to generate private pathsets, you may need to disable public path use. You can set the followings:

  1. In data/pathset_config.xml: <public_pathset enabled="false" mode="normal">
  2. In data/simrun_MidTerm.xml: <public_transit enabled="false"/>

More details can be found here.

  1. <thread_pool/> controls the number of threads to spawn for pathset generation. The task of pathset generation is highly parallelizable. The data in the OD table is divided equally among each thread which in turn iterates the list and generates a set of paths for each OD.
  2. The value of mode in <private_pathset\> controls whether SimMobility runs in private pathset generation or normal mode. The value of mode in <public_pathset\> element controls whether SimMobility runs in public transit pathset generation or normal mode. NOTE: Ideally we must not set both private_pathset and public_pathset elements to generation mode for the same run. The reason is that either pathset generation is a long running process by itself. We do not want to allow for chaining of private and public transit pathsets one after the other and hence slow down the process of pathset generation. If both modes are set to generation only private pathsets are generated (just because its mode value is checked first) and then the program exits.
  3. The name of the input table to read ODs for pathset generation is specified in the <od_source/> element.
  4. The name of the output file to write the generated pathsets is specified in the <bulk_generation_output_file/> element. This file is created in the same directory where SimMobility is executed from.
    After editing the config file as required, we can run SimMobility as usual. During execution, the code, e.g., sim_mob::PrivatePathsetGenerator, looks for the mode values and generates pathsets for the ODs provided and outputs the same into the specified file.

5. Writing the pathset into the database

After the process completes, we need to manually import the generated pathsets into the corresponding pathset table, via a separated SQL query:

copy routechoice.<pathset_table> from '/path/to/generated/pathset/file' csv;

To know what is the name of your <pathset_table>, in case of private Pathset (it works similarly for the public transit Pathset), check the simrun_MidTerm.xml file, in particular the tag <config>/<db_proc_groups>/<proc_map>/<mapping> whose name is pvt_pathset and check the field procedure. Go into your database (you can use any databse application e.g., PgAdmin), and check the functions stored inside the public schema. You should find a function named as specified in the field procedure above. Open the declaration of the procedure and look for the FROM-part. There, you should find the name of the pathset_table.

6. Using the pathsets

If you want to use the pathsets, for example in the MidTerm withinday simulation, just set <private_pathset enabled="true" mode="normal" and <public_pathset enabled="true" mode="normal" and run SimMobility again.

Implementation details

This section explains the C++ code and structures used for the pathset generation and can be useful for user who need to change or optimize the implementation. All the other users can skip this.

The Pathset is represented in C++ with the class sim_mob::PathSet, which contains a set called pathChoices. This is a set of pointers to sim_mob::SinglePath objects. Each SinglePath contains a vector of sim_mob::WayPoint and is described by some measures, like travelCost, travelTime, etc.

Clone this wiki locally