I want a goal to be unique, so that only a single instance of the goal is active at a time. The unique flag should do the job, but it doesn't - which is a big issue in my case because the executed plan is repeated for an excessive amount of times. The goal does not use any parameters.
Here is a small example agent which demonstrates this behavior - the unique flag in the @Goal-Annotation has no effect and two goals become active at the same time.
Ah, thank you, this makes sense. Implementing hashCode() and equals() for my unique goals fixed the problem for me.
I noticed that the constructor is still called twice, but only goal finishes. I assume this is expected behavior - so a second instance is created despite the unique flag, but then Jadex compares it to the first one via equals(), which returns true, and the second goal is dropped?
I really think this "contract" about the unique flag should be found in the documentation somewhere - the only place where I found some information on it was in the outdated "Goals User Guide", which says:
By default two goal instances of the same type are equal, when all parameters and parameter sets have the same values.
Obviously, this seems not to directly apply to BDIv3.
So a description in the API documentation for the "unique" element of the Goal annotation which mentions the equals() and hashCode() methods would be very helpful.
Again, thank you for your fast reply!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I want a goal to be unique, so that only a single instance of the goal is active at a time. The unique flag should do the job, but it doesn't - which is a big issue in my case because the executed plan is repeated for an excessive amount of times. The goal does not use any parameters.
Here is a small example agent which demonstrates this behavior - the unique flag in the @Goal-Annotation has no effect and two goals become active at the same time.
The output of execution is:
So a second instance of the goal is created although the first is still active.
Is this a bug? Or am I missing something? I'm using Jadex 3.0.117.
Hi,
the unique flag works based on equals test on the goal class/object. So in your case they are all different as no equals method has been implemented.
Best,
Lars
Ah, thank you, this makes sense. Implementing hashCode() and equals() for my unique goals fixed the problem for me.
I noticed that the constructor is still called twice, but only goal finishes. I assume this is expected behavior - so a second instance is created despite the unique flag, but then Jadex compares it to the first one via equals(), which returns true, and the second goal is dropped?
I really think this "contract" about the unique flag should be found in the documentation somewhere - the only place where I found some information on it was in the outdated "Goals User Guide", which says:
Obviously, this seems not to directly apply to BDIv3.
So a description in the API documentation for the "unique" element of the Goal annotation which mentions the equals() and hashCode() methods would be very helpful.
Again, thank you for your fast reply!