systragroup / quetzal

Quetzal is a modeling library designed for transport planning and traffic forecasts
Other
43 stars 9 forks source link

faster and correct assignment method #100

Closed marlinarnz closed 1 year ago

marlinarnz commented 1 year ago

Dear developers, Recently, I had problems with quetzal's assignment methods. Both, the assign and fast_assign methods, produced wrong results, i.e. a network load that did not correspond to the pkm computed in the LoS table by a magnitude of up to ten (depending on the mode). Hence, I tried around and found a method that works without errors and takes less than half the time. It's a vectorised method instead of the sequential method as currently implemented:

for seg in tqdm(sm.segments):
    sm.links[seg] = sm.pt_los[['link_path', seg]].explode('link_path')\
        .groupby('link_path').sum()[seg].fillna(0)
    sm.road_links[seg] = sm.car_los[['link_path', seg]].explode('link_path')\
        .groupby('link_path').sum()[seg].fillna(0)
sm.links['volume'] = sm.links[sm.segments].sum(axis=1)
sm.road_links['volume'] = sm.road_links[sm.segments].sum(axis=1)

The LoS table needs computed volumes and must be split in car and PT to update car_los and pt_los. It takes 6.26 minutes per demand segment for a 15 million rows LoS table. The fast_assign method takes 14.5 minutes per segment.

sboivinsystra commented 1 year ago

Hello, we found an error in the functions analysismodel.analysis_pt_length and analysis_car_length.

it returned false pt_los['in_vehicle_length] car_los['in_vehicle_length] when there was NaN length into the links and road_links.

fast_assign work fine handling thoses nan and I have the same result using your method and fast_assign.