我新调试好的程序如下,应该是对的,供参考
* v# a8 e) N7 u( S% ]: R8 z' C3 i因为特殊要求,这里的边的长度是二维座标内的空间距离- H5 a$ O3 B' H7 X+ W/ E9 _( s
) ]+ n' M: r) |0 ]; T$ V
to find-distance5 ^5 x4 u" b1 |7 Z, R+ |) f: U
let i 0) w& z `* I1 _$ N& w2 }. z
let j 0& y# ]5 S0 s$ |
let nodedistance 05 S& S( X! C# n8 t- S
let linknumber 0
8 K! T7 ?0 u" D+ W
! {3 X7 X2 k; A3 R- X) S0 @ while [j < count turtles]
% f" H' p# I8 ~6 H- F [4 a, i" X! o( n% U5 Y; A% @, p" Y* U
while [i < count turtles]/ H( o2 u& H7 M; u
[ if link-neighbor? turtle i
) ?* }+ s2 p: A* g( V d [ask turtle j [set nodedistance nodedistance + distance turtle i]$ v# o. T% X1 n6 U, a
ask turtle j [set linknumber linknumber + count [link-neighbors] of turtle i]) K& L, i8 j8 K" }" {# b. [
]5 Z( X5 C/ @) X: V' j* h
set i i + 1
/ q) I& g0 W0 n2 K ] 6 m+ B3 M2 u2 `: Z R8 a; P% a, U# R
set j j + 1$ f' T5 f! e$ S) [ [! Q, S; {
]1 D# t" B) u2 d
set average-path-length nodedistance / (linknumber * 2)" q8 w$ d3 @% a" i
end |