/** * 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; }
/** * Get the string representation. * @return The string representation. */ public String toString() { return "("+getValueSource()+getOperator()+value+")"; } }
/** * Get the variables. * @return The declared variables. */ public List getVariables() { return getVariablesForValueSource(getValueSource()); }
IValueExtractor ex = createValueExtractor(-1, lic.getValueSource(), -1, context, false); ConstantExtractor vex = new ConstantExtractor(lic.getValue()); ret.add(new ConstraintEvaluator(lic.getOperator(), ex, vex));
IValueExtractor ex = createValueExtractor(-1, lic.getValueSource(), -1, context, false); ConstantExtractor vex = new ConstantExtractor(lic.getValue()); ret.add(new ConstraintEvaluator(lic.getOperator(), ex, vex));
/** * 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}; }
/** * Get the string representation. * @return The string representation. */ public String toString() { return "("+getValueSource()+getOperator()+value+")"; } }
/** * Get the variables. * @return The declared variables. */ public List getVariables() { return getVariablesForValueSource(getValueSource()); }
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.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_PAUSED)); rgoalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, model));
/** * 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 rule "all done". */ public IRule createAllDoneRule() { // ;;; ******** // ;;; all_done // ;;; ******** // // (defrule all_done // (context (state print_results)) // => // (halt)) ObjectCondition ad = new ObjectCondition(Manners.context_type); ad.addConstraint(new LiteralConstraint(Manners.context_has_state, "print_results")); IAction action = new IAction() { public void execute(IOAVState state, IVariableAssignments assignments) { System.out.println("TERMINATED!!!"); } }; return new Rule("all done", ad, action); } }
goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_ACTIVE)); goalcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.goal_has_finishedplans, fplans)); IConstraint rebapl = new AndConstraint(new IConstraint[]{new LiteralConstraint(OAVBDIRuntimeModel.processableelement_has_apl, null, IOperator.EQUAL), new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_rebuild}, Boolean.FALSE)}); IConstraint nomoreplan = new OrConstraint(new IConstraint[]{new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_retry}, Boolean.FALSE), rebapl}); goalcon.addConstraint(nomoreplan); goalcon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_recur}, Boolean.FALSE)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.achievegoal_type, IOperator.INSTANCEOF)); goalcon.addConstraint(new BoundConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.achievegoal_has_targetcondition}, target)); plancon.addConstraint(new BoundConstraint(null, rplan)); plancon.addConstraint(new BoundConstraint(null, fplans, IOperator.CONTAINS)); plancon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.plan_has_processingstate, OAVBDIRuntimeModel.PLANPROCESSINGTATE_FINISHED)); IConstraint goalhastarget = new LiteralConstraint(target, null, IOperator.NOTEQUAL); IConstraint planfail = new LiteralConstraint(OAVBDIRuntimeModel.plan_has_lifecyclestate, OAVBDIRuntimeModel.PLANLIFECYCLESTATE_FAILED); IConstraint planabort = new LiteralConstraint(OAVBDIRuntimeModel.plan_has_lifecyclestate, OAVBDIRuntimeModel.PLANLIFECYCLESTATE_ABORTED); plancon.addConstraint(new OrConstraint(new IConstraint[]{goalhastarget, planfail, planabort}));
goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_ACTIVE)); goalcon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVAttributeType.OBJECTTYPE}, OAVBDIMetaModel.achievegoal_type, IOperator.NOTEQUAL)); goalcon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_retry}, Boolean.TRUE)); goalcon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.processableelement_has_posttoall}, Boolean.FALSE)); IConstraint conaplnotnull = new LiteralConstraint(OAVBDIRuntimeModel.processableelement_has_apl, null, IOperator.NOTEQUAL); OrConstraint orcon = new OrConstraint(new IConstraint[]{conaplnotnull, new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_rebuild}, Boolean.TRUE)}); goalcon.addConstraint(orcon); goalcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.goal_has_finishedplans, rplan, IOperator.CONTAINS)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.processableelement_has_state, OAVBDIRuntimeModel.PROCESSABLEELEMENT_CANDIDATESSELECTED)); plancon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.plan_has_processingstate, OAVBDIRuntimeModel.PLANPROCESSINGTATE_FINISHED));
goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_ACTIVE)); goalcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.goal_has_finishedplans, fplans)); IConstraint rebapl = new AndConstraint(new IConstraint[]{new LiteralConstraint(OAVBDIRuntimeModel.processableelement_has_apl, null, IOperator.EQUAL), new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_rebuild}, Boolean.FALSE)}); IConstraint nomoreplan = new OrConstraint(new IConstraint[]{new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_retry}, Boolean.FALSE), rebapl}); goalcon.addConstraint(nomoreplan); goalcon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_recur}, Boolean.FALSE)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.querygoal_type, IOperator.INSTANCEOF)); plancon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.plan_has_processingstate, OAVBDIRuntimeModel.PLANPROCESSINGTATE_FINISHED));
constraint = new LiteralConstraint(valuesource, val, op); else constraint = new LiteralConstraint(valuesource, val);
constraint = new LiteralConstraint(valuesource, val, op); else constraint = new LiteralConstraint(valuesource, val);
/** * 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; }
goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_ACTIVE)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_INPROCESS)); IConstraint nocandcon = new LiteralConstraint(OAVBDIRuntimeModel.processableelement_has_state, OAVBDIRuntimeModel.PROCESSABLEELEMENT_NOCANDIDATES); IConstraint candselcon = new LiteralConstraint(OAVBDIRuntimeModel.processableelement_has_state, OAVBDIRuntimeModel.PROCESSABLEELEMENT_CANDIDATESSELECTED); IConstraint noaplcon = new LiteralConstraint(OAVBDIRuntimeModel.processableelement_has_apl, null); IConstraint notrebuild = new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_rebuild}, Boolean.FALSE); goalcon.addConstraint(new OrConstraint(new IConstraint[]{nocandcon, new AndConstraint(new IConstraint[]{candselcon, noaplcon, notrebuild})})); goalcon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_recur}, Boolean.TRUE)); plancon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.plan_has_reason, rgoal));
goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_ACTIVE, IOperator.NOTEQUAL)); OrConstraint statecon = new OrConstraint(new IConstraint[]{ new LiteralConstraint(OAVBDIRuntimeModel.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_INPROCESS), new LiteralConstraint(OAVBDIRuntimeModel.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_PAUSED) }); goalcon.addConstraint(statecon);
/** * 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; }