IConstraint msgrec = new LiteralConstraint(OAVBDIRuntimeModel.changeevent_has_type, OAVBDIRuntimeModel.CHANGEEVENT_MESSAGEEVENTRECEIVED); IConstraint msgsent = new LiteralConstraint(OAVBDIRuntimeModel.changeevent_has_type, OAVBDIRuntimeModel.CHANGEEVENT_MESSAGEEVENTSENT); cecon.addConstraint(new OrConstraint(new IConstraint[]{msgrec, msgsent})); cecon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.changeevent_has_element, revent)); cecon.addConstraint(new BoundConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.changeevent_has_element, OAVBDIRuntimeModel.element_has_model}, mevent)); IConstraint relme = new BoundConstraint(OAVBDIRuntimeModel.listenerentry_has_relevants, mevent, IOperator.CONTAINS); IConstraint relre = new BoundConstraint(OAVBDIRuntimeModel.listenerentry_has_relevants, revent, IOperator.CONTAINS); liscon.addConstraint(new OrConstraint(new IConstraint[]{relme, relre}));
IConstraint c1 = new BoundConstraint(OAVBDIRuntimeModel.capability_has_internalevents, rpe, IOperator.CONTAINS); IConstraint c2 = new BoundConstraint(OAVBDIRuntimeModel.capability_has_messageevents, rpe, IOperator.CONTAINS); capcon.addConstraint(new OrConstraint(new IConstraint[]{c1, c2})); IConstraint co1 = new BoundConstraint(OAVBDIRuntimeModel.waitabstraction_has_internaleventtypes, mpe, IOperator.CONTAINS); IConstraint co2 = new BoundConstraint(OAVBDIRuntimeModel.waitabstraction_has_messageeventtypes, mpe, IOperator.CONTAINS); wacon.addConstraint(new OrConstraint(new IConstraint[]{co1, co2}));
IConstraint aplnull = new LiteralConstraint(OAVBDIRuntimeModel.processableelement_has_apl, null, IOperator.EQUAL); IConstraint notretry = new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_retry}, Boolean.FALSE); goalcon.addConstraint(new AndConstraint(new IConstraint[]{notrecur, new OrConstraint(new IConstraint[]{notretry, new AndConstraint(new IConstraint[]{notreb, aplnull})})}));
goalcon.addConstraint(new BoundConstraint(null, 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)
/** * 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; }
rplancon.addConstraint(new OrConstraint(new IConstraint[]{co1, co2}));
rplancon.addConstraint(new OrConstraint(new IConstraint[]{co1, co2}));
rplancon.addConstraint(new OrConstraint(new IConstraint[]{co1, co2}));
IConstraint con1 = new BoundConstraint(OAVBDIRuntimeModel.capability_has_plans, rpe, IOperator.CONTAINS); IConstraint con2 = new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rpe, IOperator.CONTAINS); rcapacon.addConstraint(new OrConstraint(new IConstraint[]{con1, con2}));
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)); 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}));
IConstraint co1 = new BoundConstraint(OAVBDIRuntimeModel.waitabstraction_has_goals, rpe, IOperator.CONTAINS); IConstraint co2 = new BoundConstraint(OAVBDIRuntimeModel.waitabstraction_has_goalfinisheds, mpe, IOperator.CONTAINS); wacon.addConstraint(new OrConstraint(new IConstraint[]{co1, co2}));
IConstraint con1 = new BoundConstraint(OAVBDIRuntimeModel.capability_has_plans, rpe, IOperator.CONTAINS); IConstraint con2 = new BoundConstraint(OAVBDIRuntimeModel.capability_has_goals, rpe, IOperator.CONTAINS); rcapacon.addConstraint(new OrConstraint(new IConstraint[]{con1, con2}));
IConstraint rem = new LiteralConstraint(OAVBDIRuntimeModel.changeevent_has_type, OAVBDIRuntimeModel.CHANGEEVENT_FACTREMOVED); IConstraint change = new LiteralConstraint(OAVBDIRuntimeModel.changeevent_has_type, OAVBDIRuntimeModel.CHANGEEVENT_FACTCHANGED); cecon.addConstraint(new OrConstraint(new IConstraint[]{add, rem, change})); cecon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.changeevent_has_element, rbeliefset)); cecon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.changeevent_has_element, OAVBDIRuntimeModel.beliefset_type, IOperator.INSTANCEOF));
/** * Rule to abort a plan when the corresponding goal was deactivated. */ public static Rule createPlanInstanceAbortRule() { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); Variable rplan = new Variable("?rplan", OAVBDIRuntimeModel.plan_type); Variable rcapa = new Variable("?rcapa", OAVBDIRuntimeModel.capability_type); ObjectCondition goalcon = new ObjectCondition(rgoal.getType()); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_INPROCESS, IOperator.NOTEQUAL)); ObjectCondition plancon = new ObjectCondition(rplan.getType()); plancon.addConstraint(new BoundConstraint(null, rplan)); plancon.addConstraint(new OrConstraint( new LiteralConstraint(OAVBDIRuntimeModel.plan_has_lifecyclestate, OAVBDIRuntimeModel.PLANLIFECYCLESTATE_NEW), new LiteralConstraint(OAVBDIRuntimeModel.plan_has_lifecyclestate, OAVBDIRuntimeModel.PLANLIFECYCLESTATE_BODY))); plancon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.plan_has_reason, rgoal)); ObjectCondition capcon = new ObjectCondition(rcapa.getType()); capcon.addConstraint(new BoundConstraint(null, rcapa)); capcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_plans, rplan, IOperator.CONTAINS)); Rule abort_plan = new Rule("planinstance_abort", new AndCondition(new ICondition[]{goalcon, plancon, capcon}), PLAN_ABORT); return abort_plan; }
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));
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));
rpe, IOperator.CONTAINS)); plancon.addConstraint(new OrConstraint(new IConstraint[]
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));
targetcapcon.addConstraint(new OrConstraint(new IConstraint[]
ingoalcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.element_has_model, mgoal)); ingoalcon.addConstraint(new OrConstraint(new LiteralConstraint(OAVBDIRuntimeModel.goal_has_lifecyclestate, OAVBDIRuntimeModel.GOALLIFECYCLESTATE_ACTIVE, IOperator.NOTEQUAL), new AndConstraint(new LiteralConstraint(inmode, OAVBDIMetaModel.INHIBITS_WHEN_IN_PROCESS), new LiteralConstraint(OAVBDIRuntimeModel.goal_has_processingstate, OAVBDIRuntimeModel.GOALPROCESSINGSTATE_INPROCESS, IOperator.NOTEQUAL))));