Reputation: 21
I'm quite new with Java & AnyLogic so please get on my level for this one.
Is there a way for agents to get a variable value from another agent? In that case, agents would be of the same type. Thus, they all have the same variables, but since it's variables with random initial values and not parameters, the values aren't the same.
Agents are also initially connected via Small-World connections and these connections are not altered during the runs.
How can agents, occurring in a Event for example, gather a variable value from another agent (e.g. Agent i gets the variable value X of agent j). This value would be put in a small equation in order to modify the value of variable X of agent i. In other words, the agent i would be affected by his connected agent j, hence altering his value of X.
I've tried multiple combinations of .getConnectedAgent()
and .get
without any success. I'm now trying to extract the values of X for each agent into a database and then use that database to gather the value of X of agent j by agent i, but I'm not making any progress there.
The values needed to be extracted are double
s, but I could change the variables to integers if it would be easier.
Upvotes: 2
Views: 1588
Reputation: 12803
There is no need to extract that into a database. You should do some more learning around object-oriented programming, your issue has less to do with AnyLogic and more with using Java properly.
If you have a population of Agents called "MyAgents", where each agent has a variable var with a random double value, then agent 12 can get the double value of agent 14 by calling var = get_Main().MyAgents.get(13).var
.
Here, var
on the left hand side is the var of the calling agent. get_Main()
takes it one level up in the hierarchy to access its own population and other agents. It then accesses the 14th agent (Java is zero-based) and its var value.
If you plan to use getConnectedAgent()
, you need to connect agents first. This is done to some extend if you use "Small world" but often, you want to define connections manually. Check the "Link to Agent" article in the help.
cheers
Upvotes: 2