简体   繁体   English

如何在Mainlogic中将参数从Main提供给代理

[英]How to give a parameter from the Main to an agent in Anylogic

my Main contains a conveyor, which transports a carton (my agent) from A to B. I added a radio button with which the user can choose the size of the box ("small", "medium", "big" & "very big"). 我的Main包含一条传送带,可将纸箱(我的代理商)从A传送到B。我添加了一个单选按钮,用户可以使用该按钮选择盒子的大小(“小”,“中”,“大”和“非常”大”)。 I now want every carton to save the value of the radio button. 我现在希望每个纸箱保存单选按钮的值。 I tried a lot of different stuff like linking it to a parameter, but I didn't manage to figure it out. 我尝试了很多其他方法,例如将其链接到参数,但是我没有弄清楚。

Picture of my model: 我的模特图片:

在此处输入图片说明

the code I used for the radio button is: 我用于单选按钮的代码是:

if( value == 0 )
    radioValue = 1;
else if( value == 1 )
    radioValue = 2;
else if( value == 2 )
    radioValue = 3;
 else if( value == 3 )
    radioValue = 4;

radioValue being the parameter in the Main i linked my radio-button to. radioValue是我将单选按钮链接到Main中的参数。

How do I give this parameter to the agent and how do I read it out later? 如何将此参数提供给代理,以后如何读出?

Thanks in advance for helping! 在此先感谢您的帮助!

in your Kist agent create a variable called size of type int. 在Kist代理中,创建一个名为int类型的变量。

in the source block, in the properties, on the "on at exit" action, under the action section of the properties write the following code: 在源代码块的属性中,在“退出时打开”动作中,在属性的动作部分下,编写以下代码:

agent.size=radioValue;

This is one of the most basic things to do in AnyLogic... so I suggest for you to go through a training before even starting to work on any model. 这是AnyLogic中要做的最基本的事情之一。因此,我建议您在开始使用任何模型之前都要接受培训。 This can be done by going through the tutorials, the anylogic in 3 days book or my course here: noorjax.teachable.com/p/anylogic 这可以通过阅读教程,三天之内的anylogic书或我在这里的课程来完成: noorjax.teachable.com/p/anylogic

later you can use agent.size to access the size of your agent, in any of the blocks. 之后,您可以使用agent.size在任何块中访问代理的大小。

Without seeing more of the code, my general suggestion would be to consider looping through the agents (eg, with a for loop) and having them all set a local variable cartSize equal to radioValue (I wouldn't use "size" because its also used for agentsets I believe). 在没有看到更多代码的情况下,我的一般建议是考虑遍历代理(例如,使用for循环),并让它们全部设置一个等于radioValue的局部变量cartSize(我不会使用“ size”,因为它也我相信用于代理集)。 Just spitballing here, but something like this? 只是在这里吐口水,但是这样的事吗?

for (int x = 0; x < carton.size(); x++) {
     carton.get(x).cartSize = radioValue;
} 

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

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