Skip to content

Commit

Permalink
Merge branch '39-error-when-computing-ttce-when-dce-is-infinity' into…
Browse files Browse the repository at this point in the history
… 'develop'

Resolve "Error when computing TTCE when DCE is infinity"

Closes #39

See merge request cps/commonroad/commonroad-criticality-measures!34
  • Loading branch information
YuanfeiLin committed Apr 28, 2024
2 parents 31a2b26 + 2bf4c50 commit 7792b14
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- adds the error handling of the out-of-projection-domain for many measures, such as TTC, THW, ALongReq, ALatReq
- Initialization of the ego vehicle in the base class
- fix the pf and soi measure, when the other vehicle is not present in the scenario for some time steps
- fix the dce and ttce measure of which the initial value should be math.inf
## [0.3.2 & 0.3.3] - 2024.03.16
### Added
- Error handling for check in same lanelet
Expand Down
2 changes: 1 addition & 1 deletion commonroad_crime/measure/distance/dce.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DCE(CriMeBase):

def __init__(self, config: CriMeConfiguration):
super(DCE, self).__init__(config)
self.time_dce = None
self.time_dce = math.inf

def compute(self, vehicle_id: int, time_step: int = 0, verbose: bool = True):
"""
Expand Down
10 changes: 7 additions & 3 deletions commonroad_crime/measure/time/ttce.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import matplotlib.pyplot as plt
import numpy as np
import logging
import math

from commonroad_crime.measure.distance.dce import DCE
from commonroad_crime.data_structure.base import CriMeBase
Expand Down Expand Up @@ -44,9 +45,12 @@ def compute(self, vehicle_id: int, time_step: int = 0, verbose: bool = True):
return np.nan

self._dce_object.compute(vehicle_id, self.time_step)
self.value = utils_gen.int_round(
(self._dce_object.time_dce - self.time_step) * self.dt, 3
)
if self._dce_object.time_dce is not math.inf:
self.value = utils_gen.int_round(
(self._dce_object.time_dce - self.time_step) * self.dt, 3
)
else:
self.value = self._dce_object.time_dce
utils_log.print_and_log_info(
logger,
f"*\t\t {self.measure_name} with vehicle id {vehicle_id} = {self.value}",
Expand Down

0 comments on commit 7792b14

Please sign in to comment.