0

--This post has been edited as @Benjamin has suggested in his answer

I am trying to model peer influence for churn situations. Agents will send messages to their peers depending on different conditions. I have also created a List called MessagesReceived to store received messages.(The number of these messages may be >1).

Advocate function body

I have tried processing (i.e. adding the message to a list of received messages) these messages in Connections>OnMessageReceived but although I can access message and sender objects, I don't know how to access the receiving agent there.

Main>Connections>OnMessageReceived

what would you suggest in this case?

P.S: variable names and types may be a little different in screenshots but the problem I described here does not come from that.

1 Answers1

0

Please always only ask one question per issue, else it gets too confusing.

So let me answer your first question:

although I can access message and sender objects, I don't know how to access the receiving agent there

You can simply type this. in the code box below and you have access to "yourself". In fact, you do not even need that, simply access the fields from "yourself" here. If you are in an agent with variable myVar, you simply use that.

enter image description here

For the other questions, please open separate issues, see this.

Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • 1
    Thank you very much. Didn't notice that there was also a "Connections" in agent too. This way the other question will be a no-issue as all messages will be visible in "Connections". – mohammad javad Jafari Aug 17 '22 at 11:11
  • So, I have tried adding `this.MessagesReceived.add(msg)` inside Agent>Connections>Communications>OnMessageReceived. I have also removed/ignored message processing transitions in statechart. Also, I have disabled "Forward message to statechart" option. Now I get a NullPointerException Error on onReceive method of my agent. AnySuggestions @Benjamin? – mohammad javad Jafari Aug 17 '22 at 12:06
  • OK, inspecting my Consumer.Java file (Consumer being my agents' name) it seems that creating a list of strings as variable does not cut it exactly as it is still null. Adding `Messages_Recieved = new LinkedList();` to OnStartup() method of Consumer.Java takes care of the problem – mohammad javad Jafari Aug 17 '22 at 12:38
  • Please always ask new questions on new issues, SOF does not work like a forum, see https://www.benjamin-schumann.com/blog/2021/4/1/how-to-win-at-anylogic-on-stackoverflow . – Benjamin Aug 17 '22 at 13:32