首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按要报告的过程对列表进行排序

按要报告的过程对列表进行排序
EN

Stack Overflow用户
提问于 2013-06-13 02:24:29
回答 1查看 44关注 0票数 0

因此,当使用我创建的报告器过程进行计算时,我尝试根据它的值对列表进行排序。代码如下:

代码语言:javascript
复制
globals [ goal Smin Smax distWeight colorWeight ]
turtles-own [ S Ac ]

to setup
  ca
  set Smin 2
  set Smax 6
  set distWeight 2
  set colorWeight 3

  ask n-of n patches [
    sprout 1 [ 
      set color one-of [ red blue ] 
      set heading one-of [ 90 270 ]
      set S []
      ]

  ]
  reset-ticks
end

to go
  ask turtles [

    foreach sort other turtles [
      ask ? [
        if Smin < Sim myself ? [
          if Sim myself ? < Smax [
            set S lput ? S
          ]
        ]
      ]
    ]

    ;how do I do this? this does not work
    set Ac max-one-of S [Sim myself ?]

  ]
  tick
end

to-report Sim [Ame Ao]
  report (Sfcolor Ame Ao * colorWeight) + (Sfdistance Ame Ao * distWeight)
end

to-report Sfcolor [Ame Ao]
  ifelse [color] of Ame = [color] of Ao 
  [ report 1 ]
  [ report 0 ]
end

to-report Sfdistance [Ame Ao]
  report 1 / euclidean-distance [xcor] of Ame [ycor] of Ame [xcor] of Ao [ycor] of Ao 
end

to-report euclidean-distance [x y x1 y1]
  report sqrt ((x1 - x) ^ 2  + (y1 - y) ^ 2)
end

to-report Gain [ SimVal ]
  report ( Smax - Smin ) / Smax - SimVal
end

现在,我想要一个名为Ac的变量来包含turtle,它是S的一个元素,具有最高的Sim值。我试着这样做

代码语言:javascript
复制
set Ac max-one-of S [Sim myself ?]

但它不起作用。

EN

回答 1

Stack Overflow用户

发布于 2013-06-20 02:56:36

如果你确切地说出它不起作用的原因,那会有所帮助。

但是对于初学者来说,这条语句在foreach循环之外,所以呢?不会有任何意义。

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

https://stackoverflow.com/questions/17072613

复制
相关文章

相似问题

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