/** * Expressions, which are unrelated to real object * conditions should be bound to the dummy condition. * After building all constraints, the dummy condition * will be removed by reassigning its constraints to * a suitable object condition (respecting variable assignment order). */ public ObjectCondition getDummyCondition() { if(dummy==null) { dummy = new ObjectCondition(OAVJavaType.java_object_type); addCondition(dummy); } return dummy; }
/** * Expressions, which are unrelated to real object * conditions should be bound to the dummy condition. * After building all constraints, the dummy condition * will be removed by reassigning its constraints to * a suitable object condition (respecting variable assignment order). */ public ObjectCondition getDummyCondition() { if(dummy==null) { dummy = new ObjectCondition(OAVJavaType.java_object_type); addCondition(dummy); } return dummy; }
/** * Create a new object condition with the given constraints. * Also adds mappings corresponding to bound constraints (if any). * @param type The object type. * @param constraints The constraints (if any). */ public ObjectCondition createObjectCondition(OAVObjectType type, IConstraint[] constraints) { ObjectCondition ocon = new ObjectCondition(type); for(int i=0; constraints!=null && i<constraints.length; i++) { ocon.addConstraint(constraints[i]); } addCondition(ocon); return ocon; }
/** * Create a new object condition with the given constraints. * Also adds mappings corresponding to bound constraints (if any). * @param type The object type. * @param constraints The constraints (if any). */ public ObjectCondition createObjectCondition(OAVObjectType type, IConstraint[] constraints) { ObjectCondition ocon = new ObjectCondition(type); for(int i=0; constraints!=null && i<constraints.length; i++) { ocon.addConstraint(constraints[i]); } addCondition(ocon); return ocon; }
/** * Create the plan context invalid rule. * @param usercond The ADF part of the target condition. * @param mplan The plan model element. */ public static Object[] createPlanContextInvalidUserRule(Object mplan) { Variable rplan = new Variable("?rplan", OAVBDIRuntimeModel.plan_type); Variable rcapa = new Variable("?rcapa", OAVBDIRuntimeModel.capability_type); ObjectCondition plancon = new ObjectCondition(OAVBDIRuntimeModel.plan_type); plancon.addConstraint(new BoundConstraint(null, rplan)); plancon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, mplan)); ObjectCondition capcon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capcon.addConstraint(new BoundConstraint(null, rcapa)); capcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_plans, rplan, IOperator.CONTAINS)); return new Object[]{new AndCondition(new ICondition[]{plancon, capcon}), PLAN_ABORT, null, null, Boolean.TRUE}; }
/** * Create a goal, when the ADF creation condition triggers. * @param model The goal model element. */ public static Object[] createGoalCreationUserRule(Object model) { Variable ragent = new Variable("?ragent", OAVBDIRuntimeModel.agent_type); Variable rcapa = new Variable("?rcapa", OAVBDIRuntimeModel.capability_type); Variable mgoal = new Variable("?mgoal", OAVBDIMetaModel.goal_type); ObjectCondition ragentcon = new ObjectCondition(OAVBDIRuntimeModel.agent_type); ragentcon.addConstraint(new BoundConstraint(null, ragent)); ragentcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.agent_has_state, OAVBDIRuntimeModel.AGENTLIFECYCLESTATE_ALIVE)); ObjectCondition capcon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capcon.addConstraint(new BoundConstraint(null, rcapa)); capcon.addConstraint(new BoundConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.capability_has_goals}, mgoal, IOperator.CONTAINS)); ObjectCondition mgoalcon = new ObjectCondition(OAVBDIMetaModel.goal_type); mgoalcon.addConstraint(new BoundConstraint(null, mgoal)); mgoalcon.addConstraint(new LiteralConstraint(null, model)); return new Object[]{ new AndCondition(new ICondition[]{ragentcon, mgoalcon, capcon}), GOAL_CREATION_ACTION}; }
/** * Create the maintaingoal succeeded rule. * @param usercond The ADF part of the target condition. * @param model The goal model element. */ public static Object[] createMaintaingoalSucceededUserRule(Object model) { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); Variable rcapa = new Variable("?rcapa", OAVBDIRuntimeModel.capability_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); // goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.maintaingoal_type, IOperator.INSTANCEOF)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, model)); ObjectCondition capacon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capacon.addConstraint(new BoundConstraint(null, rcapa)); capacon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rgoal, IOperator.CONTAINS)); return new Object[]{ new AndCondition(new ICondition[]{goalcon, capacon}), GOAL_IDLE, IPriorityEvaluator.PRIORITY_1}; }
/** * Create the achievegoal succeeded rule (for goals with target condition). * @param usercond The ADF part of the target condition. * @param model The goal model element. */ public static Object[] createAchievegoalSucceededUserRule(Object model) { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); Variable rcapa = new Variable("?rcapa", OAVBDIRuntimeModel.capability_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, model)); ObjectCondition capacon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capacon.addConstraint(new BoundConstraint(null, rcapa)); capacon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rgoal, IOperator.CONTAINS)); return new Object[]{ new AndCondition(new ICondition[]{goalcon, capacon}), GOAL_SUCCEEDED, IPriorityEvaluator.PRIORITY_1}; }
/** * Set a suspended goal to option state, when the ADF suspension condition triggers. * @param usercond The ADF condition part. * @param model The goal model element. */ public static Object[] createGoalOptionUserRule(Object model) { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); Variable rcapa = new Variable("?rcapa", OAVBDIRuntimeModel.capability_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_SUSPENDED)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, model)); ObjectCondition capcon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capcon.addConstraint(new BoundConstraint(null, rcapa)); capcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rgoal, IOperator.CONTAINS)); return new Object[]{ new AndCondition(new ICondition[]{goalcon, capcon}), GOAL_OPTION_ACTION}; }
/** * Create achievegoal processing rule. */ protected static Rule createAchievegoalProcessingRule() { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_ACTIVE)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_IDLE)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.achievegoal_type, IOperator.INSTANCEOF)); ObjectCondition capcon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rgoal, IOperator.CONTAINS)); Rule achievegoal_processing = new Rule("achievegoal_processing", new AndCondition(new ICondition[]{goalcon, capcon}), GOAL_PROCESSING); return achievegoal_processing; }
/** * Create querygoal processing rule. */ protected static Rule createQuerygoalProcessingRule() { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_ACTIVE)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_IDLE)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.querygoal_type, IOperator.INSTANCEOF)); ObjectCondition capcon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rgoal, IOperator.CONTAINS)); Rule querygoal_processing = new Rule("querygoal_processing", new AndCondition(new ICondition[]{goalcon, capcon}), GOAL_PROCESSING); return querygoal_processing; }
/** * Create performgoal processing rule. */ protected static Rule createPerformgoalProcessingRule() { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_ACTIVE)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_IDLE)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.performgoal_type, IOperator.INSTANCEOF)); ObjectCondition capacon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capacon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rgoal, IOperator.CONTAINS)); Rule performgoal_processing = new Rule("performgoal_processing", new AndCondition(new ICondition[]{goalcon, capacon}), GOAL_PROCESSING); return performgoal_processing; }
/** * Set a goal to suspended state, when the ADF context condition triggers. * @param usercond The ADF part of the context condition (will be negated automatically). * @param model The goal model element. */ public static Object[] createGoalSuspendUserRule(Object model) { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); Variable rcapa = new Variable("?rcapa", OAVBDIRuntimeModel.capability_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_SUSPENDED, IOperator.NOTEQUAL)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, model)); ObjectCondition capcon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capcon.addConstraint(new BoundConstraint(null, rcapa)); capcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rgoal, IOperator.CONTAINS)); return new Object[]{ new AndCondition(new ICondition[]{goalcon, capcon}), GOAL_SUSPEND_ACTION, null, null, Boolean.TRUE}; // Invert user condition. }
/** * Terminate agent rule. * Terminates the agent and removes it from the platform. */ protected static Rule createTerminateAgentRule() { ObjectCondition ragentcon = new ObjectCondition(OAVBDIRuntimeModel.agent_type); ragentcon.addConstraint(new BoundConstraint(null, new Variable("?ragent", OAVBDIRuntimeModel.agent_type))); ragentcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.agent_has_state, OAVBDIRuntimeModel.AGENTLIFECYCLESTATE_TERMINATED)); IAction action = new IAction() { public void execute(IOAVState state, IVariableAssignments assignments) { Object ragent = assignments.getVariableValue("?ragent"); cleanupAgent(state, ragent); } }; Rule agent_terminating = new Rule("agent_terminated", ragentcon, action); return agent_terminating; }
/** * Create the goal failed rule (when no plans available). * (state = nocandidates, recur = false) */ protected static Rule createGoalFailedRule() { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.processableelement_has_state, OAVBDIRuntimeModel.PROCESSABLEELEMENT_NOCANDIDATES)); goalcon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_recur}, Boolean.FALSE)); Rule goal_failed = new Rule("goal_failed", goalcon, GOAL_FAILED); return goal_failed; }
/** * Create the achievegoal succeeded rule (for goals without target condition). * The goal succeeds, when one plan succeeds. */ protected static Rule createAchievegoalSucceededRule() { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); Variable rplan = new Variable("?rplan", OAVBDIRuntimeModel.plan_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.goal_has_finishedplans, rplan, IOperator.CONTAINS)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.achievegoal_type, IOperator.INSTANCEOF)); goalcon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{ OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.achievegoal_has_targetcondition}, null)); ObjectCondition plancon = new ObjectCondition(OAVBDIRuntimeModel.plan_type); plancon.addConstraint(new BoundConstraint(null, rplan)); plancon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.plan_has_processingstate, OAVBDIRuntimeModel.PLANPROCESSINGTATE_FINISHED)); plancon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.plan_has_lifecyclestate, OAVBDIRuntimeModel.PLANLIFECYCLESTATE_PASSED)); ObjectCondition capcon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rgoal, IOperator.CONTAINS)); Rule achievegoal_succeeded = new Rule("achievegoal_succeeded", new AndCondition(new ICondition[]{plancon, goalcon, capcon}), GOAL_SUCCEEDED_PLAN_REMOVE, IPriorityEvaluator.PRIORITY_1); return achievegoal_succeeded; }
/** * Create the plan creation rule. * @param usercond The ADF part of the target condition. * @param mplan The plan model element. */ public static Object[] createPlanCreationUserRule(Object mplan) { Variable ragent = new Variable("?ragent", OAVBDIRuntimeModel.agent_type); Variable mplanvar = new Variable("?mplan", OAVBDIMetaModel.plan_type); Variable rcapa = new Variable("?rcapa", OAVBDIRuntimeModel.capability_type); ObjectCondition ragentcon = new ObjectCondition(OAVBDIRuntimeModel.agent_type); ragentcon.addConstraint(new BoundConstraint(null, ragent)); ragentcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.agent_has_state, OAVBDIRuntimeModel.AGENTLIFECYCLESTATE_ALIVE)); ObjectCondition rcapacon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); rcapacon.addConstraint(new BoundConstraint(null, rcapa)); rcapacon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.capability_has_plans}, mplan, IOperator.CONTAINS)); // Hack??? How to pass mplan to action!? rcapacon.addConstraint(new BoundConstraint(new Constant(mplan), mplanvar)); return new Object[]{ new AndCondition(new ICondition[]{ragentcon, rcapacon}), PLAN_CREATION}; }
/** * Reactivate a plan when goal cleanup is finished. */ public static Rule createPlanInstanceCleanupFinishedRule() { Variable rplan = new Variable("?rplan", OAVBDIRuntimeModel.plan_type); ObjectCondition plancon = new ObjectCondition(OAVBDIRuntimeModel.plan_type); plancon.addConstraint(new BoundConstraint(null, rplan)); plancon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.plan_has_subgoals, null)); plancon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.plan_has_processingstate, OAVBDIRuntimeModel.PLANPROCESSINGTATE_GOALCLEANUP)); IAction action = new IAction() { public void execute(IOAVState state, IVariableAssignments assignments) { Object rplan = assignments.getVariableValue("?rplan"); state.setAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_processingstate, OAVBDIRuntimeModel.PLANPROCESSINGTATE_READY); } }; Rule planinstance_goalcleanupfinished = new Rule("planinstance_goalcleanupfinished", plancon, action); return planinstance_goalcleanupfinished; }
/** * Start dropping a goal, when the ADF context condition triggers. * @param usercond The ADF part of the context condition. * @param model The goal model element. */ public static Object[] createGoalDroppingUserRule(Object model) { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); Variable rcapa = new Variable("?rcapa", OAVBDIRuntimeModel.capability_type); ObjectCondition rgoalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); rgoalcon.addConstraint(new BoundConstraint(null, rgoal)); rgoalcon.addConstraint(new AndConstraint( new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_DROPPING, IOperator.NOTEQUAL), new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_DROPPED, IOperator.NOTEQUAL))); rgoalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, model)); ObjectCondition rcapcon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); rcapcon.addConstraint(new BoundConstraint(null, rcapa)); rcapcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rgoal, IOperator.CONTAINS)); return new Object[]{new AndCondition(new ICondition[]{rgoalcon, rcapcon}), GOAL_DROPPING_ACTION}; }
/** * Start dropping a goal that is succeeded or failed. */ public static Rule createGoalDroppingRule() { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); Variable mgoal = new Variable("?mgoal", OAVBDIMetaModel.goal_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.element_has_model, mgoal)); goalcon.addConstraint(new AndConstraint( new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_DROPPING, IOperator.NOTEQUAL), new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_DROPPED, IOperator.NOTEQUAL))); goalcon.addConstraint(new OrConstraint( new LiteralConstraint(OAVBDIRuntimeModel.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_SUCCEEDED), new LiteralConstraint(OAVBDIRuntimeModel.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_FAILED))); // goalcon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVAttributeType.OBJECTTYPE}, OAVBDIMetaModel.maintaingoal_type, IOperator.NOTEQUAL)); ObjectCondition capcon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rgoal, IOperator.CONTAINS)); // Hack!!! Higher priority required to avoid deliberation activating goal that is already finished in option state (e.g. due to immediately fulfilled target condition) Rule goal_dropping = new Rule("goal_dropping", new AndCondition(new ICondition[]{goalcon, capcon}), GOAL_DROPPING_ACTION, IPriorityEvaluator.PRIORITY_1); return goal_dropping; }