@@ -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 )
0 commit comments