1

netlogo プログラムに問題があります。コードは次のとおりです。

globals[
growth-param
money-size-ratio

]

turtles-own[
  location
  tsize
  bbalance
]

to setup
  ca
  reset-ticks
  ask patches[set pcolor blue]

  create-turtles initial-telemarketers [
    set size 1
    set bbalance 0.0
    setxy random-xcor random-ycor
    set shape "circle"
  ]
  set growth-param 1000
  set money-size-ratio 0.001
end

to go
  ask patches[set pcolor blue]
  sell
  accounting
  observer-updates
  tick
end

to sell

  let territory 10 * sqrt size
  let maxcalls 100 * size
  ask n-of maxcalls patches in-radius territory[
    if pcolor = blue [set pcolor black]
    set bbalance bbalance + 2
  ]

end

to accounting
  let cost size * 50
  ask turtles[
  set bbalance bbalance - cost

  ifelse bbalance < 1
  [die]
  [set size bbalance * growth-param]
  ]

end

to observer-updates

end

これは、単純に言えば、テレマーケティング会社がどれだけやり取りするかのモデルであるはずです。これは、Railsback & Grimm のモデリング ブックからのものです。

実行しようとするたびに、私が見ることができる 2 つの問題が発生します。sell プロシージャでは、タートルのみであるため bbalance を新しい値に設定したくありません。 tick はオブザーバー コンテキストのみです。

助けてくれてありがとう!

4

2 に答える 2

1
globals[

  money-size-ratio

]

turtles-own[
  location
  tsize
  bbalance
  maxsize
]

to setup
  ca
  reset-ticks
  ask patches[set pcolor blue]

  create-turtles initial-telemarketers [
    set size 1
    set bbalance 0.0
    setxy random-xcor random-ycor
    set shape "circle"
    set maxsize 0
  ]

  set money-size-ratio 0.001
end

to go

  ask patches[set pcolor blue]
  ask turtles [sell]
  ask turtles [accounting]  ;; let's ask the turtles to do this
  observer-updates
  tick

end

to sell
  let territory 10 * sqrt size
  let maxcalls 100 * size
  if maxcalls > 40401[
    set maxcalls 40401;keeps maxcalls within acceptable bounds
  ]
  let coun 0
  ask n-of maxcalls patches in-radius territory[
    if pcolor = blue[
      set pcolor black
      set coun coun + 2
    ] 
  ]
  set bbalance bbalance + coun


end

to accounting
  let cost size * 50 ;; size is a turtle variable so if you want to access it this way, let's make the whole thing
                     ;;  a turtle procedure.  That's what was confusing Netlogo about the tick command 

    set bbalance bbalance - cost

    if bbalance > growth-param
     [set size size + (bbalance - growth-param) * money-size-ratio
      set bbalance growth-param
       ]
    if size > maxsize[
      set maxsize size
    ]


    if bbalance <= 0
    [show (word "dead. Maximum size: " maxsize)
      die

      ]

    if size = 0
    [show (word "dead. Maximum size: " maxsize)
      die

      ]



end

to observer-updates

end
于 2013-04-04T19:30:39.950 に答える
0

sellはタートル プロシージャです (sizeやなどのタートル プリミティブを使用するためin-radius)。しかしgoオブザーバー手順です。タートル プロシージャをオブザーバ プロシージャから直接呼び出すことはできません。実行したいタートルを指定する必要があります。内部goではask turtles [ sell ]、単にsell.

于 2013-03-28T20:06:23.040 に答える