2017-07-11 7 views
1

私は2つの品種:suprasとsubsを持っています。近所の品種を数える(プロットする)

  • (カメの総 人口で割った値)suprasある隣人を持っている潜水艦の数
  • が潜水艦であることを隣人を持っているsuprasの数:私は2本の線を描画したい

    (カメの総人口で割ったもの)

どうすればいいですか?私はこれを試してみた:

  • plot count (subs with [one-of neighbors = supras])/num-turtles
  • plot count (supras with [one-of neighbors = subs])/num-turtles

数はケースではありません各集団のためには常に0です。そうneighbors = suprasはあなたが何のパッチがsuprasまたはsubsませんneed-あなたのものを手に入れるつもりはないと言って、

breed [supras supra] 
breed [subs sub] 

turtles-own [age] 
subs-own [status] 

to setup 
    clear-all 

    ;; Color the patches so they're easier to see 
    ask patches [ set pcolor random-float 2 ] 

    ;; 1/2 of num-turtles patches will sprout subs 
    ask n-of (num-turtles/2) patches [ 
    if not any? turtles-on patch-set self [ 
     sprout-subs 1 
    ] 
    ] 

    ;; 1/2 of num-turtles patches will sprout supras 
    ask n-of (num-turtles/2) patches [ 
    if not any? turtles-on patch-set self [ 
     sprout-supras 1 
    ] 
    ] 

    ;; Set breed colors and own-variables 
    ask subs [ 
    set color blue 
    set shape "dot" 
    set age 0 
    set status random 10 
    ] 

    ask supras [ 
    set color pink 
    set shape "dot" 
    set age 0 
    ] 

    reset-ticks 
end 

to go 

    ask turtles [ 
    let empty-patches neighbors with [not any? turtles-here] 
    if any? empty-patches[ 
     let target one-of empty-patches 
     face target 
     move-to target 
    ] 
    ] 

    ;; Mating conditions 
    ask supras [ 
    if any? subs-on neighbors [ 
     ;; Mate with highest status sub 
     mate 
    ] 
    ] 

    tick 
end 

to mate 
    move-to max-one-of subs [status] 
end 

答えて

2

neighborspatchesのagentsetを返します。ここに私のコードです。代わりに、隣人のいずれかがsupras-hereまたはsubs-hereを持っているかどうかを確認する必要があります。これは私のために働いた:

plot (count (subs with [ any? neighbors with [ any? supras-here ] ]))/(count turtles) 

plot (count (supras with [ any? neighbors with [ any? subs-here ] ]))/(count turtles) 

多くを見るためにあなたはおそらくY maxを1にスケールしたいと思うでしょう。

+0

お世話になりました。私は学ぶために遊んでいます。 NetLogoではどのような作業をしていますか? – santafebound

+2

あなたは賭けました!それは確かに周りを遊ぶための楽しいプログラムです。私のgradプロジェクトの一部はNetlogoを使用しています。このサイトから1トンのメリットを得ています。ユーザーは非常に役立っています。 –

関連する問題