0

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.

Bill P
  • 3,622
  • 10
  • 20
  • 32
Murk
  • 75
  • 1
  • 8
  • can you share the code on how you are sending the message to the vehicles? – Felipe May 03 '18 at 10:30
  • Actually I have simplified my project in this question, for easy understanding. The names of agents and their tasks are different in my code. Instead of single, there is population of 6 agents for Sender. Each sender checks in the table if its id mentioned. if yes, then it uses code= send(this,main.vehicles.get(j));. A vehicle when receives sender's object, it then moves towards that sender. Event triggers after 1 day period. Problem discussed in the question results in the vehicles moving towards wrong sender agent at the end of statechart transition. Am I able to convey my point? – Murk May 04 '18 at 05:20
  • your problem is probably on the sender side.. so impossible to know from the info provided here... you ask for a method to allow multiple vehicles to use the same statechart simultaneously... but that question shows a serious misunderstanding of how statecharts work... each vechicle has an independent statechart, so in a way they are using the same type of statechart in their own way... and on the other hand, multiple agents cannot use the same statechart since a statechart can only have 1 active state at any given point... in summary, your problem is not where you think it is – Felipe May 04 '18 at 06:45
  • Yes you were right. There was some issue in the sender's logic, not in the vehicle statechart. Also, i had to use 'messageVal' as a Parameter of vehicle agent, not as a general Variable. This helps every vehicle to own the message value to itself, regardless of other vehicle that entered the statechart and changed the value of 'messageVal' :).. I think I couldn't convey my problem properly.. But anyways, Thanks Felipe for guiding :) – Murk May 04 '18 at 14:54

0 Answers0