/** * Remove a rule from a rete network. * @param root The root node. * @param rule The rule to remove. */ public void removeRule(ReteNode root, IRule rule) { // Find terminal node that is associated with the rule // and call node usage removal. TerminalNode tnode = root.getTerminalNode(rule); removeNodeUsage(tnode); }
/** * Create a new Rete pattern matcher functionality. */ public RetePatternMatcherFunctionality(IRulebase rulebase) { this.rulebase = rulebase; this.node = new ReteNode(); // Build existing rules of the rulebase. for(Iterator it=rulebase.getRules().iterator(); it.hasNext(); ) node.addRule((IRule)it.next()); node.setInited(true); rulebase.addRulebaseListener(this); }
/** * Clone this object. * @return A clone of this object. */ public Object clone() { RetePatternMatcherFunctionality ret = null; try { ret = (RetePatternMatcherFunctionality)super.clone(); ret.rulebase = (IRulebase)rulebase.clone(); ret.rulebase.addRulebaseListener(ret); ret.node = (ReteNode)node.clone(); } catch(CloneNotSupportedException exception) { throw new RuntimeException("Cloning not supported: "+this); } return ret; } }
if(getRelevantAttributes().contains(attr)) Set tns = getTypeNodes(type); assert !check || checkConsistency(mem); Set ins = getIndirectNodes(attr, state.getTypeModel()); if(ins!=null)
/** * Add a new test node. * @param eva The constraint evaluator. * @param context The build context. */ protected void addTestNode(IConstraintEvaluator eva, BuildContext context) { INode node = new TestNode(context.getRootNode().getNextNodeId(), eva); connectLeft(context.getLastBetaNode(), node, context); context.setLastBetaNode(node); }
/** * Tell the condition system about a * new object in the state. * @param object The new object. */ public void addObject(Object id, OAVObjectType type, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { // if(type.getName().equals("goal")) // System.out.println("Value added: "+id+" "+type); // System.out.println("Value added: "+id+" "+type); state.getProfiler().start(IProfiler.TYPE_NODE, this); state.getProfiler().start(IProfiler.TYPE_NODEEVENT, IProfiler.NODEEVENT_OBJECTADDED); Set tns = getTypeNodes(type); if(tns!=null) { for(Iterator it=tns.iterator(); it.hasNext(); ) ((AlphaNode)it.next()).addObject(id, state, mem, agenda); assert !check || checkConsistency(mem); } // else // System.out.println("No typenode(s) available for: "+type); state.getProfiler().stop(IProfiler.TYPE_NODEEVENT, IProfiler.NODEEVENT_OBJECTADDED); state.getProfiler().stop(IProfiler.TYPE_NODE, this); }
/** * Add a new type node. * @param type The type node. * @param context the build context. */ protected void addTypeNode(OAVObjectType type, BuildContext context) { assert type!=null : "***" + context; // Create new type node, if necessary INode node = context.getRootNode().getTypeNode(type); if(node==null) { node = new TypeNode(context.getRootNode().getNextNodeId(), type); connectRight(context.getRootNode(), node, context); } context.setLastAlphaNode(node); }
/** * Add an initial fact node. * @param context The build context. */ protected void addInitialFactNode(BuildContext context) { // Todo: multiple initial fact nodes without sharing ? InitialFactNode node = context.getRootNode().getInitialFactNode(); if(node==null) { node = new InitialFactNode(context.getRootNode().getNextNodeId()); connectRight(context.getRootNode(), node, context); } // Update the context. context.setLastBetaNode(node); context.setTupleCount(1); }
/** * Add a new terminal node. * @param rule The rule. * @param context The build context. */ protected void addTerminalNode(IRule rule, BuildContext context) { // Create and connect the terminal node Map varinfos = context.getVarInfos(); Map extractors = new HashMap(); for(Iterator it=varinfos.keySet().iterator(); it.hasNext(); ) { Variable var = (Variable)it.next(); if(!var.isTemporary()) extractors.put(var.getName(), getLeftVariableExtractor(context, var)); } TerminalNode tnode = new TerminalNode(context.getRootNode().getNextNodeId(), rule, extractors); connectLeft(context.getLastBetaNode(), tnode, context); // Save the terminal node for later removal context.getRootNode().putTerminalNode(tnode); }
/** * Notification when a rule has been added. * @param rule The added rule. */ public void ruleAdded(IRule rule) { node.addRule(rule); }
/** * Create a new build context. */ public BuildContext(ReteNode root, IRule rule)// INode lastbnode, int tuplecnt) { this.root = root==null? new ReteNode(): root; this.rule = rule; this.lastanode = null; this.lastbnode = null; this.tuplecnt = 0; // this.lastbnode = lastbnode;//lastnode==null? root: lastnode; // this.tuplecnt = tuplecnt; this.varinfos = new HashMap(); this.alpha = false; // Will only be temporarily activated when building object conditions }
/** * Notification when an object has been added to the state. * @param id The object id. * @param type The object type. */ public void objectAdded(Object id, OAVObjectType type, boolean root) { assert !running; running = true; state.getProfiler().start(IProfiler.TYPE_OBJECT, type); state.getProfiler().start(IProfiler.TYPE_OBJECTEVENT, IProfiler.OBJECTEVENT_ADDED); node.addObject(id, type, state, retemem, agenda); state.getProfiler().stop(IProfiler.TYPE_OBJECTEVENT, IProfiler.OBJECTEVENT_ADDED); state.getProfiler().stop(IProfiler.TYPE_OBJECT, type); running = false; }
/** * Initialize the pattern matcher. * Called before the agenda is accessed * to perform any initialization, if necessary. */ public void init() { // Initialize initial fact node, if any. if(node.getInitialFactNode()!=null) node.getInitialFactNode().init(state, retemem, agenda); // Add initial objects. for(Iterator objects=state.getDeepObjects(); objects.hasNext(); ) { Object object = objects.next(); objectAdded(object, state.getType(object), false); // Hack!!! Should check if root? } state.addStateListener(this, true); // state.addStateListener(this, false); }
if(getRelevantAttributes().contains(attr)) Set tns = getTypeNodes(type); assert !check || checkConsistency(mem); Set ins = getIndirectNodes(attr, state.getTypeModel()); if(ins!=null)
/** * Add a new test node. * @param eva The constraint evaluator. * @param context The build context. */ protected void addTestNode(IConstraintEvaluator eva, BuildContext context) { INode node = new TestNode(context.getRootNode().getNextNodeId(), eva); connectLeft(context.getLastBetaNode(), node, context); context.setLastBetaNode(node); }
/** * Tell the condition system about a * new object in the state. * @param object The new object. */ public void addObject(Object id, OAVObjectType type, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { // if(type.getName().equals("goal")) // System.out.println("Value added: "+id+" "+type); // System.out.println("Value added: "+id+" "+type); state.getProfiler().start(IProfiler.TYPE_NODE, this); state.getProfiler().start(IProfiler.TYPE_NODEEVENT, IProfiler.NODEEVENT_OBJECTADDED); Set tns = getTypeNodes(type); if(tns!=null) { for(Iterator it=tns.iterator(); it.hasNext(); ) ((AlphaNode)it.next()).addObject(id, state, mem, agenda); assert !check || checkConsistency(mem); } // else // System.out.println("No typenode(s) available for: "+type); state.getProfiler().stop(IProfiler.TYPE_NODEEVENT, IProfiler.NODEEVENT_OBJECTADDED); state.getProfiler().stop(IProfiler.TYPE_NODE, this); }
/** * Add a new type node. * @param type The type node. * @param context the build context. */ protected void addTypeNode(OAVObjectType type, BuildContext context) { assert type!=null : "***" + context; // Create new type node, if necessary INode node = context.getRootNode().getTypeNode(type); if(node==null) { node = new TypeNode(context.getRootNode().getNextNodeId(), type); connectRight(context.getRootNode(), node, context); } context.setLastAlphaNode(node); }
/** * Add an initial fact node. * @param context The build context. */ protected void addInitialFactNode(BuildContext context) { // Todo: multiple initial fact nodes without sharing ? InitialFactNode node = context.getRootNode().getInitialFactNode(); if(node==null) { node = new InitialFactNode(context.getRootNode().getNextNodeId()); connectRight(context.getRootNode(), node, context); } // Update the context. context.setLastBetaNode(node); context.setTupleCount(1); }
/** * Add a new terminal node. * @param rule The rule. * @param context The build context. */ protected void addTerminalNode(IRule rule, BuildContext context) { // Create and connect the terminal node Map varinfos = context.getVarInfos(); Map extractors = new HashMap(); for(Iterator it=varinfos.keySet().iterator(); it.hasNext(); ) { Variable var = (Variable)it.next(); if(!var.isTemporary()) extractors.put(var.getName(), getLeftVariableExtractor(context, var)); } TerminalNode tnode = new TerminalNode(context.getRootNode().getNextNodeId(), rule, extractors); connectLeft(context.getLastBetaNode(), tnode, context); // Save the terminal node for later removal context.getRootNode().putTerminalNode(tnode); }
/** * Notification when a rule has been added. * @param rule The added rule. */ public void ruleAdded(IRule rule) { node.addRule(rule); }