public void actionPerformed(ActionEvent e) { steppable.setStepmode(stepmode.isSelected()); step.setEnabled(steppable.isStepmode() && !system.getAgenda().isEmpty()); } });
/** * Start the example. */ public static void main(String[] args) { Rulebase rb = new Rulebase(); rb.addRule(createFindSolutionRuleJCL()); // rb.addRule(createFindSolutionRule()); IPatternMatcherFunctionality pf = new RetePatternMatcherFunctionality(rb); RuleSystem system = new RuleSystem(createState(), rb, pf); system.init(); RuleSystemExecutor exe = new RuleSystemExecutor(system, true); RuleEnginePanel.createRuleEngineFrame(exe, "Golfing Example"); } }
this.system = system; final ReteNode root = ((RetePatternMatcherFunctionality)system.getMatcherFunctionality()).getReteNode(); final ReteMemory mem = ((RetePatternMatcherState)system.getMatcherState()).getReteMemory(); this.g = new DirectedSparseGraph(); buildGraph(g, root); hideMarkedNodes(Collections.EMPTY_SET); final NodePanel np = new NodePanel(null, mem, system.getState()); tmp.add(np, BorderLayout.CENTER); tmp.add(buts, BorderLayout.SOUTH); this.ap = new AgendaPanel(system.getAgenda()); JPanel tmp3 = new JPanel(new BorderLayout()); final JCheckBox followact = new JCheckBox("Follow activation", true); step.setEnabled(steppable.isStepmode() && !system.getAgenda().isEmpty()); final JCheckBox stepmode = new JCheckBox("Step Mode", steppable.isStepmode()); stepmode.addActionListener(new ActionListener() system.getAgenda().addAgendaListener(agendalistener); followact.addActionListener(new ActionListener() if(followact.isSelected()) Activation act = system.getAgenda().getNextActivation(); if(act!=null && followact.isSelected())
/** * Create a rule engine panel. */ public RuleEnginePanel(final RuleSystem rulesystem, final ISteppable steppable) { this.oavpanel = new OAVPanel(rulesystem.getState()); this.rulebasepanel = new RulebasePanel(rulesystem.getRulebase(), steppable); this.retepanel = new RetePanel(rulesystem, steppable, rulebasepanel); JSplitPane sp1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); sp1.setOneTouchExpandable(true); sp1.add(rulebasepanel); sp1.add(retepanel); sp1.setDividerLocation(150); this.addTab("Working Memory", icons.getIcon("show_state"), oavpanel); this.addTab("Rule Engine", icons.getIcon("show_rete"), sp1); this.setSelectedIndex(0); }
RuleSystem rete = new RuleSystem(state, rb, new RetePatternMatcherFunctionality(rb), new PriorityAgenda()); fncon.addConstraint(new BoundConstraint(null, fn)); fncon.addConstraint(new LiteralConstraint(fibo_has_value, Long.valueOf(-1))); rete.getRulebase().addRule(new Rule("recurse", fncon, new IAction() f1con.addConstraint(new LiteralConstraint(fibo_has_value, Long.valueOf(-1))); f1con.addConstraint(new LiteralConstraint(fibo_has_sequence, Integer.valueOf(1))); rete.getRulebase().addRule(new Rule("bootstrap1", f1con, new IAction() f2con.addConstraint(new LiteralConstraint(fibo_has_value, Long.valueOf(-1))); f2con.addConstraint(new LiteralConstraint(fibo_has_sequence, Integer.valueOf(2))); rete.getRulebase().addRule(new Rule("bootstrap2", f2con, new IAction() new Object[]{f1seq, new FunctionCall(new Sub(), new Object[]{f2seq, Integer.valueOf(1)})}))); rete.getRulebase().addRule(new Rule("calc", new AndCondition(new ICondition[]{f00con, f11con, f22con}), new IAction() rete.init();
RuleSystemExecutor exe = new RuleSystemExecutor(system, true); RuleEnginePanel.createRuleEngineFrame(exe, "Blocksworld Test"); IOAVState state = system.getState(); System.out.println("Rete memory: "+((RetePatternMatcherState)system.getMatcherState()).getReteMemory());
public void run() { oavpanel = new OAVPanel(bdii.getRuleSystem().getState()); SwingUtilities.invokeLater(new Runnable() { public void run() { component.add(BorderLayout.CENTER, oavpanel); component.invalidate(); component.doLayout(); component.repaint(); } }); } });
/** * Create a frame for a rete structure. * @param title The title for the frame. * @param rs The rule system. * @return The frame. */ public static JFrame createReteFrame(String title, RuleSystem rs, ISteppable steppable) { JFrame f = new JFrame(title); f.getContentPane().setLayout(new BorderLayout()); RulebasePanel rbp = new RulebasePanel(rs.getRulebase(), steppable); RetePanel rp = new RetePanel(rs, steppable, rbp); rp.showHiddenNodes(); f.add("West", rbp); f.add("Center", rp); f.pack(); f.setVisible(true); return f; } }
public IFuture<Void> execute(IInternalAccess ia) { // System.out.println("sb start: "+getComponentIdentifier()); state.setAttributeValue(ragent, OAVBDIRuntimeModel.agent_has_initparents, null); state.setAttributeValue(ragent, OAVBDIRuntimeModel.agent_has_state, OAVBDIRuntimeModel.AGENTLIFECYCLESTATE_ALIVE); // Remove arguments from state. if(state.getAttributeValue(ragent, OAVBDIRuntimeModel.agent_has_arguments)!=null) state.setAttributeValue(ragent, OAVBDIRuntimeModel.agent_has_arguments, null); rulesystem.init(); // System.out.println("sb end: "+getComponentIdentifier()); return IFuture.DONE; } });
rulesystem = new RuleSystem(state, model.getMatcherFunctionality().getRulebase(), model.getMatcherFunctionality(), new PriorityAgenda());
IPatternMatcherFunctionality pf = new RetePatternMatcherFunctionality(rb); RuleSystem system = new RuleSystem(OAVStateFactory.createOAVState(blocksworld_type_model), rb, pf); system.init(); system.getRulebase().addRule(rule);
for(int i=0; i<rules.length; i++) INode node = root.getTerminalNode(system.getRulebase().getRule(rules[i])); subgraph.add(node); np.setNode(root.getTerminalNode(system.getRulebase().getRule(rules[0])));
next = system.getAgenda().getNextActivation();
if(rulesystem.isInited()) Activation act = rulesystem.getAgenda().getLastActivation(); state.getProfiler().start(IProfiler.TYPE_RULE, act!=null?act.getRule():null); state.expungeStaleObjects(); state.getProfiler().stop(IProfiler.TYPE_RULE, act!=null?act.getRule():null); if(!rulesystem.getAgenda().isEmpty()) rulesystem.getAgenda().fireRule(); act = rulesystem.getAgenda().getLastActivation(); return !rulesystem.getAgenda().isEmpty();
RuleSystem rete = new RuleSystem(state, rb, new RetePatternMatcherFunctionality(rb), new LIFOAgenda()); rete.init();
/** * Dispose the panel and remove any listeners. */ public void dispose() { ap.dispose(); rulebasepanel.dispose(); system.getAgenda().removeAgendaListener(agendalistener); }