Quantcast

Scheduling methods and priorities

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Scheduling methods and priorities

cnietocoria
Hello, 

Here is the situation, in my model I have different agents types with its own methods. Lets say that there is one that is the main agent on the context, it performs and schedule more or less 6 methods, with different priorities. So this main agent posses a method that manages  a Map<K,V> variable, I iterate among the quantity of keys, their values and change the values after the calculations.

However, I have other agent that given a certain periodicity, it schedules a method that updates the content in a variable, adding a new set (key. values) on the agents (main agent kind). 

This error: java.util.ConcurrentModificationException occurs when the method for updating the variable on the main agent is scheduled. So I tried diverse things, and found out that the problem is when the second agent schedules the method and try to update the variable, so before it might occurs that some agents of the main kind wants to perform modification on the variable. 

To solve it i tried to change the priority on the method scheduling with NO_DURATION constant for the priority, but the error still happen, the curious thing is that it happens 2 ticks later. Also, I tried to understand if the code has some errors and do not schedule the updating method. The simulation runs without errors, it just not add new values.  

I have to explain that for updating I just have one agent of the second kind (not main agent), that checks out for every agent of the main kind. So this leads to my question:

Is it possible to in the starting of a tick say to the Scheduler I want that this method for this agent executes first than everything?

Thanks in advance, 

--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Scheduling methods and priorities

srcnick
I’m not sure I fully understand, but you will get these sorts of errors when iterating over a Java collection like a list or a map and as part of that iteration modify the collection in some way. The solution is to gather the changes that you need make when iterating, and then when the iteration is finished, make those changes.  You can do that in a single scheduled method or schedule the “execute changes” at some point after the iteration.

Is this what is going on in your case, in the course of the main agent iterating among the keys does it call methods that modifiy the map? If this doesn’t help can you say more about how the actions that modify the map are scheduled with respect to each other?

The NO_DURATION constant only applies to actions that are scheduled in the background, which I don’t think applies here.

Nick



On Oct 10, 2016, at 5:39 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello, 

Here is the situation, in my model I have different agents types with its own methods. Lets say that there is one that is the main agent on the context, it performs and schedule more or less 6 methods, with different priorities. So this main agent posses a method that manages  a Map<K,V> variable, I iterate among the quantity of keys, their values and change the values after the calculations.

However, I have other agent that given a certain periodicity, it schedules a method that updates the content in a variable, adding a new set (key. values) on the agents (main agent kind). 

This error: java.util.ConcurrentModificationException occurs when the method for updating the variable on the main agent is scheduled. So I tried diverse things, and found out that the problem is when the second agent schedules the method and try to update the variable, so before it might occurs that some agents of the main kind wants to perform modification on the variable. 

To solve it i tried to change the priority on the method scheduling with NO_DURATION constant for the priority, but the error still happen, the curious thing is that it happens 2 ticks later. Also, I tried to understand if the code has some errors and do not schedule the updating method. The simulation runs without errors, it just not add new values.  

I have to explain that for updating I just have one agent of the second kind (not main agent), that checks out for every agent of the main kind. So this leads to my question:

Is it possible to in the starting of a tick say to the Scheduler I want that this method for this agent executes first than everything?

Thanks in advance, 

--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Scheduling methods and priorities

cnietocoria
Hi Nick, 

I think that you understand, and is a very good solution I will try it. 

The way that the agents modify is: The main agent kind holds a cohort of population and per each year I have to add a new cohort. So I store in the Map <yearNumber, numberOfIndividuals>. To update the cohorts I use a method in the second class agent. The method is scheduled with a high priority, although I have this error. As you mention I have to iterate in this Map using methods inside of the main class. 

I was thinking about a different solution for my problem with the cohorts, but I will try to implement what you suggest. 

Thanks    

On Tue, Oct 11, 2016 at 3:33 PM, Nick Collier <[hidden email]> wrote:
I’m not sure I fully understand, but you will get these sorts of errors when iterating over a Java collection like a list or a map and as part of that iteration modify the collection in some way. The solution is to gather the changes that you need make when iterating, and then when the iteration is finished, make those changes.  You can do that in a single scheduled method or schedule the “execute changes” at some point after the iteration.

Is this what is going on in your case, in the course of the main agent iterating among the keys does it call methods that modifiy the map? If this doesn’t help can you say more about how the actions that modify the map are scheduled with respect to each other?

The NO_DURATION constant only applies to actions that are scheduled in the background, which I don’t think applies here.

Nick



On Oct 10, 2016, at 5:39 AM, Cesar Nieto Coria <[hidden email]> wrote:

Hello, 

Here is the situation, in my model I have different agents types with its own methods. Lets say that there is one that is the main agent on the context, it performs and schedule more or less 6 methods, with different priorities. So this main agent posses a method that manages  a Map<K,V> variable, I iterate among the quantity of keys, their values and change the values after the calculations.

However, I have other agent that given a certain periodicity, it schedules a method that updates the content in a variable, adding a new set (key. values) on the agents (main agent kind). 

This error: java.util.ConcurrentModificationException occurs when the method for updating the variable on the main agent is scheduled. So I tried diverse things, and found out that the problem is when the second agent schedules the method and try to update the variable, so before it might occurs that some agents of the main kind wants to perform modification on the variable. 

To solve it i tried to change the priority on the method scheduling with NO_DURATION constant for the priority, but the error still happen, the curious thing is that it happens 2 ticks later. Also, I tried to understand if the code has some errors and do not schedule the updating method. The simulation runs without errors, it just not add new values.  

I have to explain that for updating I just have one agent of the second kind (not main agent), that checks out for every agent of the main kind. So this leads to my question:

Is it possible to in the starting of a tick say to the Scheduler I want that this method for this agent executes first than everything?

Thanks in advance, 

--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




--
--------------------------------------------------------------
PhD. Student at University of Camerino
Ing. Cesar Augusto Nieto Coria
skype: cnietocoria


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Loading...