Skip to content

Commit

Permalink
add tripmode TAXI
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchenplus committed Oct 23, 2024
1 parent 7ca938e commit e7161b6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test.py
TODO
.vscode
docs/
ignore/
Expand Down
1 change: 1 addition & 0 deletions mosstool/trip/generator/_util/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}
BUS = tripv2.TRIP_MODE_BUS_WALK
CAR = tripv2.TRIP_MODE_DRIVE_ONLY
TAXI = tripv2.TRIP_MODE_TAXI
BIKE = tripv2.TRIP_MODE_BIKE_WALK
WALK = tripv2.TRIP_MODE_WALK_ONLY
LANE_TYPE_DRIVING = mapv2.LANE_TYPE_DRIVING
Expand Down
13 changes: 13 additions & 0 deletions mosstool/trip/generator/_util/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ def gen_profiles(
)
return profiles

def recalculate_trip_modes(profile: dict,trip_modes:List[int])->List[int]:
res_modes = np.array([m for m in trip_modes], dtype=np.uint8)
if (
profile.get("consumption",-1)
in {
personv2.CONSUMPTION_LOW,
personv2.CONSUMPTION_RELATIVELY_LOW,
}
or not _in_range(profile.get("age",24), 18, 70)
):
# no car to drive
res_modes[np.where(res_modes == CAR)] = TAXI
return [m for m in res_modes]

def recalculate_trip_mode_prob(profile: dict, V: np.ndarray):
"""
Expand Down
7 changes: 4 additions & 3 deletions mosstool/trip/generator/generate_from_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ...util.format_converter import dict2pb, pb2dict
from ._util.const import *
from ._util.utils import (extract_HWEO_from_od_matrix, gen_bus_drivers,
gen_departure_times, gen_profiles,
gen_departure_times, gen_profiles,recalculate_trip_modes,
recalculate_trip_mode_prob)
from .template import default_vehicle_template_generator

Expand Down Expand Up @@ -83,11 +83,12 @@ def _get_mode_with_distribution(
V_bicycle = -0.1185 * bicycle_duration / 60
V = np.array([V_bus, V_subway, V_fuel, V_elec, V_bicycle])
V = np.exp(V)
_all_trip_modes = recalculate_trip_modes(profile,ALL_TRIP_MODES)
V = recalculate_trip_mode_prob(profile, V)
V = V / sum(V)
rng = np.random.default_rng(seed)
choice_index = rng.choice(len(V), p=V)
return ALL_TRIP_MODES[choice_index]
return _all_trip_modes[choice_index]


def _match_aoi_unit(projector, aoi):
Expand Down Expand Up @@ -413,7 +414,7 @@ def __init__(
bus_penalty: float = 600.0,
bus_expense: float = 5.0,
bike_speed: float = 10 / 3.6,
bike_penalty: float = 0.9,
bike_penalty: float = 0.0,
template_func: Callable[[], Person] = default_vehicle_template_generator,
add_pop: bool = False,
multiprocessing_chunk_size: int = 500,
Expand Down
1 change: 1 addition & 0 deletions mosstool/trip/route/preroute.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

_TYPE_MAP = {
TripMode.TRIP_MODE_DRIVE_ONLY: RouteType.ROUTE_TYPE_DRIVING,
TripMode.TRIP_MODE_TAXI: RouteType.ROUTE_TYPE_DRIVING,
TripMode.TRIP_MODE_BIKE_WALK: RouteType.ROUTE_TYPE_WALKING,
TripMode.TRIP_MODE_BUS_WALK: RouteType.ROUTE_TYPE_BY_BUS,
TripMode.TRIP_MODE_WALK_ONLY: RouteType.ROUTE_TYPE_WALKING,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mosstool"
version = "1.0.10"
version = "1.0.11"
description = "MObility Simulation System toolbox "
authors = ["Jun Zhang <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit e7161b6

Please sign in to comment.