简体   繁体   English

如何创建一个 function 到特定的 Attractor 元素作为 Anylogic 中 moveTo 块的目标

[英]How to create a function to specific Attractor element as a destination of moveTo block in Anylogic

I'm trying to create a function that returns the specific attractor destination to the moveTo block.我正在尝试创建一个 function ,它将特定的吸引子目的地返回到 moveTo 块。 The function will check if the 1st attractor is busy will go to check the next attractor. function 将检查第一个吸引子是否忙,go 将检查下一个吸引子。 If the next attractor is available then product moveTo that attractor destination.如果下一个吸引子可用,则产品移动到该吸引子目的地。 Struggling at how to reach attractor as an element of an array and return that element to be a destination of moveTo.努力研究如何将吸引子作为数组的一个元素到达并将该元素返回为 moveTo 的目的地。 Also how to loop checking the condition of next attractor if that attractor is not available.如果该吸引子不可用,如何循环检查下一个吸引子的条件。

I tried to use the collection and population agent.我尝试使用收集和人口代理。 But cannot return the attractor element.但不能返回吸引子元素。

Please advise, and thank you for your comment.请指教,并感谢您的评论。 Attractor model photo吸引器 model 照片

Use a LinkedHashMap for instance called yourCollection in which the key will be of type Attractor and the value will be a boolean (true if it's free, false if it's busy)... then you can just do yourCollection.get(yourAttractor) and it will return a true or false使用名为 yourCollection 的 LinkedHashMap 例如,其中的键将是 Attractor 类型,值将是 boolean (如果它是免费的,则为 true,如果它很忙,则为 false)......然后你可以做 yourCollection.get(yourAttractor) 和它将返回 true 或 false

Initialize it like this:像这样初始化它:

for(Attractor a : collectionCellTest){
    yourCollection.put(a,false);
}

and your function to return a free attractor should be something like this:你的 function 返回一个免费的吸引子应该是这样的:

for(Attractor a : yourCollection.keySet()){
    if(yourCollection.get(a)){
         return a;
    }
}
return null;

You can also put resources in the attractors and just use moveTo the seized resource unit... this would be the most robust way I think.您也可以将资源放入吸引器中,然后使用 moveTo 被占用的资源单元......这将是我认为最强大的方式。

If you want to do more special stuff with the attractor, you can also consider using a collection of classes in which the class will have the attractor and if it's free or not at least.如果您想使用吸引子做更多特殊的事情,您还可以考虑使用 class 将具有吸引子的类的集合,以及它是否至少是免费的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM