How to send message to all agents in population? - anylogic

I need to send message to all students in population from monthly event.
But (I guess) it`s not possible to use sendToAll()
method in this case, because event is declared inside of another enviroment.
I know how to send message to specific agent through using students.random() as a second argument in send()
method, but is it possible to send message to all agents?

This loops across all students in the population and sends them a message:
for (Student currentStudent : students) {
send("Hey", currentStudent);
}

Related

Create collection of agents already in queue in Anylogic

I'm simulating abandonment by waiting customers in a queue environment. I'm assuming that a person will abandon a queue if they notice that people who were in the queue ahead of them have left the queue (amongst other things like their own time in queue). To do this, I need to capture the details of the people already waiting in a queue when a new person joins the queue. I figure I need a collection created in the customer agent that i can store agent details of those ahead of them in queue. I can then use code to "populate" this collection via the on enter action of the queue block. but I'm not sure how to progress. I am struggling with how to find the IDs of agents in a queue and collect values of their parameters. Any help will be appreciated! Thank you.
When a new agent enters the queue you can use a for loop to cycle through all the agents in the queue and add it to a variable inside the agent.
Take the following simple example.
There is a custom agent type MyAgent it has a collection of type ArrayList accepting objects of type MyAgent.
Now when an agent enters a queue I can store the agents ahead of it in the queue in the following way
Please note the limit of the for loop is i < self.size()-1, if you don't add the -1 the agent will add itself to the list. (assuming your queue is FIFO (First in first out) the new agent will be the last in the list.

How to allow multiple agents of same population to use statechart simultanously, but independent of eachother, in Anylogic 8 PLE

In my project, I am using a statechart inside a population of agents named 'vehicle'. There are 5 vehicles. All vehicles have same speed. There is one more agent named 'sender'. Now what happens in my project is, that sender sends different messages to different vehicles. i.e. messages are m1,m2,m3,m4,m5 which are sent to vehicles having id v1,v2,v3,v4,v5. Messages are sent from sender, each time when a cyclic event triggers in the sender.
Lets take an example, when the event triggers in sender, it sends a message m1 to v1. The statechart receives the message m1 and uses it till the finishpoint of statechart. Similarly after a certain interval message m2 is sent to v2 and so on. Each message received is assigned to a variable named 'messageVal' in vehicle agent.
Click here to view statechart.
Currently it is working fine.
Here is the problem that occurs when I assign different speeds to vehicles.
The statechart for vehicle v1 when is still processing in the middle, while the event in the sender triggers again and sends another message m2 to vehicle v2. In this way, the variable value of 'messageVal' variable for vehicle v1, which should have been m1, becomes m2 now. and so on. Hence, the Results i receive for each vehicle, at the end, are incorrect.
Here is a sample Result:
vehicle=v1, message=m2
vehicle=v2, message=m2
I don't have any problem with the logic behind the event. All I need to know is, that does anyone know any method to allow multiple vehicles that have different speeds, to use statechart simultaneously without the values of ‘messageVal’ variable being altered till statechart's finishpoint?
If there is any confusion in understanding my question, I can further elaborate it. Thankyou.

Synchronous event triggering

I want to trigger at the exact same time through message receipt, some processes into different Actors. Considering my Actors possible heavily stacked mailBoxes, what would be the best method to implement this?
I'm assuming you want the actors to read the messages at the same time. This, of course is not possible (while an actor is processing a message he cannot be disturbed).
But you can make sure that your trigger message is the next message they will take from the mailbox. This can be achieved by using a priority mailbox, for example this one: http://doc.akka.io/api/akka/snapshot/index.html#akka.dispatch.UnboundedStablePriorityMailbox
The messages in the mailbox will be sorted by priority. If you give your trigger messages the highest priority, they will be processed first.

unsubscribe selected subscribers from node in xmpp

in xmpp publish subscribe protocol there is a provision to subscribe and unsubscribe to a node. but what if a publisher itself want to temporarily unsubscribe some of the subscribers and keep on publishing to selected subscribers only.
for example
A , B and C has subscribed to node PIZZA now if after somepoint if PIZZA node wants to publish only to A and C but not B.
i read the protocol but i didn't find anything like this , so is there anyone has any idea how to do it ?
i am using openfire as server and asmack libs as client
I don't know much about xmpp, maybe this is standard practice there, but normally the publisher doesn't know anything about the receivers so shouldn't control who is subscribed. Why does the publisher know better than the receiver whether the receiver should receive?
I would try a different approach, such as adding data in the message so the receiver can decide whether they should ignore the message.
Sending a blank message would not likely work: then all receivers that handle message only if not blank will skip it. So it will only work if B does not filter on blank messages. Instead, if the message has "filter=...", then receivers can decide to process based on the value of filter. Like, perhaps receivers A and C are a Type "X" of receiver, and receivers B and D are a type "Y" of receiver. Then if filter = "X", then receivers B and D know to ignore it. If filter is "Y", A and C know to ignore it. If filter is empty, they all process it.

Can I filter the messages I receive from a message queue (MSMQ) by some property? (a.k.a. topic)

I am creating a Windows Service in C# that processes messages from a queue. I want to give ops the flexibility of partitioning the service in production according to properties of the message. For example, they should be able to say that one instance processes web orders from Customer A, another batch orders from Customer A, a third web or batch orders from Customer B, and so on.
My current solution is to assign separate queues to each customer\source combination. The process that puts orders into the queues has to make the right decision. My Windows Service can be configured to pull messages from one or more queues. It's messy, but it works.
No, but you can PEEK into the queue and decide if you really want to consume the message.
Use GetMessageEnumerator2() like this:
MessageEnumerator en = q.GetMessageEnumerator2();
while (en.MoveNext())
{
if (en.Current.Label == label)
{
string body = ((XmlDocument)en.Current.Body).OuterXml;
en.RemoveCurrent();
return body;
}
}