IRule find_solution = new Rule("find_solution", cond, new IAction()
/** * Get a unique rulename for a given rulename. * @param rb The rulebase. * @param rulename The rulename. * @return The (possibly modified) rulename. */ public static String getUniqueRuleName(IRulebase rb, String rulename) { int count = 1; String suffix = ""; Rule testrule = new Rule(rulename+suffix, null, null); while(rb.getRules().contains(testrule)) { suffix = "_"+count; testrule = new Rule(rulename+suffix, null, null); } return testrule.getName(); } }
/** * 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); } }
/** * Get a unique rulename for a given rulename. * @param rb The rulebase. * @param rulename The rulename. * @return The (possibly modified) rulename. */ public static String getUniqueRuleName(IRulebase rb, String rulename) { int count = 1; String suffix = ""; Rule testrule = new Rule(rulename+suffix, null, null); while(rb.getRules().contains(testrule)) { suffix = "_"+count; testrule = new Rule(rulename+suffix, null, null); } return testrule.getName(); } }
/** * 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; }
return new Rule("continue", c, action);
/** * 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; }
/** * 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;
invert ? new NotCondition((ICondition)usercond) : (ICondition)usercond }); ret = tmp.length==2 ? new Rule(rulename, cond, (IAction)tmp[1]) : new Rule(rulename, cond, (IAction)tmp[1], (IPriorityEvaluator)tmp[2]); ICondition cond = ParserHelper.parseCondition((ICondition)tmp[0], text, language, state.getTypeModel(), imports, null, helper, tmp.length>=4 ? (Variable)tmp[3] : null, invert); ret = tmp.length==2 ? new Rule(rulename, cond, (IAction)tmp[1]) : new Rule(rulename, cond, (IAction)tmp[1], (IPriorityEvaluator)tmp[2]);
return new Rule("goal_deliberate_deactivation", new AndCondition(new ICondition[]{goalcon, rcapacon}), action);
return new Rule("path done", new AndCondition(new ICondition[]{pd1, pd2}), action);
rb.addRule(new Rule("new_message", msgcon, new IAction()
Rule agent_execute_action = new Rule("agent_execute_action", new AndCondition(new ICondition[]{actioncon, ragentcon}), action); return agent_execute_action;