Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 在NetLogo中使用两个条件对修补程序集或代理集进行排序_Sorting_Netlogo - Fatal编程技术网

Sorting 在NetLogo中使用两个条件对修补程序集或代理集进行排序

Sorting 在NetLogo中使用两个条件对修补程序集或代理集进行排序,sorting,netlogo,Sorting,Netlogo,我的补丁程序具有成本和增益属性,我想用最小成本和最大增益对补丁程序列表进行排序。排序依据功能用于对一个属性进行排序,但如何对两个属性进行排序?要对多个属性的代理集进行排序,可以使用或: 您需要通过的排序标准是,给定要排序的项目之一,将报告一个数字列表,根据该列表对项目进行排序 在您的情况下,您可以像这样使用它: let sorted-patches sort-by-criteria ( task [[ list (-1 * cost) gain ] of ? ] ) patches 对于两

我的补丁程序具有
成本
增益
属性,我想用最小
成本
和最大
增益
对补丁程序列表进行排序。
排序依据
功能用于对一个属性进行排序,但如何对两个属性进行排序?

要对多个属性的代理集进行排序,可以使用或:

您需要通过的
排序标准是,给定要排序的项目之一,将报告一个数字列表,根据该列表对项目进行排序

在您的情况下,您可以像这样使用它:

let sorted-patches sort-by-criteria (
  task [[ list (-1 * cost) gain ] of ? ]
) patches

对于两个标准,它可能不值得使用,但如果你有一个很长的标准列表,那么它可能比其他任何方法都更容易使用和更清晰。

你能更准确地说出你想要的“最低成本和最大收益”的确切含义吗?我可以想象几个可能的含义——你可以从另一个中减去一个,或者只使用后者来打破前者的联系,或者……这假设只有在成本相等的情况下,收益才重要。但我想知道海报是否真的想要一个兼顾两者的东西。是的。我没有考虑这个替代方案,但我想如果海报想要某种成本和收益的加权排序,他可以在
版本上使用
排序,并用适当的函数替换
(成本*-1000)+收益,事实上,我想找到
成本
收益
之间的最佳组合。。。不仅在成本相等的情况下。你如何定义“最佳组合”?就像赛斯在上面建议的那样,仅仅是收益-成本?
to-report sort-by-criteria [ criteria items ]
  ; `criteria` needs to be a task that returns a list of numbers
  report sort-by [
    compare-lists (runresult criteria ?1) (runresult criteria ?2)
  ] items
end

to-report compare-lists [ l1 l2 ]
  report ifelse-value (empty? l1 or empty? l2) [ false ] [
    ifelse-value (first l1 = first l2)
      [ compare-lists but-first l1 but-first l2 ]
      [ first l1 < first l2 ]
  ]
end
let sorted-patches sort-by-criteria (
  task [[ list (-1 * cost) gain ] of ? ]
) patches