I created an agent 1 and an agent 2 both existing in main. On startup I place agent 2 in a node which is located whithin agent 1 (main.agent1.node). But now when I want to move agent 2 to another node existing on main, the agent moves to an entirely different location, which seems to be dependent on the relative position of agent 1. Can someone explain the mechanism at work to me? Is agent 2 living in the continuous space of agent 1? How can I transfer it to main, so that it would move to the right position in relation to the main diagram? Thanks for taking the time.
Yes, spacing is always relative to the agent that "owns" you.
To transfer agent1 back to main alongside agent2, best use a flowchart "enter" block on main, push agent1 through it and use its "New location" setting to select some node on Main.
You can also call setEnvironment(main.getEnvironment()) to do it programmatically. More info in the help: https://anylogic.help/anylogic/agentbased/continuous-space.html#agent-animation
Related
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.
So, I have a case in anylogic where a drone needs to be transported via a bike from a certain place (namely, Depot) to a certain place (namely, Stopover Point). After that, the drone will be released from the bike and will do some mapping to a set of designated locations of Mapping Points. For this case, I used a process flow to make the bike (that I treat as a resource unit) to seize the agent (drone) at the Depot before the bike move to the Stopover Point and releasing the drone there.
At first, I used to make some kind of sandbox model where I only use one Depot and one Stopover Point
so that it is easier when I want to use my agent (drone) in a process flow via enter block (ex: I only have to write main.depot.enter.take(this); at my agent (drone) statechart to enter it to the process flow at Depot bacause the Depot is a single agent).
The problem occurs when I tried to use more than one Depot and make it as a population of agent. This makes me unable to use main.depot.enter.take(this); because of the property of the Depot for it is now a population of agent and not a single agent anymore.
The question is how should I do if I want my agent (drone) to enter the process flow of a certain/specific Depot (ex: only Depot[0])? I have used a paramater such as "name" with the value consists of texts like "Depot 1, Depot 2, and so on" and modify the commmand to filter(main.depots, a -> a.name == "Depot 1").enter.take(this); or main.depot[0].enter.take(this); but I think that's not the right way to code it because it didn't works. So, how is exactly the correct way to code or to do it if I want my agent to enter a process flow of a specific agent (ex: Depot[0]) from a population of agent (ex: Depots)? Thank you.
You should use () instead of [] to select one depot from the population.
So to select the one with index 0, you write: main.depot(0).enter.take(this).
To select a depot based on the name parameter, I would use the findFirst function which selects one of the depots. In your exitblock, you could write:
main.depot(findFirst(main.depot, a->a.name.equals("Depot1")).getIndex()).enter.take(this)
The getIndex()method returns the index of the selected agent.
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:
We are trying to create a generic moving capability for our agents that way we can use this capability in many projects.
The way I thought to do it was to create an agent called move and use it as a member in each agent I have in the future. (I would have wanted to use it as the upper class but since Java can only use one class as a parent this is not possible).
The problem is that when preforming the moveTo() command in the move agent it does not move the spacial coordinates of the owner agent.
Is it possible to link the two parameters so that any time x,y,z change in move agent the x,y,z in the owner agent also change?
If I understood your question right you want to have more control over your agent movements and have some custom logic you want to apply to all moveTo blocks. In that case it's easier to create a custom flowchart for your move than trying to modify your agents. You can use your custom move (instead of moveTo) every time you need to move any agent.
In Anylogic, how to make an agent run an action (like search in a certain radius for an agent) while moving towards another agent? I'm using PML to move to another agent but how can I include an intermediate task in the flow? Maybe combining with state charts? Any idea?
Difficult to say with these details but I feel like you may want something of this sort:
This event should be inside the agent that is moving (in which case the "yourAgent." should be removed:
Another option is to have a statechart inside the agent that is moving, something like this:
You trigger the message transition when your agent starts moving and you create a conditional transition with the condition distanceTo(otherAgent)
There are more ways of doing this... but these 2 came to mind first