Function decide where to store the pallets - anylogic

I would like to store the pallets into pallet rack "PRD6" if my typeID = 1, else I would like to store them into pallet rack "PRD7". My agent type is Pallet. I don't know how to build up the function. I'm currently learning java basics but I don't know either how to declare the variables. I read it in the help document but it doesn't help. Thank you for helping.

the correct syntax is the following:
agent.typeID==1 ? PRD6 : PRD7
but if you have lots of options, you should call a function here that returns a PalletRack and generate the if/else statement in that function

Related

Rack Pick in a custom flowchart with a dynamic event

I would like to use my custom flowchart for different process flows and my target is to pick my pallets from the racks to the certain times from my dbase. So with a delay block it doesn't work so I replaced it by a wait block where I will release the pallets which should get picked by the time of my dbase. The function doesn't work and I'm not sure if it is the right way to solve my problem. I would like to release the number of pallets (n) to the picktime of my dbase.
Thank you for your help!
Your DE looks good but you are calling it from a wrong location, that is what the error is telling you. Make sure you access that location first before calling create_DE....
(depends on where you call it from and where it lives, see https://help.anylogic.com/index.jsp?topic=%2Fcom.anylogic.help%2Fhtml%2Fcode%2FAccess.html&resultof=%22%77%68%65%72%65%22%20%22%61%6d%22%20%22%69%22%20

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 :-)

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 ;-)

How to get the dataset for text from Main and run in parameter variation experiment using anylogic?

I am working on an evacuation process project and would like to know if its possible to acquire a dataset for text or a variable from main and run in parameter variation experiment (for 100 runs) while storing/saving it after every iteration. This text keeps changing every time the simulation runs because the number of people able to escape during evacuation is different. An alarm (event) goes off and it triggers another event (event1), this then updates the text that counts the number of people in the building.
stopCounting of type boolean is false and peopleRemaining of type long
getPeopleInsideCount() comes from my function
The code I tried using in After experiment run for parameter variation experiment is
iteration3++;
dataset2.add(iteration3,(double)Long.parseLong(root.text2.getText()));
I understand that this code is unable to read the text from the main as a dataset. I have run the simulation in main and the text updates while also noticing that the peopleRemaining variable follows the number in text. Maybe it is possible to obtain variable in a dataset?
please learn to use the AnyLogic help as well. There, you will learn that a Dataset object only stores numbers. Also, a text object has only text as a String. They are not compatible.
You will want to store your evacuation number in a variable of type Int, name it myEvacNumber. So in addition of showing it in your text, you must manually store it in that variable. Best do that at the end of your evacuation ;-)
Then in your experiment in the "after simulation run" codebox, you can access it and store it into your dataset using
dataset.add(root.myEvacNumber);
Note that this will store the value that was in that variable at the very end of each simulation run!

Cannot solving error while using SelectOutputOut block

I am still a beginner at modeling anylogic. I am currently using the selectOutputOut block to create the different routes of agent flow (the agent named product). I already created a function for choosing the output and already inputted the type SelectOutputOut for returning values.
I simply followed the SelectOutputN example from AnyLogic example model. However, there is an error "This method must return a result of type SelectOutputOut" which I really do not know how to fix.
If you have any solutions, please help me.
Thanks in advance.
Here are the images
at the very end of the choosingOutput function body write return null;
The problem is that you only have "else if" statements, you need to either write an else statement to cover all the possibilities, or return something at the very end (in case all the ifs are false)
It will also work if your last if, instead of writing if else(agent.product == TypeC), you just write else