首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Railsback和Grimm,基于Agent和基于个人的模型第10. 4章中的网络徽标商业模式代码

Railsback和Grimm,基于Agent和基于个人的模型第10. 4章中的网络徽标商业模式代码
EN

Stack Overflow用户
提问于 2015-12-08 11:53:15
回答 1查看 832关注 0票数 0

我正在试用由Railsback和Grimm (基于Agent和基于个人的建模)书中的示例。在使用第10.4章的说明时,我编写了一个业务模型。我可以成功地建立模型,但是当我点击go按钮时,我会得到一个错误。

代码语言:javascript
复制
 "this code can't be run by a patch
 error while turtle 3 running UTILITY-FOR
     called by procedure REPOSITION
     called by procedure GO
     called by Button 'go'"

这是我的密码

代码语言:javascript
复制
patches-own
 [
  annual-profit
  business-risk
 ]

turtles-own
 [
  wealth
 ]
to setup
 clear-all
 ;initializing the profit
 ask patches 
  [
   set annual-profit random 1000
   set business-risk 1 - risk-probability
   set pcolor scale-color green annual-profit 0 1000
  ]
 crt 5 ; created five business spots for test
  [
   setxy random-xcor random-ycor
   set shape "house"
   set color red
   set wealth random 10000]
   reset-ticks
end

to go
  ask turtles [reposition]
  tick
end

to reposition
  let potential-destinations neighbors with 
  [not any? turtles-here]

  ;adding the current patch to the potential-destinations
  set potential-destinations
    (patch-set potential-destinations patch-here)
 ; Identify the best one of the destinations
  let best-patch max-one-of potential-destinations
  [utility-for myself]

  ;Now move there
  move-to best-patch
 end

to-report utility-for [a-turtle]
  ; a patch-context reporter that calculates utility
  ; for turtle "a-turtle" in this patch
  ; first get the turtle's wealth

  let turtles-wealth [wealth] of a-turtle
  let profit [annual-profit] of patch-here
  let risk [business-risk] of patch-here

 ; then calculate turtles's utility given its wealth and
 ; relevant variables
   let utility ( turtles-wealth + profit * 5 ) * (risk ^ ticks)

   report utility
 end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-08 19:05:12

变化

代码语言:javascript
复制
let profit [annual-profit] of patch-here
let risk [business-risk] of patch-here

代码语言:javascript
复制
let profit annual-profit
let risk business-risk

hth

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34155218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档