Skip to content

Commit

Permalink
delete large commented codes in transit components
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-sijia committed Jul 11, 2024
1 parent 7aed0f6 commit 2e77132
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 239 deletions.
189 changes: 3 additions & 186 deletions tm2py/components/network/transit/transit_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ def calc_segment_cost(transit_volume: float, capacity, segment) -> float:
return 0.0

line = segment.line
# segment_capacity = time_period_capacity(
# line.vehicle.total_capacity, line.headway, time_period_duration
# )
# seated_capacity = time_period_capacity(
# line.vehicle.seated_capacity, line.headway, time_period_duration
# )

seated_capacity = (
line.vehicle.seated_capacity * {time_period_duration} * 60 / line.headway
Expand All @@ -114,8 +108,6 @@ def calc_segment_cost(transit_volume: float, capacity, segment) -> float:

return normalized_crowded_cost

# return textwrap.dedent(inspect.getsource(calc_segment_cost))

return textwrap.dedent(inspect.getsource(calc_segment_cost)).format(
time_period_duration=time_period_duration, weights=weights
)
Expand Down Expand Up @@ -201,65 +193,6 @@ def calc_segment_cost(transit_volume: float, capacity, segment) -> float:
)


# def calc_segment_cost_curry(func, time_period_duration: float, weights):
# """
# curry function for calc_segment_cost
# """
# return (lambda y: func(time_period_duration, weights, y))

# def calc_segment_cost(
# time_period_duration: float, weights, transit_volume: float, segment
# ) -> float:
# """Calculates crowding factor for a segment.

# Toronto implementation limited factor between 1.0 and 10.0.
# For use with Emme Capacitated assignment normalize by subtracting 1

# Args:
# time_period_duration(float): time period duration in minutes
# weights (_type_): transit capacity weights
# segment_pax (float): transit passengers for the segment for the time period
# segment: emme line segment

# Returns:
# float: crowding factor for a segment
# """

# if transit_volume == 0:
# return 0.0

# line = segment.line
# segment_capacity = time_period_capacity(
# line.vehicle.total_capacity, line.headway, time_period_duration
# )
# seated_capacity = time_period_capacity(
# line.vehicle.seated_capacity, line.headway, time_period_duration
# )

# seated_pax = min(transit_volume, seated_capacity)
# standing_pax = max(transit_volume - seated_pax, 0)

# seated_cost = (
# weights.min_seat
# + (weights.max_seat - weights.min_seat)
# * (transit_volume / segment_capacity) ** weights.power_seat
# )

# standing_cost = (
# weights.min_stand
# + (weights.max_stand - weights.min_stand)
# * (transit_volume / segment_capacity) ** weights.power_stand
# )

# crowded_cost = (seated_cost * seated_pax + standing_cost * standing_pax) / (
# transit_volume + 0.01
# )

# normalized_crowded_cost = max(crowded_cost - 1, 0)

# return normalized_crowded_cost


def calc_total_offs(line) -> float:
"""Calculate total alightings for a line.
Expand Down Expand Up @@ -445,57 +378,6 @@ def calc_headway(transit_volume, transit_boardings, headway, capacity, segment):
)


# def calc_headway_curry(func, time_period_duration: float, eawt_weights, mode_config, use_fares):
# """
# curry function for calc_segment_cost
# """
# return lambda y: func(time_period_duration, eawt_weights, mode_config, y, use_fares)

# def calc_headway(
# time_period_duration: float,
# eawt_weights,
# mode_config,
# segment,
# use_fares: bool = False,
# ):
# """Calculate perceived (???) headway updated by ... and extra added wait time.

# # TODO Document more fully.

# Args:
# time_period_duration(float): time period duration in minutes
# segment: Emme Transit segment object
# eawt_weights:
# mode_config:
# use_fares (bool): if true, will use fares

# Returns:
# _type_: _description_
# """
# # QUESTION FOR INRO: Kevin separately put segment.line.headway and headway as an arg.
# # Would they be different? Why?
# # TODO: Either can we label the headways so it is clear what is diff about them or just use single value?

# _segment_capacity = time_period_capacity(
# segment.line.headway, segment.line.vehicle.total_capacity, time_period_duration
# )

# _extra_added_wait_time = calc_extra_wait_time(
# segment,
# _segment_capacity,
# eawt_weights,
# mode_config,
# use_fares,
# )

# _adjusted_headway = calc_adjusted_headway(
# segment,
# _segment_capacity,
# )

# return _adjusted_headway + _extra_added_wait_time


EmmeTransitJourneyLevelSpec = List[
Dict[
str,
Expand Down Expand Up @@ -565,32 +447,13 @@ def run(self):
# TODO I think the demand import part should be outside of the time period loop
if self.controller.config.warmstart.warmstart:
# import transit demands
print("running uncongested transit assignment with warmstart demand")
print(
"running uncongested transit assignment with warmstart demand"
)
self.sub_components["prepare transit demand"].run()
self.run_transit_assign(
time_period, use_ccr, congested_transit_assignment
)
# TODO: run skim
# TODO: trim_demand
# congested_transit_assignment = self.config.congested_transit_assignment
# # apply peaking factor
# if self.config.congested.use_peaking_factor:
# path_boardings = self.get_abs_path(
# self.config.output_transit_boardings_path
# )
# ea_df_path = path_boardings.format(period='ea_pnr')
# if (time_period.lower() == 'am') and (os.path.isfile(ea_df_path)==False):
# raise Exception("run ea period first to account for the am peaking factor")
# if (time_period.lower() == 'am') and (os.path.isfile(ea_df_path)==True):
# print("peaking_factor")
# ea_df = pd.read_csv(ea_df_path)
# self._apply_peaking_factor(time_period, ea_df=ea_df)
# if (time_period.lower() == 'pm'):
# self._apply_peaking_factor(time_period)
# print("congested")
# self.run_transit_assign(time_period, use_ccr, congested_transit_assignment)
# if self.config.congested.use_peaking_factor and (time_period.lower() == 'ea'):
# self._apply_peaking_factor(time_period)
else:
self.transit_emmebank.zero_matrix # TODO: need further test
# TODO is transit assignment needed for skimming?
Expand All @@ -608,14 +471,6 @@ def run(self):
# import transit demands
self.sub_components["prepare transit demand"].run()

# if (self.config.congested.trim_demand_before_congested_transit_assignment and
# congested_transit_assignment):
# use_ccr = False
# congested_transit_assignment = False
# self.run_transit_assign(time_period, use_ccr, congested_transit_assignment)
# #TODO: run skim
# #TODO: trim_demand

self.run_transit_assign(
time_period, use_ccr, congested_transit_assignment
)
Expand Down Expand Up @@ -781,35 +636,9 @@ def _run_ccr_assign(self, time_period: str) -> None:
_tclass_specs = [tclass.emme_transit_spec for tclass in transit_classes]
_tclass_names = [tclass.name for tclass in transit_classes]

# NOTE TO SIJIA
# If sending the actual function doesn't work in EMME and its needs the TEXT of the
# function, then you can send it using
#
# put at top of code:
# import inspect.getsource
#
# replace _cost_func["python_function"]:... with
# "python_function": inspect.getsource(partial.crowded_segment_cost(_duration, _ccr_weights))
#
# do similar with _headway_cost_function, etc.

# segment_curry = calc_segment_cost_curry(
# calc_segment_cost, _duration, _ccr_weights
# )

# headway_curry = calc_headway_curry(
# calc_headway,
# _duration,
# _eawt_weights,
# _mode_config,
# use_fares=self.config.use_fares,
# )

_cost_func = {
"segment": {
"type": "CUSTOM",
# "python_function": textwrap.dedent(inspect.getsource(segment_curry)),
# "python_function": textwrap.dedent(inspect.getsource(lambda y: calc_segment_cost(_duration, _ccr_weights, y))),
"python_function": func_returns_crowded_segment_cost(
_duration, _ccr_weights
),
Expand All @@ -818,7 +647,6 @@ def _run_ccr_assign(self, time_period: str) -> None:
},
"headway": {
"type": "CUSTOM",
# "python_function": textwrap.dedent(inspect.getsource(headway_curry)),
"python_function": func_returns_calc_updated_perceived_headway(
_duration,
_eawt_weights,
Expand Down Expand Up @@ -997,7 +825,6 @@ def _export_boardings_by_line(self, time_period: str) -> None:
mode = line.mode
for segment in line.segments(include_hidden=True):
boardings += segment.transit_boardings
# total_board = sum(seg.transit_boardings for seg in line.segments)
out_file.write(
",".join(
[
Expand Down Expand Up @@ -1541,8 +1368,6 @@ def emme_transit_spec(self) -> EmmeTransitSpec:

@property
def _demand_matrix(self) -> str:
# if self._iteration < 1:
# return 'ms"zero"' # zero demand matrix
return f'mf"TRN_{self._class_config.skim_set_id}_{self._time_period}"'

def _get_used_mode_ids(self, modes: List[TransitModeConfig]) -> List[str]:
Expand Down Expand Up @@ -1916,7 +1741,6 @@ def _journey_levels(self) -> EmmeTransitJourneyLevelSpec:
"next_journey_level": len(new_journey_levels) + 2,
},
{"mode": "w", "next_journey_level": i + 2},
## {'mode': 'p', 'next_journey_level': len(new_journey_levels)+2},
{
"mode": "k",
"next_journey_level": len(new_journey_levels) + 2,
Expand All @@ -1940,7 +1764,6 @@ def _journey_levels(self) -> EmmeTransitJourneyLevelSpec:
"mode": "w",
"next_journey_level": len(new_journey_levels) + 2,
},
## {'mode': 'p', 'next_journey_level': len(new_journey_levels)+2},
{"mode": "k", "next_journey_level": 1},
]
)
Expand All @@ -1964,7 +1787,6 @@ def _journey_levels(self) -> EmmeTransitJourneyLevelSpec:
"mode": "w",
"next_journey_level": len(new_journey_levels) + 2,
},
## {'mode': 'p', 'next_journey_level': len(new_journey_levels)+2},
{"mode": "k", "next_journey_level": 1},
]
)
Expand All @@ -1988,7 +1810,6 @@ def _journey_levels(self) -> EmmeTransitJourneyLevelSpec:
"mode": "w",
"next_journey_level": len(new_journey_levels) + 2,
},
## {'mode': 'p', 'next_journey_level': len(new_journey_levels)+2},
{
"mode": "k",
"next_journey_level": len(new_journey_levels) + 2,
Expand Down Expand Up @@ -2068,7 +1889,6 @@ def _journey_levels(self) -> EmmeTransitJourneyLevelSpec:
"next_journey_level": len(new_journey_levels) + 2,
},
{"mode": "w", "next_journey_level": i + 1},
## {'mode': 'p', 'next_journey_level': len(new_journey_levels)+2},
{
"mode": "k",
"next_journey_level": len(new_journey_levels) + 1,
Expand All @@ -2092,7 +1912,6 @@ def _journey_levels(self) -> EmmeTransitJourneyLevelSpec:
"mode": "w",
"next_journey_level": len(new_journey_levels) + 2,
},
## {'mode': 'p', 'next_journey_level': len(new_journey_levels)+2},
{
"mode": "k",
"next_journey_level": len(new_journey_levels) + 2,
Expand All @@ -2119,7 +1938,6 @@ def _journey_levels(self) -> EmmeTransitJourneyLevelSpec:
"mode": "w",
"next_journey_level": len(new_journey_levels) + 2,
},
## {'mode': 'p', 'next_journey_level': len(new_journey_levels)+2},
{
"mode": "k",
"next_journey_level": len(new_journey_levels) + 2,
Expand All @@ -2146,7 +1964,6 @@ def _journey_levels(self) -> EmmeTransitJourneyLevelSpec:
"mode": "w",
"next_journey_level": len(new_journey_levels) + 2,
},
## {'mode': 'p', 'next_journey_level': len(new_journey_levels)+2},
{
"mode": "k",
"next_journey_level": len(new_journey_levels) + 2,
Expand Down
25 changes: 0 additions & 25 deletions tm2py/components/network/transit/transit_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,21 +793,6 @@ def run(self):
faresystems, faresystem_groups, network
)
self.save_journey_levels("ALLPEN", journey_levels)
# local_modes = []
# premium_modes = []
# for mode in self.config.modes:
# if mode.type == "LOCAL":
# local_modes.extend(mode_map[mode.mode_id])
# if mode.type == "PREMIUM":
# premium_modes.extend(mode_map[mode.mode_id])
# local_levels = self.filter_journey_levels_by_mode(
# local_modes, journey_levels
# )
# self.save_journey_levels("BUS", local_levels)
# premium_levels = self.filter_journey_levels_by_mode(
# premium_modes, journey_levels
# )
# self.save_journey_levels("PREM", premium_levels)

except Exception as error:
self._log.append({"type": "text", "content": "error during apply fares"})
Expand Down Expand Up @@ -1645,12 +1630,6 @@ def generate_transfer_fares(self, faresystems, faresystem_groups, network):
segment[boarding_cost_id] = max(xferboard_cost, 0)
level += 1

# for vehicle in network.transit_vehicles():
# if vehicle.mode == meta_mode:
# network.delete_transit_vehicle(vehicle)
# for link in network.links():
# link.modes -= set([meta_mode])
# network.delete_mode(meta_mode)
self._log.append(
{
"type": "header",
Expand Down Expand Up @@ -1717,10 +1696,6 @@ def follow_rule(next_level):
return journey_levels

def log_report(self):
# manager = self.controller.emme_manager
# emme_project = manager.project
# manager.modeller(emme_project)
# PageBuilder = _m.PageBuilder
report = PageBuilder(title="Fare calculation report")
try:
for item in self._log:
Expand Down
Loading

0 comments on commit 2e77132

Please sign in to comment.