首页 文章

AnyLogic排序算法

提问于
浏览
0

在AnyLogic中,我们可以执行max和min来找出两个值之间的最大值或最小值 . 但是,我如何执行(例如)5个值的排序,其中每个值都存储在变量中(对于基于代理的建模)?

非常感谢你提前 . 如果您认为应该提供更多细节,也请告诉我 .

1 回答

  • 1

    例如,有3个变量叫做variable1,variable2和variable3 . 让我们添加一个带有double类型元素的集合(arrayList)(假设你的变量是double类型)

    每次要对这些值进行排序时:

    collection.clear(); //clear the collection before adding the variables
    collection.add(variable); //add the variables
    collection.add(variable1);
    collection.add(variable2);
    Collections.sort(collection);//sorts the collection from smaller to larger
    Collections.reverse(collection);//you can use this code in case you want to sort from larger to smaller instead
    

    然后,您可以通过执行来访问该集合

    collection.get(i)
    

    它在哪里是集合的索引(在这种情况下有3个变量,它可以是0,1或2)

相关问题