Skip to content

Commit

Permalink
relative gap as dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-sijia committed Jul 8, 2024
1 parent 137728a commit 90df1cc
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tm2py/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,19 @@ class ClassDemandConfig(ConfigItem):
factor: float = Field(default=1.0, gt=0)


@dataclass(frozen=True)
class HighwayRelativeGapConfig(ConfigItem):
"""Highway assignment relative gap parameters.
Properties:
global_iteration: global iteration number
relative_gap: relative gap
"""

global_iteration: int = Field(ge=0)
relative_gap: float = Field(gt=0)


@dataclass(frozen=True)
class HighwayClassConfig(ConfigItem):
"""Highway assignment class definition.
Expand Down Expand Up @@ -935,7 +948,7 @@ class HighwayConfig(ConfigItem):
"""

generic_highway_mode_code: str = Field(min_length=1, max_length=1)
relative_gap: float | Tuple[float, ...] = Field(ge=0)
relative_gaps: Tuple[HighwayRelativeGapConfig, ...] = Field()
max_iterations: int = Field(ge=0)
area_type_buffer_dist_miles: float = Field(gt=0)
drive_access_output_skim_path: Optional[str] = Field(default=None)
Expand Down Expand Up @@ -1341,11 +1354,9 @@ def maz_skim_period_exists(cls, value, values):
def relative_gap_length(cls, value, values):
"""Validate highway.relative_gap is a list of the same length as global iterations."""
if "end_iteration" in values:
if isinstance(value, float):
return value
assert (
len(value) == len(values["end_iteration"]),
"relative_gap must be the same length as end_iteration",
len(value) == len(values["end_iteration"]+1),
"relative_gap must be the same length as end_iteration+1",
)
return value

Expand Down

0 comments on commit 90df1cc

Please sign in to comment.