mosstool.trip.generator.generate_from_od¶
Module Contents¶
Classes¶
generate trip from OD matrix. |
Functions¶
Data¶
API¶
- mosstool.trip.generator.generate_from_od.geo_coords(geo)¶
- mosstool.trip.generator.generate_from_od._get_mode(p1, p2)¶
- mosstool.trip.generator.generate_from_od._get_mode_with_distribution(partial_args: tuple[list[str], tuple[float, float, float, float, float, float, float, float, float, float, float]], p1: tuple[float, float], p2: tuple[float, float], profile: dict, seed: int = 0)¶
- mosstool.trip.generator.generate_from_od._match_aoi_unit(partial_args: tuple[list[Any]], aoi)¶
- mosstool.trip.generator.generate_from_od._generate_unit(partial_args: tuple[mosstool.map._map_util.const.np.ndarray, mosstool.map._map_util.const.np.ndarray, mosstool.map._map_util.const.np.ndarray, mosstool.map._map_util.const.np.ndarray, dict[int, list[dict[str, typing.Any]]], dict[int, dict[str, typing.Any]], dict[str, list[int]], int, typing.Any, list[float], int], get_mode_partial_args: tuple[list[str], tuple[float, float, float, float, float, float, float, float, float, float, float]], a_home_region: int, a_profile: dict[str, typing.Any], modes: list[typing.Union[typing.Literal[mosstool.trip.generator.generate_from_od._generate_unit.H], typing.Literal[mosstool.trip.generator.generate_from_od._generate_unit.W], typing.Literal[mosstool.trip.generator.generate_from_od._generate_unit.E], typing.Literal[mosstool.trip.generator.generate_from_od._generate_unit.O], typing.Literal[+]]], p_mode: list[float], seed: int)¶
- mosstool.trip.generator.generate_from_od._process_agent_unit(partial_args_tuple: tuple[tuple[mosstool.map._map_util.const.np.ndarray, mosstool.map._map_util.const.np.ndarray, mosstool.map._map_util.const.np.ndarray, mosstool.map._map_util.const.np.ndarray, dict[int, list[dict[str, typing.Any]]], dict[int, dict[str, typing.Any]], dict[str, list[int]], int, typing.Any, list[float], int], tuple[list[str], tuple[float, float, float, float, float, float, float, float, float, float, float]]], arg: tuple[int, int, int, dict[str, typing.Any], list[typing.Union[typing.Literal[H], typing.Literal[W], typing.Literal[E], typing.Literal[O], typing.Literal[+]]], list[float]])¶
- mosstool.trip.generator.generate_from_od._fill_sch_unit(partial_args: tuple[mosstool.map._map_util.const.np.ndarray, dict[int, list[dict[str, typing.Any]]], dict[int, dict[str, typing.Any]], dict[str, list[int]], int, typing.Any, list[float], int], get_mode_partial_args: tuple[list[str], tuple[float, float, float, float, float, float, float, float, float, float, float]], p_home: int, p_home_region: int, p_work: int, p_work_region: int, p_profile: dict[str, typing.Any], modes: list[typing.Union[typing.Literal[H], typing.Literal[W], typing.Literal[E], typing.Literal[mosstool.trip.generator.generate_from_od._fill_sch_unit.O], typing.Literal[+]]], p_mode: list[float], seed: int)¶
- mosstool.trip.generator.generate_from_od._fill_person_schedule_unit(partial_args_tuple: tuple[tuple[mosstool.map._map_util.const.np.ndarray, dict[int, list[dict[str, typing.Any]]], dict[int, dict[str, typing.Any]], dict[str, list[int]], int, typing.Any, list[float], int], tuple[list[str], tuple[float, float, float, float, float, float, float, float, float, float, float]]], arg: tuple[int, int, int, int, int, dict[str, typing.Any], list[typing.Union[typing.Literal[H], typing.Literal[W], typing.Literal[E], typing.Literal[O], typing.Literal[+]]], list[float], int])¶
- mosstool.trip.generator.generate_from_od.__all__¶
[‘TripGenerator’]
- class mosstool.trip.generator.generate_from_od.TripGenerator(m: mosstool.type.Map, pop_tif_path: Optional[str] = None, activity_distributions: Optional[dict] = None, driving_speed: float = 30 / 3.6, parking_fee: float = 20.0, driving_penalty: float = 0.0, subway_speed: float = 35 / 3.6, subway_penalty: float = 600.0, subway_expense: float = 10.0, bus_speed: float = 15 / 3.6, bus_penalty: float = 600.0, bus_expense: float = 5.0, bike_speed: float = 10 / 3.6, bike_penalty: float = 0.0, template_func: collections.abc.Callable[[], mosstool.type.Person] = default_person_template_generator, add_pop: bool = False, multiprocessing_chunk_size: int = 500, workers: int = cpu_count())¶
generate trip from OD matrix.
Initialization
Args:
m (Map): The Map.
pop_tif_path (str): path to population tif file.
activity_distributions (dict): human mobility mode and its probability. e.g. {“HWH”: 18.0, “HWH+”: 82.0,}. H for go home, W for go to work, O or + for other activities
driving_speed (float): vehicle speed(m/s) for traffic mode assignment.
parking_fee (float): money cost(¥) of parking a car for traffic mode assignment.
driving_penalty (float): extra cost(s) of vehicle for traffic mode assignment.
subway_speed (float): subway speed(m/s) for traffic mode assignment.
subway_penalty (float): extra cost(s) of subway for traffic mode assignment.
subway_expense (float): money cost(¥) of subway for traffic mode assignment.
bus_speed (float): bus speed(m/s) for traffic mode assignment.
bus_penalty (float): extra cost(s) of bus for traffic mode assignment.
bus_expense (float): money cost(¥) of bus for traffic mode assignment.
bike_speed (float): extra cost(s) of bike for traffic mode assignment.
bike_penalty (float): money cost(¥) of bike for traffic mode assignment.
template_func (Callable[[],Person]): The template function of generated person object, whose
schedules,homewill be replaced and others will be copied.add_pop (bool): Add population to aois.
multiprocessing_chunk_size (int): the maximum size of each multiprocessing chunk
workers (int): number of workers.
- _read_aois()¶
- _read_regions()¶
- _read_od_matrix()¶
- _match_aoi2region()¶
- _generate_mobi(agent_num: int = 10000, area_pops: Optional[list] = None, person_profiles: Optional[list] = None, seed: int = 0, max_chunk_size: int = 500)¶
- generate_persons(od_matrix: mosstool.map._map_util.const.np.ndarray, areas: geopandas.geodataframe.GeoDataFrame, available_trip_modes: list[str] = ['drive', 'walk', 'bus', 'subway', 'taxi'], departure_time_curve: Optional[list[float]] = None, area_pops: Optional[list] = None, person_profiles: Optional[list[dict]] = None, seed: int = 0, agent_num: Optional[int] = None) list[mosstool.type.Person]¶
Args:
od_matrix (numpy.ndarray): The OD matrix.
areas (GeoDataFrame): The area data. Must contain a ‘geometry’ column with geometric information and a defined
crsstring.available_trip_modes (list[str]): available trip modes for person schedules.
departure_time_curve (Optional[list[float]]): The departure time of a day (24h). The resolution must >=1h.
area_pops (list): list of populations in each area. If is not None, # of the persons departs from each home position is exactly equal to the given pop num.
person_profiles (Optional[list[dict]]): list of profiles in dict format.
seed (int): The random seed.
agent_num (int): number of agents to generate.
Returns:
list[Person]: The generated person objects.
- _get_driving_pos_dict() dict[tuple[int, int], mosstool.type.LanePosition]¶
- generate_public_transport_drivers(template_func: Optional[collections.abc.Callable[[], mosstool.type.Person]] = None, stop_duration_time: float = 30.0, seed: int = 0) list[mosstool.type.Person]¶
Args:
template_func (Optional[Callable[[],Person]]): The template function of generated person object, whose
schedules,homewill be replaced and others will be copied. If not provided, thetemp_funcprovided in__init__will be utilized.stop_duration_time (float): The duration time (in second) for bus at each stop.
seed (int): The random seed.
Returns:
list[Person]: The generated driver objects.
- _generate_schedules(input_persons: list[mosstool.type.Person], seed: int)¶
- fill_person_schedules(input_persons: list[mosstool.type.Person], od_matrix: mosstool.map._map_util.const.np.ndarray, areas: geopandas.geodataframe.GeoDataFrame, available_trip_modes: list[str] = ['drive', 'walk', 'bus', 'subway', 'taxi'], departure_time_curve: Optional[list[float]] = None, seed: int = 0) list[mosstool.type.Person]¶
Generate person schedules.
Args:
input_persons (list[Person]): Input Person objects.
od_matrix (numpy.ndarray): The OD matrix.
areas (GeoDataFrame): The area data. Must contain a ‘geometry’ column with geometric information and a defined
crsstring.available_trip_modes (Optional[list[str]]): available trip modes for person schedules.
departure_time_curve (Optional[list[float]]): The departure time of a day (24h). The resolution must >=1h.
seed (int): The random seed.
Returns:
list[Person]: The person objects with generated schedules.
- generate_taxi_drivers(template_func: Optional[collections.abc.Callable[[], mosstool.type.Person]] = None, parking_positions: Optional[list[Union[mosstool.type.LanePosition, mosstool.type.AoiPosition]]] = None, agent_num: Optional[int] = None, seed: int = 0) list[mosstool.type.Person]¶
Args:
template_func (Optional[Callable[[],Person]]): The template function of generated person object, whose
schedules,homewill be replaced and others will be copied. If not provided, thetemp_funcprovided in__init__will be utilized.parking_positions (Optional[list[Union[LanePosition,AoiPosition]]]): The parking positions of each taxi.
agent_num (Optional[int]): The taxi driver num.
seed (int): The random seed.
Returns:
list[Person]: The generated driver objects.