Variable from another agent in main - anylogic

I created an agent called Technician its a population and it has the variable capacity in boolean. The variable belongs to one agent (agent 0). In my main i have a button that changes its color if it is clicked on. The code i wrote for the Button in Fill color is.
technician.capacity==true? yellowGreen : tomato
It says that capacity cannot be resolved or is not a field
If i try technician with a T
Technician.capacity==true? yellowGreen : tomato
It says cannot make a reference to a non-static field
There must be wrong something with reference to technician part.
How can i fix it?

If your variable is in the Agent type, then every technician in your model has a capacity variable. For your code to work, you need to specify which technician you are referring to. Example: technician.get(0).capacity.

you need to use an actual agent from the population so it would be something like this:
technicians(0).capacity==true? yellowGreen : tomato
Technician is the Agent Type...
by default variables are not static in an agent, and i won't go to what a static variable is... but Technician.capacity would work only if the capacity is static, which would means that capacity would have the same value for all agents in the population
if your population is not defined in plural then you need to do
technician(0).capacity==true? yellowGreen : tomato

Technician is the type of the agent, the real agent is in the population technician.
If you wish to access a specific agent and check its parameter, you must do so by accessing the population.
technician.get(0).capacity

Related

What is the error with setPreferredSpeed Unit?

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.

Static reference error for getDistanceTravelled() of transporter agent

I have an agent, called "AGV", which is used as a transporter in my model. It is the agent for my fleet named "OrderFleet".
How can I get the distance travelled at the end of my simulation runs for my AGVs?
If I put AGV.getDistanceTravelled(METER); into the "On destroy" of my main agent, called "main", I receive the error:
Cannot make a static reference to the non-static method
getDistanceTravelled(Length Units) from the type AGV.
AGV is an agent type not an agent, so you cannot use the getDistanceTravelled() function on it. To resolve your issue, start by creating a population of agents of type AGV by dragging and dropping to Main the "Agent" element of the "Agent" Palette.
Then, make sure the new transporters in your fleet block are added to that population by doing the following:
Now, in the On Destroy field you can write the following code:
for( AGV a : AGVs ) {
traceln(a.getDistanceTravelled(METER));
}
This will return the distance travelled of each AGV in that fleet.
You need to put the code into the "on destroy" section of your AGV agent type, not Main. (Main is destroyed only once at the end of the model and does, obviously, not travel itself at all :) ).
If you do not have a separate agent type for the AGVs yet, you need to create (and apply) it. See the example models where this is shown in detail

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

Anylogic from "release block" change variable integer

I have an Agent Cart created with 4 variables inside. Each variable is an integer and one of them is called red and has an initial value of 4.
When I use seize/release statement I want change the integer by -1.
In the action section ive tried "On release" saying (Cart)unit.red in hope of changing the variable from 4 to 3. It gives an error back. "red cannot be resolved or is not a field" along with an syntax error on ")", assignment operator expected in (Cart)unit.red. Writing (Cart)unit.variable doesnt work either. Another sub-question : Is it possible to change two of the variables in the class from the "on release" block?
EDIT
Classpicture
Overview
Seize
Release
You need to assign Cart to your resource pool in order to be able to use it.
Check this image:
After that you need to be very careful on making the distinction between Cart, cart and carts
Cart being the class
cart being the agent if there is only 1 cart and you defined it as a single agent
carts being the population of agents
in your case, only the class is needed if you created a resource type called Cart... check out the capital letters compared to the non-capitalized ones.
Ok, now in your seize block you can use the cart ONLY in the action called on seize unit or on prepare unit.
if you do ((Cart)unit).red=3; it WILL work, as long as you understood all the previous explanation.
It it doesn't, you will need to give A LOT more information about your model, including very precise images of everything you are doing.