Menu

Using Beliefs with Goal Conditions seems to block ChangeEvent triggers

Help
sdr3
2017-03-08
2017-03-14
  • sdr3

    sdr3 - 2017-03-08

    Hello,

    I wrote an agent that was triggering self regulating plans based on a belief (ie. @Trigger(factchangeds="belief")). then I tried using this same belief in a goal condition (@GoalCreationCondition). When I ran the agent with the Goal implemented, the plans associated with triggers senstive to this belief would not execute. I created a test case Agent to observe this behaviour.

    I have implemented a belief called number which triggers the numberChangedPlan plan with the factchangeds propertyListener in the trigger.

    I have also created a dummy goal GenericGoal which uses the belief number in the @GoalCreationCondition. If you run the agent with the goal present in the agent description class, then the numberChangedPlan will not be triggered. with the Goal commented out, numberChangedPlan is triggered.

    Is this expected behaviour?

    public class SelectiveBeliefChangeBDI {
    
        @Belief
        protected double number;
    
        @AgentCreated
        public void init(IInternalAccess agent){
            number = 9.2;
        }
    
        @AgentBody
        public void body(IInternalAccess agent){
    
            number = 9.4;
            number = 9.5;
    
        }
    
        @Plan(trigger=@Trigger(factchangeds="number"))
        public void numberChangedPlan(ChangeEvent event){
            ChangeInfo<Double> change = (ChangeInfo<Double>) event.getValue();
            System.out.println(agentName + "number has changed to:  " + change.getValue() + " from " + change.getOldValue());
    
        }
    
        @Goal
        public class GenericGoal{
    
            protected double num1;
            protected double result;
    
            @GoalCreationCondition
            public boolean preCheckNumber(){
                return number>20.0;
            }
    
            public GenericGoal(){
                this.num1 = number;
            }
    
        }
    
    }
    

    EDIT: I removed unrelated code from the example

     

    Last edit: sdr3 2017-03-08
  • Alexander Pokahr

    Hi Steve,

    I can confirm that I'm able to reproduce this behavior.
    It looks odd and seems to be a bug. I will investigate further and come back to you.

    Cheers,
    Alex

     
  • Alexander Pokahr

    Hi Steve,

    I found the problem.

    The @GoalCreationCondition is only supported on constructors and static methods.
    Unfortunately, instead of reporting an error, the init of the agent silently fails, such that
    the plans are not executed. I will try to include better error reporting in the next release
    and also provide more documentation on the @GoalCreationCondition annotation.

    Meanwhile, the following code should do what you want:

    @Goal
    public static class GenericGoal
    {
        protected double    num1;
    
        protected double    result;
    
        @GoalCreationCondition
        public static boolean preCheckNumber(SelectiveBeliefChangeBDI agent)
        {
            System.out.println("checking: "+agent.number);
            return agent.number > 20.0;
        }
    
        public GenericGoal(SelectiveBeliefChangeBDI agent)
        {
            this.num1 = agent.number;
            System.out.println("created goal: "+num1);
        }
    }
    

    Note the static modifier on the goal class and the preCheckNumber method.
    Being static also requires injecting the outer agent object as a parameter, which
    is luckily assigned automatically by Jadex.

    Cheers,
    Alex

     

    Last edit: Alexander Pokahr 2017-03-15
  • sdr3

    sdr3 - 2017-03-16

    Hello Alex,
    Thankyou for the quick response. :) I assume that this will also apply for other Goal conditional annotations, such as @GoalRecur, @GoalMaintainCondition, etc. ?

    I will test and post back :)

     
  • sdr3

    sdr3 - 2017-03-29

    Hi Alex,
    can you please post the source code of your test, my implementation of your suggestion is resulting in the same issue. It looks eerily like you are passing something like an ExternalAccess object to the goal to monitor the belief set with.

    for now I have made a work around by constructing extra redundant plans to trigger the goal in certain conditions, however in the future i want to utilize GoalRecur, GoalTarget, etc methods to control agent behaviour.

    Kind Regards

     
  • Alexander Pokahr

    Hi Steve,

    it is already included in the latest nightly distributions.

    You can find it, e.g., in:
    - jadex-standard-3.0.69.zip in the file
    - jadex-3.0.69/sources.zip and there in the folder
    - sources/jadex-applications-bdiv3/src/main/java/jadex/bdiv3/testcases/semiautomatic as
    - SelectiveBeliefChangeBDI.java

    Regarding your previous question:
    Only the creation condition method needs to be static (because there is no goal object, yet).
    The other conditions are non-static and are executed seperately on each goal object (when there are multiple instances of the same goal).

    Cheers,
    Alex

     

Log in to post a comment.