Skip to content

Commit

Permalink
add ProbabilisticTemplateGenerator for person template
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchenplus committed Sep 28, 2024
1 parent c7928c6 commit b43e546
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 512 deletions.
4 changes: 3 additions & 1 deletion examples/gen_pt_drivers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from mosstool.trip.generator.generate_from_od import TripGenerator
from mosstool.trip.generator import (TripGenerator,
default_bus_template_generator)
from mosstool.type import Map, Persons

# map from `./examples/add_pt_to_map.py` and `./examples/add_pt_post_process.py`
Expand All @@ -7,6 +8,7 @@
m.ParseFromString(f.read())
tg = TripGenerator(
m=m,
template_func=default_bus_template_generator,
)
bus_drivers = tg.generate_public_transport_drivers()
persons_output_path = "data/temp/bus_drivers.pb"
Expand Down
15 changes: 7 additions & 8 deletions examples/random_persons.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from mosstool.trip.generator import (DEFAULT_PERSON, PositionMode,
from mosstool.trip.generator import (PositionMode,
ProbabilisticTemplateGenerator,
RandomGenerator)
from mosstool.trip.route import RoutingClient, pre_route
from mosstool.type import Map, Person, Persons, TripMode
Expand All @@ -9,18 +10,15 @@ async def main():
with open("data/temp/map.pb", "rb") as f:
m = Map()
m.ParseFromString(f.read())

template = Person()
template.CopyFrom(DEFAULT_PERSON)
template.vehicle_attribute.model = "normal"
template.pedestrian_attribute.model = "normal"
pg = ProbabilisticTemplateGenerator(
headway_values=[1.5, 2, 2.5], headway_probabilities=[1, 1, 1]
)
rg = RandomGenerator(
m,
[PositionMode.LANE, PositionMode.LANE],
TripMode.TRIP_MODE_DRIVE_ONLY,
template=template,
template_func=pg.template_generator,
)

persons = rg.uniform(
num=100,
first_departure_time_range=(8 * 3600, 9 * 3600),
Expand All @@ -43,6 +41,7 @@ async def main():
with open("data/temp/persons.json", "w") as f:
f.write(pb2json(pb))


if __name__ == "__main__":
import asyncio

Expand Down
8 changes: 6 additions & 2 deletions mosstool/trip/generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
from .generate_from_od import TripGenerator
from .gravity import GravityGenerator
from .random import PositionMode, RandomGenerator
from .template import DEFAULT_PERSON
from .template import (ProbabilisticTemplateGenerator,
default_bus_template_generator,
default_vehicle_template_generator)

__all__ = [
"DEFAULT_PERSON",
"ProbabilisticTemplateGenerator",
"default_vehicle_template_generator",
"default_bus_template_generator",
"RandomGenerator",
"PositionMode",
"GravityGenerator",
Expand Down
Loading

0 comments on commit b43e546

Please sign in to comment.