Anylogic - 两组之间的自定义资源选择

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

使用 AnyLogic 服务块,我尝试使用自定义资源选择条件来获取资源集。我决定抓住哪个集合的标准是代理的布尔参数。使用this question的答案我实现了以下代码来获取所需的资源:

ResourcePool t_pool = (ResourcePool)pool;
// resource selection condition
if ( (t_pool == resourcePool1) && (agent.bool) ||
     (t_pool == resourcePool2) && (!agent.bool)){
    return true;
}
else {
    return false;
}

这适用于一种资源的替代集,但是当我的集由多个资源池组成时,该块无法占用该集。

例如有两个集合

{commonResourcePool, resourcePool1}
{commonResourcePool, resourcePool2}
,我检查了局部变量pool,它只采用commonResourcePool的值。切换池的顺序没有帮助。

我找到的一个解决方案是使用 Seize/release 块来管理 commonResourcePool。谁有更优雅的解决方案,使用局部变量访问两个池,例如选择它选择的那个,或者直接选择资源集之一?

(我使用 AnyLogic PLE 8.4.0)

预期结果:根据布尔值抢占预期集合。 获得的结果:未设置被抓住并且代理被阻止。 我尝试过的事情: 切换集合中池的顺序。结果相同:只有 commonResourcePool 被局部变量 pool 检查。

代码的修改:每次到达块时我都尝试创建一个新集合,但是我并非无法创建集合(ResourceSet 不存在)。我试过的代码是这样的:

    // create the two resource sets
    ResourceSet resourceSet1 = new ResourceSet();
    ResourceSet resourceSet2 = new ResourceSet();

    // customize the resource choice based on the agent parameter bool
    if (agent.bool.par_cancer) {
        resourceSet1.add(commonResourcePool);
        resourceSet1.add(resourcePool1);
        customizeResourceChoice(resourceSet1);
    } else if (!agent.bool) {
        resourceSet2.add(commonResourcePool);
        resourceSet2.add(resourcePool2);
        customizeResourceChoice(resourceSet2);
    } else {
        // handle invalid agent parameter value
    }

谢谢, 最好的问候

编辑: 这是为重现问题而创建的dummy model(原始模型出现相同的问题)。 该函数在服务块的this section中调用。 函数中包含的代码是here。 很抱歉没有在原始帖子中包含这些屏幕截图。

anylogic
© www.soinside.com 2019 - 2024. All rights reserved.