/** * Parse a condition. * @param text The text. * @param model The model. * @param invert True if the user condition needs to be inverted. * @return The condition. */ public static ICondition parseCondition(ICondition precon, String text, String language, OAVTypeModel model, String[] imports, List errors, IParserHelper helper, Variable returnvar, boolean invert) { ICondition ret = null; if(language==null || language.equals("jcl")) { ret = parseJavaCondition(text, imports, errors, helper, returnvar, invert); } else if(language.equals("clips")) { ICondition usercon = parseClipsCondition(text, model, imports, errors); if(invert) usercon = new NotCondition(usercon); ret = precon==null ? usercon : usercon==null ? precon : new AndCondition(new ICondition[]{precon, usercon}); } return ret; }
/** * Build an and condition. */ public void buildAndCondition(AndCondition curcond, BuildContext context) { List conds = curcond.getConditions(); for(int i=0; i<conds.size(); i++) { buildCondition((ICondition)conds.get(i), context); } }
/** * Parse a condition. * @param text The text. * @param model The model. * @param invert True if the user condition needs to be inverted. * @return The condition. */ public static ICondition parseCondition(ICondition precon, String text, String language, OAVTypeModel model, String[] imports, List errors, IParserHelper helper, Variable returnvar, boolean invert) { ICondition ret = null; if(language==null || language.equals("jcl")) { ret = parseJavaCondition(text, imports, errors, helper, returnvar, invert); } else if(language.equals("clips")) { ICondition usercon = parseClipsCondition(text, model, imports, errors); if(invert) usercon = new NotCondition(usercon); ret = precon==null ? usercon : usercon==null ? precon : new AndCondition(new ICondition[]{precon, usercon}); } return ret; }
/** * Build an and condition. */ public void buildAndCondition(AndCondition curcond, BuildContext context) { List conds = curcond.getConditions(); for(int i=0; i<conds.size(); i++) { buildCondition((ICondition)conds.get(i), context); } }
List ocons = curcond.getObjectConditions(); if(ocons.size()>1) buildAndCondition(new AndCondition(ocons), context); else buildObjectCondition((ObjectCondition)ocons.get(0), context);
lcons.addAll(i+1, ((AndCondition)lcons.get(i)).getConditions()); lcons.remove(i);
List ocons = curcond.getObjectConditions(); if(ocons.size()>1) buildAndCondition(new AndCondition(ocons), context); else buildObjectCondition((ObjectCondition)ocons.get(0), context);
lcons.addAll(i+1, ((AndCondition)lcons.get(i)).getConditions()); lcons.remove(i);
condition = new AndCondition(conds);
condition = new AndCondition(conds);
new AndCondition(new ICondition[]{ragentcon, new NotCondition(new AndCondition(new ICondition[]{rgoalcon, rcapacon1})), new NotCondition(new AndCondition(new ICondition[]{rplancon, rcapacon2}))}), action); return agent_terminating;
/** * Cleanup rule for removing change events. */ protected static Rule createRemoveChangeEventRule() { Variable ragent = new Variable("?ragent", OAVBDIRuntimeModel.agent_type); Variable changeevent = new Variable("?changeevent", OAVBDIRuntimeModel.changeevent_type); ObjectCondition changecon = new ObjectCondition(OAVBDIRuntimeModel.changeevent_type); changecon.addConstraint(new BoundConstraint(null, changeevent)); ObjectCondition ragentcon = new ObjectCondition(OAVBDIRuntimeModel.agent_type); ragentcon.addConstraint(new BoundConstraint(null, ragent)); ragentcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.agent_has_changeevents, changeevent, IOperator.CONTAINS)); IAction action = new IAction() { public void execute(IOAVState state, IVariableAssignments assignments) { Object changeevent = assignments.getVariableValue("?changeevent"); Object ragent = assignments.getVariableValue("?ragent"); state.removeAttributeValue(ragent, OAVBDIRuntimeModel.agent_has_changeevents, changeevent); // System.err.println("removing: "+changeevent+", "+BDIInterpreter.getInterpreter(state).getAgentAdapter().getComponentIdentifier()); } }; Rule rule = new Rule("changeevent_remove", new AndCondition(new ICondition[]{changecon, ragentcon}), action); return rule; }
/** * 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; }
/** * 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; }
Rule message_no_match = new Rule("message_no_match", new AndCondition(new ICondition[]{messagecon, agentcon}), action);//, pe); return message_no_match;
new AndCondition(new ICondition[]{goalcon, rcapacon}), action);
return new Rule("path done", new AndCondition(new ICondition[]{pd1, pd2}), action);
return new Rule("goal_exit_active_state", new AndCondition(new ICondition[]{goalcon, capcon}), action, IPriorityEvaluator.PRIORITY_1);
/** * 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}; }