Anylogic:如何对具有相似参数的代理进行批处理?

Anylogic: how to Batch agents with similar parameters?

我有一个名为 products 的代理,在这个代理中,我分配了一个名为 sp 的参数;在模拟中,我有相同的代理,其 sp 范围从 1 到 5。我想在同一批中使用相同的 sp 对代理进行批处理,即 10。所以如果我有 200 个代理,其中 49 个 sp 等于 1,我想将它们分成 5 个批次 (10,10,10,10,9),并且 sp 等于 2 与另一批等。

非常感谢您提供的任何帮助。

有很多方法可以做到这一点,但考虑到你有不一致的批次(即你有 10 个批次,最后一个是 9 个批次)我会先把所有的wait 块内的代理(或者您可以使用 queue),然后以编程方式控制它们

举下面这个小例子

我一直等到 200 个“产品”代理到达等待块,然后按下调用函数 batchReleaseCheck()

的“检查批次”按钮

这是代码

LinkedHashMap<Integer, List<Product>> productsWaiting = new LinkedHashMap<Integer, List<Product>>();
for (int i = 0; i < wait.size(); i ++){
    Product product = wait.get(i);
    int sp = product.sp;
    if (!productsWaiting.containsKey(sp)) productsWaiting.put(sp, new ArrayList<Product>());
    productsWaiting.get(sp).add(product);
    
    //Check the batch size if sufficient we release it
    if (productsWaiting.get(sp).size() == batchSize) {
        for (Product p:productsWaiting.get(sp)) {
            wait.free(p);
        }
        return; // we exit the loop since we have released a batch
    } 
}

// If we get to the end of the loop we were not able to release any batch we now release each SP type regardless of their current batch size

for (int i = 1; i < 6; i ++) {
    if (productsWaiting.get(i) == null) continue;
    for (Product p:productsWaiting.get(i)) {
        wait.free(p);
    }
    batch.set_batchSize(productsWaiting.get(i).size()); //Since the batch is less than the standard we need to change it to what ever we are releasing
    return; // we exit the loop since we have released a batch
} 

您创建一个地图,根据 sp 编号将产品存储在列表中。如果您在任何时候发现您有足够的单元来创建一个批次,我们将停止并将它们从等待块中释放。

如果我们到达 for 循环的末尾并且我们没有任何 sp 编号有足够的单位来组成整个批次,我们简单地释放我们所拥有的。

在这个例子中你需要每次点击按钮才能发布批次,或者你可以在批次对象的发布代码中添加批次检查函数调用。这一切都将按顺序发生,但同时发生 step