如何实现Netlogo代码以达成共识

时间:2014-11-18 05:48:51

标签: netlogo

我是Netlogo的新人,任何人都可以指导我如何在同一点上获得多只乌龟的共识。我脑子里有一个粗略的代码,但我不知道如何实现它的NetLogo代码。


to setup 
  ca
  crt num-agents [ 
    set color red
    setxy random-xcor random-ycor
    set shape "car"
    create-links-with other turtles
    ]
end

to go



  ask turtles [
    let closest-turtle min-one-of (other turtles) [distance myself ]
;    let difference subtract-headings heading (towards closest-turtle)
;    set heading (heading + 0.1 * difference)
;    fd 1

    let x-component sum [dx] of closest-turtle
    let y-component sum [dy] of closest-turtle
    move-to x-component
  ]
end

; Difference = Difference of my xy-cordinates from others turtles
; set_my_xy = [currentposition+0.1*difference]
; or [x;y]=[x:y]+0.1*sum[my_location - other_turtles_location]  

1 个答案:

答案 0 :(得分:1)

如果我没弄错的话,你试图实现与Viscek模型非常相似的东西。请尝试以下代码:

 ask turtles[ 
    set new-v-x mean [v-x] of (turtle-set other turtles in-radius <set-distance-for-vision>)
    set new-v-y mean [v-y] of (turtle-set other turtles in-radius <set-distance-for-vision>)

v-x和v-y更新如下:

  set v-x speed * dx
  set v-y speed * dy