mosstool.trip.generator.random

Module Contents

Classes

PositionMode

RandomGenerator

Random trip generator

Data

API

mosstool.trip.generator.random.__all__

[‘PositionMode’, ‘RandomGenerator’]

class mosstool.trip.generator.random.PositionMode

Bases: enum.Enum

AOI

0

LANE

1

class mosstool.trip.generator.random.RandomGenerator(m: pycityproto.city.map.v2.map_pb2.Map, position_modes: list[mosstool.trip.generator.random.PositionMode], trip_mode: pycityproto.city.trip.v2.trip_pb2.TripMode, template_func: collections.abc.Callable[[], pycityproto.city.person.v2.person_pb2.Person] = default_person_template_generator)

Random trip generator

Initialization

Args:

  • m (Map): The Map.

  • position_modes (list[PositionMode]): The schedules generated will follow the position modes in this list. For example, if the list is [PositionMode.AOI, PositionMode.LANE, PositionMode.AOI], the generated person will start from an AOI, then go to a lane, and finally go to an AOI.

  • trip_mode (TripMode): The target trip mode.

  • template_func (Callable[[],Person]): The template function of generated person object, whose schedules, home will be replaced and others will be copied.

_rand_position(candidates: Union[list[pycityproto.city.map.v2.map_pb2.Aoi], list[pycityproto.city.map.v2.map_pb2.Lane]])
uniform(num: int, first_departure_time_range: tuple[float, float], schedule_interval_range: tuple[float, float], seed: Optional[int] = None, start_id: Optional[int] = None) list[pycityproto.city.person.v2.person_pb2.Person]

Generate a person object by uniform random sampling

Args:

  • num (int): The number of person objects to generate.

  • first_departure_time_range (tuple[float, float]): The range of the first departure time (uniform random sampling).

  • schedule_interval_range (tuple[float, float]): The range of the interval between schedules (uniform random sampling).

  • seed (Optional[int], optional): The random seed. Defaults to None.

  • start_id (Optional[int], optional): The start id of the generated person objects. Defaults to None. If None, the id will be NOT set.

Returns:

  • list[Person]: The generated person objects.