Skip to content

prepare() and resume() perform duplicate computation #150

Description

@NONONOexe

While developing based on sample_road_detector.py, we noticed that prepare() and resume() perform the same computation. We believe this calculation should be performed by precompute(), not resume().

defresume(self, precompute_data: PrecomputeData) ->RoadDetector:
super().resume(precompute_data)
ifself.get_count_resume() >=2:
returnselfself._target_areas: set[EntityID] =set()
entities=self._world_info.get_entities_of_types([Refuge, Building, GasStation])
forentityinentities:
ifnotisinstance(entity, Building):
continueforentity_idinentity.get_neighbors():
neighbor=self._world_info.get_entity(entity_id)
ifisinstance(neighbor, Road):
self._target_areas.add(entity_id)
self._priority_roads=set()
forentityinself._world_info.get_entities_of_types([Refuge]):
ifnotisinstance(entity, Building):
continueforentity_idinentity.get_neighbors():
neighbor=self._world_info.get_entity(entity_id)
ifisinstance(neighbor, Road):
self._priority_roads.add(entity_id)
returnselfdefprepare(self) ->RoadDetector:
super().prepare()
ifself.get_count_prepare() >=2:
returnselfself._target_areas=set()
entities=self._world_info.get_entities_of_types([Refuge, Building, GasStation])
forentityinentities:
building: Building=cast(Building, entity)
forentity_idinbuilding.get_neighbors():
neighbor=self._world_info.get_entity(entity_id)
ifisinstance(neighbor, Road):
self._target_areas.add(entity_id)
self._priority_roads=set()
forentityinself._world_info.get_entities_of_types([Refuge]):
refuge: Refuge=cast(Refuge, entity)
forentity_idinrefuge.get_neighbors():
neighbor=self._world_info.get_entity(entity_id)
ifisinstance(neighbor, Road):
self._priority_roads.add(entity_id)
returnself

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions