Skip to content

Commit e9ea0e3

Browse files
authored
Merge pull request #85 from adf-python/fix/docs/hot-fix
エージェントとサーバーの起動についてとクラスタリングの可視化
2 parents 7d0888d + 0b91770 commit e9ea0e3

File tree

8 files changed

+126
-22
lines changed

8 files changed

+126
-22
lines changed

docs/source/download/cluster_plot.zip

11.7 KB
Binary file not shown.

docs/source/hands-on/clustering.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ class KMeansPPClustering(Clustering):
287287
return col_ind
288288
```
289289

290+
k-means++の実装は、scikit-learnの`KMeans`クラスを使用しています。`KMeans`クラスは、`n_clusters`で指定したクラスター数によって地図上のオブジェクトをクラスタリングします。クラスタリング結果は、`labels_`属性に格納されます。また、`cluster_centers_`属性には各クラスターの中心座標が格納されます。
291+
292+
hungarianアルゴリズムの実装は、scipyの`linear_sum_assignment`関数を使用しています。`linear_sum_assignment`関数は、コスト行列を引数として受け取り、最適な割り当てを行います。
293+
290294
次に、作成したモジュールを登録します。`config/module.yaml` を以下のように編集してください。
291295

292296
```yaml
@@ -298,4 +302,55 @@ SampleHumanDetector:
298302
Clustering: src.<your_team_name>.module.algorithm.k_means_pp_clustering.KMeansPPClustering
299303
```
300304
301-
シミュレーションサーバーを起動して、エージェントを起動してください。エージェントが起動すると、標準出力にクラスタリング結果が表示されます。
305+
ターミナルを2つ起動します。
306+
307+
片方のターミナルを開き、シミュレーションサーバーを以下のコマンドで起動します:
308+
309+
```bash
310+
# Terminal A
311+
cd WORKING_DIR/rcrs-server/scripts
312+
./start-comprun.sh -m ../maps/tutorial_ambulance_team_only/map -c ../maps/tutorial_ambulance_team_only/config
313+
```
314+
315+
その後、別のターミナルを開き、エージェントを起動します:
316+
317+
```bash
318+
# Terminal B
319+
cd WORKING_DIR/<your_team_name>
320+
python main.py
321+
```
322+
323+
エージェントが起動すると、標準出力にクラスタリング結果が表示されます。
324+
325+
```bash
326+
[info ] Clustered entities: [[257, 259, 262, 263, 270, 278, 280, 297, 336, 913, 914, 915, 916, 917, 918, 919, 933, 941, 942, 943, 944, 945, 946, 947, 974, 250, 253], [349, 896, 899, 902, 934, 960, 968, 969, 970, 971, 248, 251], [258, 266, 268, 269, 274, 275, 279, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 932, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 975, 976, 254, 255], [256, 271, 273, 281, 296, 298, 314, 330, 903, 904, 905, 910, 911, 912, 935, 936, 937, 938, 939, 940, 247, 249]] [KMeansPPClustering]
327+
[info ] Agent cluster indices: [([89544, 19925], 1), ([69989, 120063], 0), ([130029, 50380], 2), ([29898, 59056], 3)] [KMeansPPClustering]
328+
```
329+
330+
このままだと、クラスタリング結果がわかりにくいので、クラスタリング結果を地図上に表示してみましょう。
331+
332+
{download}`クラスターの可視化用スクリプト <./../download/cluster_plot.zip>`をダウンロードして解凍し、`main.py`の以下の部分に
333+
334+
```python
335+
# クラスタリング結果
336+
clusters = []
337+
```
338+
339+
出力の`Clustered entities: `の後ろの部分の配列をコピーして貼り付けてください。
340+
341+
342+
343+
```python
344+
# クラスタリング結果
345+
clusters = [[257, 259, 262, 263, 270, 278, 280, 297, 336, 913, 914, 915, 916, 917, 918, 919, 933, 941, 942, 943, 944, 945, 946, 947, 974, 250, 253], [349, 896, 899, 902, 934, 960, 968, 969, 970, 971, 248, 251], [258, 266, 268, 269, 274, 275, 279, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 932, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 975, 976, 254, 255], [256, 271, 273, 281, 296, 298, 314, 330, 903, 904, 905, 910, 911, 912, 935, 936, 937, 938, 939, 940, 247, 249]]
346+
```
347+
348+
貼り付けたら、以下のコマンドを実行してください。
349+
350+
```bash
351+
python main.py
352+
```
353+
354+
以下のような画像が出力されます。
355+
356+
![クラスタリングの画像](./../images/cluster.png)

docs/source/hands-on/search.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ class KMeansPPSearch(Search):
7070

7171
```yaml
7272
DefaultTacticsAmbulanceTeam:
73-
Search: src.<team-name>.module.complex.k_means_pp_search.KMeansPPSearch
73+
Search: src.<your_team_name>.module.complex.k_means_pp_search.KMeansPPSearch
7474

7575
DefaultTacticsFireBrigade:
76-
Search: src.<team-name>.module.complex.k_means_pp_search.KMeansPPSearch
76+
Search: src.<your_team_name>.module.complex.k_means_pp_search.KMeansPPSearch
7777

7878
DefaultTacticsPoliceForce:
79-
Search: src.<team-name>.module.complex.k_means_pp_search.KMeansPPSearch
79+
Search: src.<your_team_name>.module.complex.k_means_pp_search.KMeansPPSearch
8080
```
8181
8282
## モジュールの実装
@@ -87,7 +87,7 @@ DefaultTacticsPoliceForce:
8787

8888
```yaml
8989
KMeansPPSearch:
90-
Clustering: src.<team-name>.module.algorithm.k_means_pp_clustering.KMeansPPClustering
90+
Clustering: src.<your_team_name>.module.algorithm.k_means_pp_clustering.KMeansPPClustering
9191
```
9292

9393
次に、`KMeansPPSearch` モジュールで `KMeansPPClustering` モジュールを呼び出せるようにします。
@@ -146,7 +146,23 @@ class KMeansPPSearch(Search):
146146

147147
以上で、`KMeansPPClustering` モジュールを用いた `KMeansPPSearch` モジュールの実装が完了しました。
148148

149-
実行すると、各エージェントが担当地域内からランダムに探索対象を選択し、探索を行います。
149+
ターミナルを2つ起動します。
150+
151+
片方のターミナルを開き、シミュレーションサーバーを以下のコマンドで起動します:
152+
153+
```bash
154+
# Terminal A
155+
cd WORKING_DIR/rcrs-server/scripts
156+
./start-comprun.sh -m ../maps/tutorial_ambulance_team_only/map -c ../maps/tutorial_ambulance_team_only/config
157+
```
158+
159+
その後、別のターミナルを開き、エージェントを起動します:
160+
161+
```bash
162+
# Terminal B
163+
cd WORKING_DIR/<your_team_name>
164+
python main.py
165+
```
150166

151167
## モジュールの改善
152168

@@ -172,13 +188,13 @@ class KMeansPPSearch(Search):
172188
### 探索対象がステップごとに変わってしまう問題
173189

174190
```{admonition} 方針のヒント
175-
:class: tip dropdown
191+
:class: hint dropdown
176192
177193
一度選択した探索対象に到達するまで、探索対象を変更しないようにする
178194
```
179195

180196
```{admonition} プログラム例
181-
:class: tip dropdown
197+
:class: hint dropdown
182198
183199
````python
184200
def calculate(self) -> Search:
@@ -212,13 +228,13 @@ class KMeansPPSearch(Search):
212228
### すでに探索したエンティティを再度探索対象として選択してしまう問題
213229

214230
```{admonition} 方針のヒント
215-
:class: tip dropdown
231+
:class: hint dropdown
216232
217233
すでに探索したエンティティを何かしらの方法で記録し、再度探索対象として選択しないようにする
218234
```
219235

220236
```{admonition} プログラム例
221-
:class: tip dropdown
237+
:class: hint dropdown
222238
223239
````python
224240
def __init__(
@@ -287,13 +303,13 @@ class KMeansPPSearch(Search):
287303
### 近くに未探索のエンティティがあるのに、遠くのエンティティを探索対象として選択してしまう
288304

289305
```{admonition} 方針のヒント
290-
:class: tip dropdown
306+
:class: hint dropdown
291307
292308
エンティティ間の距離を計算し、もっとも近いエンティティを探索対象として選択する
293309
```
294310

295311
```{admonition} プログラム例
296-
:class: tip dropdown
312+
:class: hint dropdown
297313
298314
````python
299315
def calculate(self) -> Search:

docs/source/images/cluster.png

63 KB
Loading

docs/source/install/environment/environment.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# 環境構築
2+
23
adf-core-pythonをインストールするには以下の必要条件が必要です。
34
既にお使いのPCにインストールされている場合は再度インストールする必要はありません。
45

@@ -17,6 +18,7 @@ adf-core-pythonをインストールするには以下の必要条件が必要
1718
[Linuxでの必要条件のインストール方法](./linux/install.md)
1819

1920
## シミュレーションサーバーのインストール
21+
2022
次にRoboCup Rescue Simulationのシミュレーションサーバーをインストールします。
2123

2224
```{note}
@@ -48,3 +50,7 @@ cd scripts
4850

4951
上記のように何個かのウィンドウが表示されたら成功です。
5052
コマンドラインで `Ctrl + C` (MacOSの場合は `Command + C` ) を押すとシミュレーションサーバーが終了します。
53+
54+
```{warning}
55+
シミュレーションサーバーを停止させたあとは、プロセスが残ってしまう場合があるので`./kill.sh` を実行してください。
56+
```

docs/source/tutorial/agent/agent.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Your agent team name: my-agent
1717
Creating a new agent team with name: my-agent
1818
```
1919

20+
```{note}
21+
エージェントチーム名は、エージェントのディレクトリ名として使用されます。
22+
以後、エージェントチーム名を `<your_team_name>` として参照します。
23+
```
24+
2025
入力後、下記のようなエージェントのテンプレートがカレントディレクトリに作成されます。
2126

2227
```bash
@@ -55,7 +60,7 @@ cd WORKING_DIR/rcrs-server/scripts
5560

5661
```bash
5762
# Terminal B
58-
cd WORKING_DIR/my-agent
63+
cd WORKING_DIR/<your_team_name>
5964
python main.py
6065
```
6166

docs/source/tutorial/agent/agent_control.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,20 @@ DefaultTacticsFireBrigade:
107107
HumanDetector: src.<your_team_name>.module.complex.fire_brigade_human_detector.FireBrigadeHumanDetector
108108
```
109109
110-
シミュレーションサーバーを起動し、エージェントを実行してみましょう。
110+
ターミナルを2つ起動します。
111+
112+
片方のターミナルを開き、シミュレーションサーバーを以下のコマンドで起動します:
113+
114+
```bash
115+
# Terminal A
116+
cd WORKING_DIR/rcrs-server/scripts
117+
./start-comprun.sh -m ../maps/tutorial_fire_brigade_only/map -c ../maps/tutorial_fire_brigade_only/config
118+
```
119+
120+
その後、別のターミナルを開き、エージェントを起動します:
111121

112122
```bash
123+
# Terminal B
113124
cd WORKING_DIR/<your_team_name>
114125
python main.py
115126
```
@@ -151,13 +162,13 @@ RRS上のエンティティは下図のように `Entity` を継承したクラ
151162
- `entity` が市民であるかどうかを判定する
152163

153164
```python
154-
isinstance(entity, Civilian)
165+
is_civilian: bool = isinstance(entity, Civilian)
155166
```
156167

157168
- エンティティIDを取得する
158169

159170
```python
160-
entity.get_id()
171+
entity_id: EntityID = entity.get_id()
161172
```
162173

163174
- 市民が生きているかどうかを判定する
@@ -185,19 +196,19 @@ if buriedness is None or buriedness <= 0:
185196
- エンティティIDからエンティティを取得する
186197

187198
```python
188-
self._world_info.get_entity(entity_id)
199+
entity: Entity = self._world_info.get_entity(entity_id)
189200
```
190201

191202
- 指定したクラスのエンティティを全て取得する
192203

193204
```python
194-
self._world_info.get_entities_by_type([Building, Road])
205+
entities: list[Entity] = self._world_info.get_entities_by_type([Building, Road])
195206
```
196207

197208
- エージェントの位置から指定したエンティティまでの距離を取得する
198209

199210
```python
200-
self._world_info.get_distance(me, civilian.get_id())
211+
distance: float = self._world_info.get_distance(me, civilian.get_id())
201212
```
202213

203214
[詳細はこちら](../../adf_core_python.core.agent.info.rst)
@@ -211,7 +222,7 @@ self._world_info.get_distance(me, civilian.get_id())
211222
- 自分自身のエンティティIDを取得する
212223

213224
```python
214-
self._agent_info.get_entity_id()
225+
my_entity_id: EntityID = self._agent_info.get_entity_id()
215226
```
216227

217228
[詳細はこちら](../../adf_core_python.core.agent.info.rst)
@@ -305,9 +316,20 @@ class SampleHumanDetector(HumanDetector):
305316
return self._result
306317
```
307318

308-
シミュレーションサーバーを起動し、エージェントを実行してみましょう。
319+
ターミナルを2つ起動します。
320+
321+
片方のターミナルを開き、シミュレーションサーバーを以下のコマンドで起動します:
322+
323+
```bash
324+
# Terminal A
325+
cd WORKING_DIR/rcrs-server/scripts
326+
./start-comprun.sh -m ../maps/tutorial_fire_brigade_only/map -c ../maps/tutorial_fire_brigade_only/config
327+
```
328+
329+
その後、別のターミナルを開き、エージェントを起動します:
309330

310331
```bash
332+
# Terminal B
311333
cd WORKING_DIR/<your_team_name>
312334
python main.py
313335
```

docs/source/tutorial/config/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
```bash
66
.
7-
└── <team-name>
7+
└── <your_team_name>
88
└── config
99
├── development.json
1010
├── launcher.yaml

0 commit comments

Comments
 (0)