Skip to main content

Trip Generators

Random Generators

from mosstool.trip.generator import RandomGenerator

RandomGenrator generate specified number of persons with random departure times and random visiting positions.

The initialization function of RandomGenerator.

Args of RandomGenerator.__init__

  1. m (Map): the map
  2. position_modes (List[PositionMode]): the schedules generated will follow the position modes in this list, the generated person will visit modes of positions as specified.
  3. trip_mode (TripMode): the target trip mode
  4. template (Person): the template of generated person object, whose schedules, home will be replaced and others will be copied

This function Generate persons following uniform distribution

Args of RandomGenerator.uniform

  1. num (int): the number of person objects to generate
  2. first_departure_time_range (Tuple[float, float]): the range of the first departure time (uniform random sampling)
  3. schedule_interval_range (Tuple[float, float]): the range of the interval between schedules (uniform random sampling)
  4. seed (int): the random seed. Defaults to None
  5. start_id (int): the start id of the generated person objects. Defaults to None. If None, the id will be NOT set

OD-Matrix Generators

This model generate OD-matrix for trip generation.

Gravity model

from mosstool.trip.generator import GravityGenerator

Args of GravityGenerator.__init__

  1. Lambda, Alpha, Beta, Gamma (float): the parameters of Gravity model.

Args of GravityGenerator.load_area

  1. area (GeoDataFrame): the area data as origins and destinations.

Args of GravityGenerator.generate

  1. pop (list[int]): the population of each area, consistent with the order of area.

Realistic Generators by Diffusion Models Based on Public Data

from mosstool.trip.generator import AigcGenerator

Args of AigcGenerator.__init__

  1. Lambda, Alpha, Beta, Gamma (float): the parameters of Gravity model.

Args of AigcGenerator.set_satetoken

  1. satetoken (str): set the satetoken for the generator, token is used for World_Imagery, can be applied from ArcGIS (https://www.arcgis.com/home/item.html?id=10df2279f9684e4a9f6a7f08febac2a9)

Args of AigcGenerator.load_area

  1. area (GeoDataFrame): the area data as origins and destinations.

OD-Matrix Based Generators

from mosstool.trip.generator.generate_from_od import TripGenerator

TripGenerator generate specified number of persons according to input OD matrix.

Args of TripGenerator.__init__

  1. m (Map): the map

  2. pop_tif_path (str): path of world population TIFF

  3. template (Person): the template of generated person object, whose schedules, home will be replaced and others will be copied

  4. add_pop (bool): if true and pop_tif_path is valid, population of AOI will be calculated

  5. workers: (int): number of workers for multiprocessing of adding populations

Args of TripGenerator.generate_persons

  1. od_matrix (numpy.ndarray): the OD matrix
  2. areas (GeoDataFrame): the area data as origins and destinations, consistent with the order of od_matrix.
  3. departure_time_curve(list[float]): the departure time of a day (24h). The resolution must >=1h
  4. agent_num: (int): the number of person objects to generate
  5. seed (int): the random seed. Defaults to 0