A question about seizing more than one ressource in Anylogic - anylogic

I'm working on a supply chain project with AnyLogic. In my model which is similar to product delivery example in AnyLogic examples, there are two agents which are Retailer and Fulfillment center. Both have their own vehicles. What I'm trying to do is to share vehicles so retailers and Fulfillment centers use the vehicles of each others. What I did is to create two Ressource Pool in each agent. So in the seize block as it shown below in picture, I added two ressource sets . In each statechart of each vehicle as it shown below and after delievering products, I informed my vehicle to go back to his initial location and in this case it can be Retailer or Fulfillment center. However after simulation, I got an error message in console that tells me that my agent which is the vehicle is trying to move to unknown source

If you put 2 ResourcePools into 2 agents, you have 4 pools in total. But you only want 1 shared pool, right?
Only add 1 ResourcePool to Main and use that from both agent's Seize elements. You will not be able to select the pool in the usual dropdown list (as there is no pool in either agent) but you can easily use the dynamic code to specify it. Note that the code below assumes both agents are embedded in Main:

Related

Can a transporter follow an 'material' agent into another agent?

I have an material agent that is moved from the Main agent to inside another agent (simulating a room). I can send the material agent using the Exit and Enter blocks. The 'room' agent contains a network that the material agent is being sent to.
The material agent is initially being moved in Main using a Transporter. However I'm not able to get this Transporter to follow the material agent into the room agent. The main questions is - is it possible to send a Transporter into another agent? Or does it need to remain in the agent that the Transporter Fleet is located?
Thank you.
I will correct benjamin by saying that with setEnvironment you can't do it since that's a function that is called on the agent initialization.
Instead of setEnvironment,something you do normally is to send the agent to a new population (which is the way you dynamically change environment), but it doesn't work with transporters
My answer would be that you can't do it since transporters who follow paths are defined as strict AGVs and can only move on their initial network and you can't change the network, unlike other agents.
But i'm always a bit suspicious of myself when i say something is not possible...
This should be possible with some setEnvironment() calls.
However, it is not a good setup. Think of reality: your rooms are spatially all part of the same environment: your flat (or factory or whatever). Moving from 1 room to the next does not mean you change your flat. You stay in the same environment.
You should setup your room agents like that as well: their spatial representation should reside in Main (or whatever agent they are embedded in).
Use a parameter of type ShapeRectangle or similar in your Room agent to define which rectangle (or else) represents the spatial aspect of the room.
Then, the flow chart blocks in the Room agent simply refer to that parameter for their spatial needs.

How can I take the closest resources to specific stations from ResourcePool?

I'm simulating a manufacturing process. The stations need a variable number of ResourcePool "workers". Let's say there are 5 workers for 4 stations, and I want to simulate that those workers can work indifferently in any of the stations.
The problem is that they are not working in the closest station. Oppositely, even when a worker is next to the station, maybe the furthest worker goes until this station which needs the resource, and then the process starts. Obviously, this is inefficient and doesn't represent the reality.
I already have the workers defined, their shifts, their timetables, etc. I have tried to use the function getNeartestAgent() in 'Customize request choice', but it doesn't work. I also tried to calculate the distance of each agent with getDistance(), but I don't know how to manage it and I'm sure it must be a simpler solution even when I'm not working on GIS.
[31/08/22]
Recently I tried to develop a similar model, and I still have the same problem. The model consists of 3 stations which need 1 unit of ResourcePool. In this pool, there are 2 units. This units are agent type Operario. So, I need to choose the closest unit to the station. I tried several things, the following are just some...:
Service blocks -> Resource selection -> "Nearest to the agent". The agent is the material item, so the unit should go to the closest agent being treated in the station. However, it didn't work (units where to any station indeferently).
Service blocks -> Resource selection -> "Unit with top rating". The Unit rating field was 1/distanceTo(node1.getXYZ()). It didn't work either.
Stations (instead of Service blocks) -> Customize resource choice -> Resource choice condition. I can't stablish a boolean variable related to the unit position, as I can't compare among them.
Function. I can't compare units from ResourcePool, as they are detected as Agent and not as Operario.
ResourcePool. I tried to stablish the priority based on the distance to a certain node. But then I can't call these agents (Operario) from the station. It seems here I can only refer to material items, eventhough I write "unit.(...)".
Does anyone know how can I choose the closest resource to the station in which the task is performed? Should be through Customize resource choice -> Resource choice condition, but I don't know how!
when you use a service or seize block, in the advanced properties, there's an option called "Resource Selection"
You have to choose "Nearest to the agent"
If this doesn't work, it might mean that a resource that is close by and not selected, might be actually busy with something else... you have debug your model in order to be sure that it is not the case.

How to compare conditions of an agent with all connected agents in statechart

I am working on my thesis associated with modeling farmers' behaviors in a river basin. I am having 6
agents that contain different populations of farmers. These farmers have been located on the GIS map as the environment (main) in anylogic. I also defined the connection between populations of 6 agents by coding on the main startup and using "Link to Agent". Now, I'd like to define agents' behaviors through statecharts. But I have some difficulties. I have to compare the income of each farmer to the income of all connected farmers. How can I do that? What I have tried to define condition transition and write (for example if the income of each farmer is less than the income of all connected farmers in its network then do specific action):
IncomeT<ALL_CONNECTED.IncomeT
but it didn't work. Got any suggestions?
Thanks.
not quite clear who is your agent for which you are designing your state chart. Is it some entity (say Area) which contains a population of farmers? If yes, then why would you connect/link one Area to another? If you agent is a famer (which is not how you described it, but seems logical) then you would just store (and update) "minimum population income" in some variable and compare individual income with that stored value.
Alternatively you can use min() function. More on that: https://help.anylogic.com/index.jsp?topic=%2Fcom.anylogic.help%2Fhtml%2Fdata%2Fcollections-statistics-api.html

How can I create agent populations within an agent population

I am having this issue with Anylogic, hope to get some help :)
The situation is the following: I have a population of agents X that has 10 different agents inside it, I need to pick up these different agents and put them in the "container agent" which is my pallet, and finally store them in the Pallet Rack.
The agents are different products being produced in the same location. There is a database stating each product when will it be produced and the amount of it.
I have created the agent X, how can I create 10 different agents within it?
If you want to have an agent population within an agent population, do this:
Have an agent type "Containers"
drag that into Main to create a population "pop_Containers". Load it as you like
Create another agent type "Products"
Open the "Containers" agent type and drag in "Products" to create a "pop_Products" within "Containers"
Load your products for each container as you see fit. This depends on your specifics of your database structure.
For the other questions, please create new questions. StackOverflow works best with specific questions in each topic, see https://stackoverflow.com/help/how-to-ask

Anylogic: how to individually address to resources within a Resource Pool

I am using Anylogic where I have just one ResourcePool made by just one Resource Type unit (created through the command "Resource Agent" in the Process Library).
I define the capacity of the ResourcePool, let's say, to 20 and I would like to have each of the single element (or some of them) within the Pool with a different value for the same parameter (e.g 3 units have parameter=1 , other 4 units parameter=2 ...).
First of all how can I set individually each of this parameter? Do I need to use a population of agent? If yes how can I do that? And how can I call the resourcePoolPopulation in other location within the model?
Is there a clevere way to do that?
Hope it is clear, thanks!
That is a weak spot of resource pools, IMO. They are designed to hold a homogeneous "soup" of similar resources and it is hard to pull in a specific element.
However, not impossible, there are various ways. You can create your resource agents manually in an agent population first and add them to the pool manually after creation. Then, in the service object, tick "manual resource unit choice" (or similar) and use a criteria that matches your resource params.