Reputation: 9
We have 500 agents. Everyone has an int parameter and an int variable.
If I want to send a parameter of every agent by message to change another agent's variable, what is your solution?
For example, we have "accept
" as a parameter and "Opi
" as a variable for all agents. We send the "accept
" to all agent. When agent 1 sends its "accept" to agent 2, I want to set "Opi.2= Opi.2 + accept.1
" but Anylogic set it as "Opi.2= Opi.2 + accept.2
".
I defined the Mediator variable:
Sending message:
Action:
Upvotes: 0
Views: 575
Reputation: 9421
I hope I can understand your question:
First, to send a message from one agent to the other, you can use the send function. If your message is being sent from agent1 to agent2, to send X, you will use: send(X,agent2)
Second, in your agent connections, you will define the messages as int and on message received you can do Y=Y+msg;
Note that msg is the X received from agent1.
EDIT: The message sent is only possible to read in the connections element as I stated... in your case when you use the mediator variable in the transition, you are using the mediator variable of the agent and not the one that was sent. The only way is doing it the way I just showed you.
Upvotes: 0
Reputation: 1
Well, you need to access the agent1's parameter X1. Would be helpful if you had shared some screenshots and actual object names, but in your notation, you will need something like this, assuming you have an agent population embedded on main where all agents live (and assuming agent 1 and 2 are the same agent type), and assuming we make agent 2 update it's X
X = X + main.myAgentPopulation.get(0).Y
Also assuming that "agent 1" is the very first agent in your population.
Best if you either share some more details or get to know Java-based OOP better (you are not in the data science world of arrays, tensors and matrices :-) ).
cheers
Upvotes: 0