【问题标题】:Netlogo: Combine similar turtles and combinatorical pair creationNetlogo:组合相似海龟和组合对创建
【发布时间】:2017-02-22 00:51:18
【问题描述】:

两个问题: 1. 如何对具有某些特定变量的海龟数量进行分组,这些变量符合我的指定标准。例如创建 Id1 为“1”的海龟。 所需的输出将是包含相似值的海龟数量的列表。 2. 如果我得到了包含相似 ID 的海龟列表,我想从所有可用的海龟中得到一个组合。在 python 中(因为它是我唯一熟悉的语言)我会使用:

turtle_list = ["1","2","4","5","6","7"]

def create_pairs(source):
        result = []
        for p1 in range(len(source)):
                for p2 in range(p1+1,len(source)):
                        result.append([source[p1],source[p2]])
        return result

pairings = create_pairs(turtle_list)
print("%d pairings" % len(pairings))
for pair in pairings:
        print(pair)

【问题讨论】:

    标签: list netlogo


    【解决方案1】:

    这是一个简单的方法。为了提高效率,如果你真的需要它,请实现你上面描述的配对算法。

    turtles-own [id]
    
    to setup
      ca
      let _ids range 5
      crt 100 [set id one-of _ids]
    end
    
    to pairup [_id]
      let _ts (turtles with [id = _id])
      ask _ts [
        create-links-with other _ts
      ]
    end
    
    to test
      setup
      pairup 0
    end
    

    【讨论】:

      猜你喜欢
      • 2016-03-11
      • 1970-01-01
      • 1970-01-01
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-09
      相关资源
      最近更新 更多