2017-12-03 4 views
1

私は基本的に弱く接続された最大のコンポーネントに色付けしようとしています。 nw:weak-component-clustersは、ネットワークに存在するすべてのコンポーネントのリストを返しています。私は最大のものだけを色付けしたい。私のコードはすべてのコンポーネントに色付けしています。ネットワークで最も弱く接続されたコンポーネントを着色しています

let clusters nw:weak-component-clusters 
print length(clusters) 
show clusters 
show sort (clusters) 
foreach clusters [ 
    set color pink 
] 

答えて

2

あなたはサイズを降順でクラスタのあなたのリストをソートして、その色を変更するには、これらの最初のものを依頼するsort-byを使用することができます。

extensions [nw] 

to setup 
    clear-all 
    create-turtles 100 [ 
    set color blue 
    create-links-with n-of random 3 other turtles 
    ] 
    repeat 30 [ layout-spring turtles links 0.2 5 1 ] 
    let clusters nw:weak-component-clusters 
    ; sort by descending size of cluster: 
    let sorted-clusters sort-by [ [c1 c2] -> count c1 > count c2 ] clusters 
    ask first sorted-clusters [ set color pink ] 
end 
+0

ありがとうございました。 – BiSarfraz

関連する問題