如何检查我的代理是否确实处于anylogic 中的等待块中?

问题描述 投票:0回答:2

我正在研究一个模型,我需要根据某些条件从等待块中释放一些代理。

if(wait1.getAgent(AGENT)==true){
List <Pallet> pallet=findAll(wait1,p->p.ProductType.equals(NutritionPowder)); // create a list of products that belong the same client as the agent that arrived
if(pallet.size()>=OrderSize){ //check if the batch size is reached
//batch.set_batchSize(agent.batchSize);
for(int i=0; i<OrderSize ; i++){
for(Pallet p :pallet){
wait1.free(p);
}
}
}
else create_Create(1,HOUR,OrderSize,AGENT);
traceln("False is dynamic");
traceln(pallet.size() + "Size");
traceln("Order Size is: " + OrderSize);
}
else //do nothing;

代码的第一行是错误的,我需要帮助。

anylogic
2个回答
0
投票

你可以做

if(agent.currentBlock()!=null && agent.currentBlock().equals(wait1))

-1
投票

您可以使用此代码来监视在等待块中徘徊的代理,在特定情况下将它们释放,从而更有效地管理模型的动态。

HashSet<Pallet> waitingPallets = new HashSet<>();

waitingPallets.add(agent);

waitingPallets.remove(agent);

void checkAndReleaseAgents() {
if (waitingPallets.size() >= OrderSize) {
    Iterator<Pallet> iterator = waitingPallets.iterator();
    int count = 0;
    while (iterator.hasNext() && count < OrderSize) {
        Pallet pallet = iterator.next();
        waitBlock.free(pallet); 
        iterator.remove();
        count++;
    }
}
}
© www.soinside.com 2019 - 2024. All rights reserved.