What is the error with setPreferredSpeed Unit? - anylogic

what's the problem???!!!
Isn't the unit MPS?

Your agent type is not set to be used as a Car:
Only then does AnyLogic know the function.
PS: Always use code-complete when coding (Ctrl+space). For normal agents, it does not show a function, indicating that it does not exist.
But if you flag your agent as a "Car", it will show up.

Related

Anylogic how create new agent and assign properties?

Anylogic: This should be simple but I just cannot find it in the help files..
On creating a new agent instance, we know there are four parameters and what they are, but not in what order they were defined. Lets say parameters are "type_of_car" (String), "number_of_pax" (Integer), "automatic" (boolean), "fuel_capacity" (double). Now when calling: new myagenttype("ford", 5, false, 55) the agent gets created as a ford with 55 pax, manual and 5 liter fuel capacity - which is all wrong. (it seems the definition order of the parameters in the agent definition are in a different order)
How do we include the parameter name (or definition) when we call new agenttype() to avoid this problem, ensuring the right value gets assigned to the right parameter?
The problem originates because of a bug in Anylogic's logic in triggering functions. We have a Split which creates a new agent and assigns the agent properties on the "On exit copy" - event, however what Anylogic does is it creates the agent, forward it to the next logical block (a decision node), then execute the code of the decision - all wrong now for the agent's properties are undefined - and only then executes the "On exit copy" event which assigns the agent's properties. Very frustrating.
This is actually not a bug, this is defined in the simulation experiment properties, in the randomness section, with the "selection mode for simultaneous events" property. The default is LIFO, but if you want the opposite behavior in your case you should use FIFO... I always use LIFO too, and in these cases, sometimes I might use a 1milisecond auxiliary delay between the split and the next block in order to control the order manually... if you do that, you will solver your problem in fact... just use a 0.001 miliseconds delay after your split
Now from your Agent Type problem, the arguments for your class constructor should be written in order, and the only way to know the correct order is by using the autocomplete feature when you write new agenttype()... the autocomplete will tell you the order in which you should write your constructor arguments.

What is the right way to allot a distinct value to an agent's parameter in Anylogic?

I want my agent to be of a single type. Where type contains a list of 3 options. And the allotment should be based on probability. E.g. let's say I want to allot 1: 30%, 2: 50% and 3: 20% to each of the agents generated in the source of my main tab.
I tried with one of the ways by declaring th parameter as int and then writing randomTrue(0.3)?1:randomTrue(0.7)?2:3 in the default value. But every time the agent comes with the same value of 2.
Please can anyone help me with this??
And if I try to allot the parameters in the main window at any of the blocks, do they get attached to the specific agent that passes through that block or its value just gets updated for that time until the other agent passes? Actually I have to check each and every agent for the parameter and then send it through a specific output path from the selectoutput block.
Your code does not actually change anything in the created agent.
Create a parameter `myType´ of type Integer.
In your source code write:
agent.myType = randomTrue(0.3) ? 0 : randomTrue(0.7) ? 1 : 2
Make sure your Source block actually creates agents of the Agent type that holds the myType parameter.
Study some of the example models and tutorials, it is covered in many places :-)

How to rate units in a Resource Pool and select the highest rated unit in the seize block?

I am doing a simulation project of a logistics system. I created an agent named "AGV" with a variable "power"and I have a Resource Pool of it. I want to use the "Unit with top rating" in the "Resource Selection" of the Seize block to preferentially select the AGV with the lowest power.But when I type in "1/unit.power" in "Unit rating", the system reports an error. It seems that I cannot call the variable "power" located in the "AGV" agent. How can I solve this problem, or is there any other way to achieve my purpose.
unit is of type agent and you have to cast it as type AGV... Or whatever your type is for your agent AGV... use lowercase for populations or agents and use Uppercase first letter for classes or Agent types... That's notation standards..
Now let's assume your agent type is called AGV... be sure you use the correct type...
Then use 1.0/((AGV)unit).power
Then use 1.0 because if your variable power is an int you will have problems, if it's a double it's all good.
But let's hope you don't have power=0... because if you do, then maybe it's better to do:
-((AGV)unit).power instead, otherwise it's fine

product progression by production cicle

I'm trying to make a simple model where I can advance an agent that follows a specific production cycle.
For example, referring to the image, the article A will be created and passes only through service 1 e 2 while article B goes only through service 1 e 3. they both conclude in sink, of course.
In the past I've used Plant simulation and with methods and tables I succeed but with AnyLogic I really had no idea how to do that.
I've tried with the enter and exit but with no luck.
Does anyone know how to do that?
You would use "SelectOutput" object for that. The condition to set would be based on your article type.
Assuming you have an agent type "Article" with a String parameter p_ArticleType, and your Source block creates "Article" agents, you can use the setup below:
(Note that in your case, the "Agent type" property should not show "Agent" but "Article"!
Obviously, you can then draw connector lines to the required service objects ;-)
btw: This is some very basic capability so I recommend you study more AnyLogic tutorials where this is covered as well.
Following your clarification, in that case, you do use "Enter" and "Exit" blocks. In the "Action" code section of an "Exit" block, you would write code to move your agent to the correct "Enter" block ahead of the next service block it needs. The code is myEnterBlock.take(agent).
Please check the help and example models, there is a ton out there to do this ;-)

Using agent parameters from main to different agent?

For a project I'm trying to select the right output if a parameter of the created agent is true. The agent is created in the main but goes into a different agent for the selection of the output. If I use a select in the main and use the statement for the parameter as condition it works fine. Whenever it enters the agent and I use the same statement it gives an error (Description: product1 cannot be resolved or is not a field. Location: testCase5/Transport/selectOutput - SelectOutput).
I tried using different conditions like main.agent.product1 . Can't seem to solve the issue. I know that it has to do something with declaration probably but I'm clueless at the moment.
//for the condition that works if I put the selectOutput in the main
agent.product1
//for the condition in the agent I tried the same but didn't work. also tried
main.agent.product1 // Gives the same error but for (Description: agentcannot be resolved or is not a field.)
(Main)agent.product1
//And a few more
In AnyLogic each block of a project flow (regardless if from the process modeling library, the pedestrian library or another) has the type of Agent that is flowing through it defined in its properties. You can find this setting as Agent type in the block's properties under Advanced.
If you fail to set this correctly (meaning this setting equals the type of Agents you let flow through it), it will still flow through, BUT: you cannot access the specific properties of the Agent type.
That said, usually you do not even have to think about, because AnyLogic has an automatism there: The first block of your process flow, typically a Source-block or a Enter-block is the only block where you have to make the correct setting, all attached blocks get it then automatically!
However this does not work when:
You have separate flows (eg. you leave one flow through an Exit-block and enter another by an Enter). You'll manually have to put the correct setting also for the first block of the second process flow.
Your process flow is continued inside of another Agent/Custom Block, as in your example. AnyLogic doesnt realize the process flow inside your custom block is logically connected to the outside process flow in main. You have to specifiy manually again the Agent type flowing through in the first block of your process inside your Custom Block.