【问题标题】:How to get all possible combinations of a list in Netlogo (without value duplications in the list & using Netlogo)如何在 Netlogo 中获取列表的所有可能组合(列表中没有重复值并使用 Netlogo)
【发布时间】:2017-11-02 19:24:31
【问题描述】:

我正在努力编写一个可以让我从列表中找到所有组合的 Netlogo 程序。下面是我要建模的情况的一个示例。

我有一个包含五个代理的列表:[agent1, agent2, agent3, agent4, agent5] 我想知道如何获得所有可能的组合,并且组合必须具有固定大小(例如,如果 size = 3,那么组合场景应该是[agent1, agent2, agent3], [agent1, agent2, agent4],[agent1, agent2, agent5],[agent1, agent3, agent4], ....

通过这种方式,我将能够从每个独特组合中计算出成本绩效,其中 3 个代理可以相互交互以确定该成本,并且我将能够找到最佳组合(即最好的 3 个代理谁可以一起工作以提供最低的成本)。

我需要一种大规模生产的方式来在 Netlogo 建模环境中完成这项工作,以便稍后我可以更改大小和代理总数等参数。欣赏代码演示!

【问题讨论】:

    标签: list combinations permutation netlogo


    【解决方案1】:
    to-report comb [_m _s]
      if (_m = 0) [ report [[]] ]
      if (_s = []) [ report [] ]
      let _rest butfirst _s
      let _lista map [? -> fput item 0 _s ?] comb (_m - 1) _rest
      let _listb comb _m _rest
      report (sentence _lista _listb)
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-19
      • 2015-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多