Skip to content

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

@NONONOexe

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().

  def resume(self, precompute_data: PrecomputeData) -> RoadDetector:
    super().resume(precompute_data)
    if self.get_count_resume() >= 2:
      return self

    self._target_areas: set[EntityID] = set()
    entities = self._world_info.get_entities_of_types([Refuge, Building, GasStation])
    for entity in entities:
      if not isinstance(entity, Building):
        continue
      for entity_id in entity.get_neighbors():
        neighbor = self._world_info.get_entity(entity_id)
        if isinstance(neighbor, Road):
          self._target_areas.add(entity_id)

    self._priority_roads = set()
    for entity in self._world_info.get_entities_of_types([Refuge]):
      if not isinstance(entity, Building):
        continue
      for entity_id in entity.get_neighbors():
        neighbor = self._world_info.get_entity(entity_id)
        if isinstance(neighbor, Road):
          self._priority_roads.add(entity_id)

    return self

  def prepare(self) -> RoadDetector:
    super().prepare()
    if self.get_count_prepare() >= 2:
      return self

    self._target_areas = set()
    entities = self._world_info.get_entities_of_types([Refuge, Building, GasStation])
    for entity in entities:
      building: Building = cast(Building, entity)
      for entity_id in building.get_neighbors():
        neighbor = self._world_info.get_entity(entity_id)
        if isinstance(neighbor, Road):
          self._target_areas.add(entity_id)

    self._priority_roads = set()
    for entity in self._world_info.get_entities_of_types([Refuge]):
      refuge: Refuge = cast(Refuge, entity)
      for entity_id in refuge.get_neighbors():
        neighbor = self._world_info.get_entity(entity_id)
        if isinstance(neighbor, Road):
          self._priority_roads.add(entity_id)

    return self

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions