【问题标题】:NetLogo permission odditiesNetLogo 权限异常
【发布时间】:2013-03-28 19:14:10
【问题描述】:

我的 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 的建模书。

每次尝试运行时,它都会出现两个我可以看到的问题:在程序 sell 中,它不想将 bbalance 设置为新值,因为它仅适用于海龟,而 tick 仅适用于观察者上下文。

感谢您的帮助!

【问题讨论】:

    标签: permissions patch turtle-graphics netlogo


    【解决方案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
    

    【讨论】:

      【解决方案2】:

      sell 是一个海龟过程(因为它使用了海龟原语,例如 sizein-radius)。但是go 是一个观察者程序。你不能直接从观察者过程中调用海龟过程;您需要指定要运行它的海龟。在go 内部,我想你可能打算写ask turtles [ sell ] 而不仅仅是sell

      【讨论】:

      • 好的,如果有人试图用谷歌搜索这个并且找不到其他任何东西,这是我的完整(工作!)代码:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 2016-09-29
      • 2020-08-30
      • 2014-04-06
      • 2015-02-06
      相关资源
      最近更新 更多