Skip to content

Commit

Permalink
migrate person.v1 to person.v2
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchenplus committed Sep 27, 2024
1 parent e107f75 commit 03d0480
Show file tree
Hide file tree
Showing 14 changed files with 389 additions and 191 deletions.
7 changes: 4 additions & 3 deletions examples/random_persons.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mosstool.trip.generator import PositionMode, RandomGenerator, DEFAULT_PERSON
from mosstool.trip.generator import (V1_DEFAULT_PERSON, V2_DEFAULT_PERSON,
PositionMode, RandomGenerator)
from mosstool.trip.route import RoutingClient, pre_route
from mosstool.type import Map, Persons, TripMode, Person
from mosstool.type import Map, TripMode, Person, Persons
from mosstool.util.format_converter import pb2json


Expand All @@ -10,7 +11,7 @@ async def main():
m.ParseFromString(f.read())

template = Person()
template.CopyFrom(DEFAULT_PERSON)
template.CopyFrom(V1_DEFAULT_PERSON)
template.vehicle_attribute.model = "normal"
template.pedestrian_attribute.model = "normal"
rg = RandomGenerator(
Expand Down
31 changes: 26 additions & 5 deletions mosstool/map/_map_util/aois/append_aois_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,25 @@
import shapely.ops as ops
from scipy.spatial import KDTree
from shapely.affinity import scale
from shapely.geometry import (LineString, MultiLineString, MultiPoint,
MultiPolygon, Point, Polygon)
from shapely.geometry import (
LineString,
MultiLineString,
MultiPoint,
MultiPolygon,
Point,
Polygon,
)
from shapely.strtree import STRtree

from ....type import AoiType
from ..._util.angle import abs_delta_angle, delta_angle
from ..._util.line import (connect_line_string, get_line_angle,
get_start_vector, line_extend, offset_lane)
from ..._util.line import (
connect_line_string,
get_line_angle,
get_start_vector,
line_extend,
offset_lane,
)
from .utils import geo_coords

# ATTENTION: In order to achieve longer distance POI merging, the maximum recursion depth needs to be modified.
Expand Down Expand Up @@ -1866,12 +1877,17 @@ def add_aoi_to_map(
input_pois: list,
input_stops: list,
bbox,
merge_aoi: bool,
dis_gate: float = 30.0,
projstr: Optional[str] = None,
shp_path: Optional[str] = None,
workers: int = 32,
):
"""match AOIs to lanes"""
global aoi_uid, d_matcher, w_matcher, road_lane_matcher
global D_DIS_GATE, D_HUGE_GATE, W_DIS_GATE, W_HUGE_GATE, LENGTH_PER_DOOR, MAX_DOOR_NUM, AOI_GATE_OFFSET
W_DIS_GATE = dis_gate
D_DIS_GATE = W_DIS_GATE + EXTRA_DIS_GATE
d_matcher, w_matcher, road_lane_matcher = (
matchers["drive"],
matchers["walk"],
Expand All @@ -1882,7 +1898,9 @@ def add_aoi_to_map(
# raw POIs
raw_pois = {doc["id"]: doc for doc in input_pois}

aois = _add_aoi(aois=input_aois, stops=input_stops, workers=workers, merge_aoi=True)
aois = _add_aoi(
aois=input_aois, stops=input_stops, workers=workers, merge_aoi=merge_aoi
)
added_input_poi = []
for _, aoi in aois.items():
added_input_poi.extend(aoi["external"].get("ex_poi_ids", []))
Expand All @@ -1903,6 +1921,7 @@ def add_sumo_aoi_to_map(
input_stops: list,
projstr: str,
merge_aoi: bool,
dis_gate: float = 30.0,
workers: int = 32,
):
"""for SUMO converter, match AOI to lanes"""
Expand All @@ -1914,6 +1933,8 @@ def add_sumo_aoi_to_map(
)
global D_DIS_GATE, D_HUGE_GATE, W_DIS_GATE, W_HUGE_GATE, LENGTH_PER_DOOR, MAX_DOOR_NUM, AOI_GATE_OFFSET
global aoi_uid
W_DIS_GATE = dis_gate
D_DIS_GATE = W_DIS_GATE + EXTRA_DIS_GATE
# AOI UID
aoi_uid = AOI_START_ID
# projection parameter
Expand Down
5 changes: 3 additions & 2 deletions mosstool/map/_map_util/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
MIN_WALK_CONNECTED_COMPONENT = 5 # Minimum length of connected component of sidewalk
DEFAULT_ROAD_SPLIT_LENGTH = 20 # Default road shortening length
DEFAULT_JUNCTION_WALK_LANE_WIDTH = 4.0 # Default sidewalk width
D_DIS_GATE = 35
W_DIS_GATE = 30
# D_DIS_GATE = 35
# W_DIS_GATE = 30
EXTRA_DIS_GATE = 5
STOP_DIS_GATE = 30
STOP_HUGE_GATE = 50
D_HUGE_GATE = 505
Expand Down
11 changes: 10 additions & 1 deletion mosstool/map/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def __init__(
green_time: float = 30.0,
yellow_time: float = 5.0,
strict_mode: bool = False,
merge_aoi: bool = True,
aoi_matching_distance_threshold: float = 30.0,
output_lane_length_check: bool = False,
workers: int = cpu_count(),
):
Expand All @@ -88,7 +90,9 @@ def __init__(
- traffic_light_mode (str): fixed time traffic-light generation mode. `green_red` means only green and red light will be generated, `green_yellow_red` means there will be yellow light between green and red light, `green_yellow_clear_red` add extra pedestrian clear red light.
- green_time (float): green time
- strict_mode (bool): when enabled, causes the program to exit whenever a warning occurs
- output_lane_length_check (bool): when enabled, will do value checks lane lengths in output map.
- merge_aoi (bool): merge nearby aois
- aoi_matching_distance_threshold (float): Only AOIs whose distance to the road network is less than this value will be added to the map.
- output_lane_length_check (bool): when enabled, will do value checks lane lengths in output map
- yellow_time (float): yellow time
- workers (int): number of workers
"""
Expand All @@ -113,6 +117,9 @@ def __init__(
self.landuse_shp_path = landuse_shp_path
self.traffic_light_min_direction_group = traffic_light_min_direction_group
self.strict_mode = strict_mode
self.merge_aoi = merge_aoi
self.aoi_matching_distance_threshold = aoi_matching_distance_threshold
# TODO:加入阈值
self.output_lane_length_check = output_lane_length_check
self.workers = workers
self.traffic_light_mode: Union[
Expand Down Expand Up @@ -4106,6 +4113,8 @@ def _add_input_aoi(self):
input_pois=pois,
input_stops=stops,
bbox=(self.min_lat, self.min_lon, self.max_lat, self.max_lon),
merge_aoi=self.merge_aoi,
dis_gate=self.aoi_matching_distance_threshold,
projstr=self.proj_str,
shp_path=self.landuse_shp_path,
)
Expand Down
5 changes: 3 additions & 2 deletions mosstool/trip/generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from .generate_from_od import TripGenerator
from .gravity import GravityGenerator
from .random import PositionMode, RandomGenerator
from .template import DEFAULT_PERSON
from .template import V1_DEFAULT_PERSON,V2_DEFAULT_PERSON

__all__ = [
"DEFAULT_PERSON",
"V1_DEFAULT_PERSON",
"V2_DEFAULT_PERSON",
"RandomGenerator",
"PositionMode",
"GravityGenerator",
Expand Down
30 changes: 15 additions & 15 deletions mosstool/trip/generator/_util/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pycityproto.city.geo.v2.geo_pb2 as geov2
import pycityproto.city.map.v2.map_pb2 as mapv2
import pycityproto.city.person.v1.person_pb2 as personv1
import pycityproto.city.person.v2.person_pb2 as personv2
import pycityproto.city.trip.v2.trip_pb2 as tripv2

DIS_CAR = 1000
Expand Down Expand Up @@ -37,13 +37,13 @@
]
PT_START_ID = 1_0000_0000
PRIMARY_SCHOOL, JUNIOR_HIGH_SCHOOL, HIGH_SCHOOL, COLLEGE, BACHELOR, MASTER, DOCTOR = (
personv1.EDUCATION_PRIMARY_SCHOOL,
personv1.EDUCATION_JUNIOR_HIGH_SCHOOL,
personv1.EDUCATION_HIGH_SCHOOL,
personv1.EDUCATION_COLLEGE,
personv1.EDUCATION_BACHELOR,
personv1.EDUCATION_MASTER,
personv1.EDUCATION_DOCTOR,
personv2.EDUCATION_PRIMARY_SCHOOL,
personv2.EDUCATION_JUNIOR_HIGH_SCHOOL,
personv2.EDUCATION_HIGH_SCHOOL,
personv2.EDUCATION_COLLEGE,
personv2.EDUCATION_BACHELOR,
personv2.EDUCATION_MASTER,
personv2.EDUCATION_DOCTOR,
)
EDUCATION_LEVELS = [
PRIMARY_SCHOOL,
Expand All @@ -57,19 +57,19 @@
# probabilities
EDUCATION_STATS = [1 / len(EDUCATION_LEVELS) for _ in range(len(EDUCATION_LEVELS))]
CONSUMPTION_LEVELS = [
personv1.CONSUMPTION_LOW,
personv1.CONSUMPTION_RELATIVELY_LOW,
personv1.CONSUMPTION_MEDIUM,
personv1.CONSUMPTION_RELATIVELY_HIGH,
personv1.CONSUMPTION_HIGH,
personv2.CONSUMPTION_LOW,
personv2.CONSUMPTION_RELATIVELY_LOW,
personv2.CONSUMPTION_MEDIUM,
personv2.CONSUMPTION_RELATIVELY_HIGH,
personv2.CONSUMPTION_HIGH,
]
# probabilities
CONSUMPTION_STATS = [
1 / len(CONSUMPTION_LEVELS) for _ in range(len(CONSUMPTION_LEVELS))
]
GENDERS = [
personv1.GENDER_FEMALE,
personv1.GENDER_MALE,
personv2.GENDER_FEMALE,
personv2.GENDER_MALE,
]
# probabilities
GENDER_STATS = [1 / len(GENDERS) for _ in range(len(GENDERS))]
Expand Down
Loading

0 comments on commit 03d0480

Please sign in to comment.