Skip to content

Commit a234f0b

Browse files
committed
refactor: Update KMeansClustering to set random_state and rename unsearched_building_ids in DefaultSearch
1 parent 40501b1 commit a234f0b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

adf_core_python/implement/module/algorithm/k_means_clustering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def prepare(self) -> Clustering:
112112
def create_cluster(
113113
self, cluster_number: int, entities: list[Entity]
114114
) -> list[list[Entity]]:
115-
kmeans = KMeans(n_clusters=cluster_number)
115+
kmeans = KMeans(n_clusters=cluster_number, random_state=0)
116116
entity_positions: np.ndarray = np.array([])
117117
for entity in entities:
118118
location1_x, location1_y = entity.get_location()

adf_core_python/implement/module/complex/default_human_detector.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ def _select_target(self) -> Optional[EntityID]:
6969
cluster_index
7070
)
7171

72-
self._logger.debug(
73-
f"cluster_entities: {[str(entity.get_id()) for entity in cluster_entities]}"
74-
)
75-
7672
cluster_valid_human_entities: list[Entity] = [
7773
entity
7874
for entity in cluster_entities

adf_core_python/implement/module/complex/default_search.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from adf_core_python.core.component.module.algorithm.clustering import Clustering
1515
from adf_core_python.core.component.module.algorithm.path_planning import PathPlanning
1616
from adf_core_python.core.component.module.complex.search import Search
17+
from adf_core_python.core.logger.logger import get_agent_logger
1718

1819

1920
class DefaultSearch(Search):
@@ -29,7 +30,7 @@ def __init__(
2930
agent_info, world_info, scenario_info, module_manager, develop_data
3031
)
3132

32-
self._unsearched_building_ids: set[EntityID] = set()
33+
self._unreached_building_ids: set[EntityID] = set()
3334
self._result: Optional[EntityID] = None
3435

3536
self._clustering: Clustering = cast(
@@ -48,6 +49,11 @@ def __init__(
4849
),
4950
)
5051

52+
self._logger = get_agent_logger(
53+
f"{self.__class__.__module__}.{self.__class__.__qualname__}",
54+
self._agent_info,
55+
)
56+
5157
self.register_sub_module(self._clustering)
5258
self.register_sub_module(self._path_planning)
5359

@@ -56,18 +62,22 @@ def update_info(self, message_manager: MessageManager) -> Search:
5662
if self.get_count_update_info() > 1:
5763
return self
5864

65+
self._logger.debug(
66+
f"unreached_building_ids: {[str(id) for id in self._unreached_building_ids]}"
67+
)
68+
5969
searched_building_id = self._agent_info.get_position_entity_id()
60-
self._unsearched_building_ids.discard(searched_building_id)
70+
self._unreached_building_ids.discard(searched_building_id)
6171

62-
if len(self._unsearched_building_ids) == 0:
63-
self._unsearched_building_ids = self._get_search_targets()
72+
if len(self._unreached_building_ids) == 0:
73+
self._unreached_building_ids = self._get_search_targets()
6474

6575
return self
6676

6777
def calculate(self) -> Search:
6878
nearest_building_id: Optional[EntityID] = None
6979
nearest_distance: Optional[float] = None
70-
for building_id in self._unsearched_building_ids:
80+
for building_id in self._unreached_building_ids:
7181
distance = self._world_info.get_distance(
7282
self._agent_info.get_entity_id(), building_id
7383
)

0 commit comments

Comments
 (0)