0

So, I'm pretty new with Anylogic, but have done a lot of tutorials and I have programming experience in Java. For my thesis I'm modelling a vehicle flow as a process. In the source block, I create custom agents (vehicles) with some parameters from the database. This works fine. Then I want to assign an electric parameter with randomTrue(0.5). For this, I call a setupTaxi-function, where electric ist set. The parameter for the randomTrue-function should be changeable, so I set it as an extra paramter anteilEtaxis (0.5).

After that, I want the vehicles to do different things depending on the value of electric using SelectOutput. I selected the Condition and test on agent.electric.

I basically did the exact same thing as described in the Anylogic help. And yet the framework always chooses the true Output port, no matter if the parameter ist set to true or false.

See the image for setup and parameters. I tested this via console (the first line is a println-call in source, the second a println-call in selectOutput.). Plus you can see that the parameter is set to different values, because the 3D visualisation model depends on it:

enter image description here

Also, I tried a few different combinations of setting the parameters, reading them etc... The only thing that will work is putting randomTrue(0.5) directly in the Condition box. This is not what I want though. So if you have an idea, what is wrong, please tell me.

ACJ
  • 15
  • 1
  • 4

1 Answers1

2

This is a typical beginners problem.

I will assume you are calling the setupTaxi-function in your source in the "on exit" action... If you are doing that, then it's too late and the agent already made its decision on where it will go after the select output block.

You have to call your setupTaxi-function in 2 possible places:

1) In your source on the "on at exit" action

2) In your vehicle agent on the "on startup" action

Or even.. just make electric variable have a default value of randomTrue(main.anteilEtaxis)... that will also work.

Felipe
  • 8,311
  • 2
  • 15
  • 31
  • Thank you! You were right, the function call of setup was in the "on Exit" field. I put it in the "at Exit" field and it works now. I still don't understand why or how the decision making works excactly. I will try to look that up. Thanks for your help! – ACJ Mar 18 '18 at 09:46
  • The order is not very intuititve... it runs in this order: - on at exit - condition of the output block - on exit - on enter But it is also possible in some cases that the condition on the select output is evaluated even before the "on at exit" when the agent is stuck in the block waiting to be pulled by a block that is after the select output... In the source you generally have the "force push" option selected, but you can have that problem when it's a pull. – Felipe Mar 18 '18 at 10:19