From: <jbo...@li...> - 2006-01-18 05:38:41
|
Author: mar...@jb... Date: 2006-01-18 00:38:22 -0500 (Wed, 18 Jan 2006) New Revision: 2129 Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/FactHandle.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/PrimacyConflictResolver.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/RecencyConflictResolver.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Agenda.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/AgendaItem.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/DefaultFactHandleFactory.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleFactory.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleImpl.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleList.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/JoinNode.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/NotNode.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/PropagationContextImpl.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/RuleBaseImpl.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TupleKey.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/DefaultKnowledgeHelper.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/PropagationContext.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/Tuple.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/visualize/ReteooLayout.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/MockFactHandle.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/FactHandleTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/ObjectSourceTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/ReteTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/TestNodeTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/visualize/ReteooJungViewerTest.java Log: -Changes to get Manners working Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/FactHandle.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/FactHandle.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/FactHandle.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -60,4 +60,6 @@ * @return The external string form. */ String toExternalForm(); + + long getRecency(); } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/DefaultConflictResolver.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -64,11 +64,7 @@ // Class members // ---------------------------------------------------------------------- - // private static final ConflictResolver[] CONFLICT_RESOLVERS = new - // ConflictResolver[]{SalienceConflictResolver.getInstance(), - // RecencyConflictResolver.getInstance(), - // ComplexityConflictResolver.getInstance(), - private static final ConflictResolver[] CONFLICT_RESOLVERS = new ConflictResolver[]{SalienceConflictResolver.getInstance(), LifoConflictResolver.getInstance() }; + private static final ConflictResolver[] CONFLICT_RESOLVERS = new ConflictResolver[]{SalienceConflictResolver.getInstance(), LifoConflictResolver.getInstance()}; /** Singleton instance. */ private static final DefaultConflictResolver INSTANCE = new DefaultConflictResolver(); Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/PrimacyConflictResolver.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/PrimacyConflictResolver.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/PrimacyConflictResolver.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -41,6 +41,7 @@ * */ +import org.drools.FactHandle; import org.drools.spi.Activation; import org.drools.spi.ConflictResolver; @@ -93,6 +94,56 @@ */ public int compare(Activation lhs, Activation rhs) { - return (int) (lhs.getTuple().getLeastRecentFactTimeStamp() - rhs.getTuple().getLeastRecentFactTimeStamp()); + FactHandle[] lFacts = lhs.getTuple().getFactHandles(); + FactHandle[] rFacts = rhs.getTuple().getFactHandles(); + + FactHandle leftLeastRecent = getLeastRecentFact(lFacts); + FactHandle rightLeastRecent = getLeastRecentFact(rFacts); + + int lastIndex = ( lFacts.length < rFacts.length ) ? lFacts.length : rFacts.length ; + + if (leftLeastRecent.getRecency() == rightLeastRecent.getRecency() && lastIndex > 1 ) { + for ( int i = 0; i < lastIndex; i++ ) { + leftLeastRecent = getLeastRecentFact( lFacts, leftLeastRecent ); + rightLeastRecent = getLeastRecentFact( rFacts, rightLeastRecent ); + if ( leftLeastRecent.getRecency() != rightLeastRecent.getRecency() ) { + return (int) ( rightLeastRecent.getRecency() - leftLeastRecent.getRecency() ); + } + } + } else { + return (int) ( leftLeastRecent.getRecency() - rightLeastRecent.getRecency() ); + } + + return rFacts.length - lFacts.length; } + + private FactHandle getLeastRecentFact(FactHandle[] handles) { + FactHandle mostRecent = handles[0]; + for ( int i = 1; i < handles.length; i++ ) { + FactHandle eachHandle = handles[i]; + + if ( eachHandle.getRecency() < mostRecent.getRecency()) { + mostRecent = eachHandle; + } + } + return mostRecent; + } + + private FactHandle getLeastRecentFact(FactHandle[] handles, FactHandle handle) { + FactHandle mostRecent = null; + + for ( int i = 0; i < handles.length; i++ ) { + FactHandle eachHandle = handles[i]; + + if ( mostRecent == null && eachHandle.getRecency() > handle.getRecency() ) { + mostRecent = eachHandle; + } + + if ( mostRecent != null && eachHandle.getRecency() < mostRecent.getRecency() && eachHandle.getRecency() > handle.getRecency() ) { + mostRecent = eachHandle; + } + } + return (mostRecent != null) ? mostRecent : handle; + } + } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/RecencyConflictResolver.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/RecencyConflictResolver.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/conflict/RecencyConflictResolver.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -41,6 +41,8 @@ * */ +import org.drools.FactHandle; +import org.drools.reteoo.FactHandleImpl; import org.drools.spi.Activation; import org.drools.spi.ConflictResolver; @@ -93,6 +95,58 @@ */ public int compare(Activation lhs, Activation rhs) { - return (int) (lhs.getTuple().getMostRecentFactTimeStamp() - rhs.getTuple().getMostRecentFactTimeStamp()); + FactHandle[] lFacts = lhs.getTuple().getFactHandles(); + FactHandle[] rFacts = rhs.getTuple().getFactHandles(); + + FactHandle leftMostRecent = getMostRecentFact(lFacts); + FactHandle rightMostRecent = getMostRecentFact(rFacts); + + int lastIndex = ( lFacts.length < rFacts.length ) ? lFacts.length : rFacts.length ; + + if (leftMostRecent.getRecency() == rightMostRecent.getRecency() && lastIndex > 1) { + + for ( int i = 0; i < lastIndex; i++ ) { + leftMostRecent = getMostRecentFact( lFacts, leftMostRecent ); + rightMostRecent = getMostRecentFact( rFacts, rightMostRecent ); + if ( leftMostRecent.getRecency() != rightMostRecent.getRecency() ) { + return (int) ( rightMostRecent.getRecency() - leftMostRecent.getRecency() ); + } + } + } else { + return (int) ( rightMostRecent.getRecency() - leftMostRecent.getRecency() ); + } + + return rFacts.length - lFacts.length; } + + private FactHandle getMostRecentFact(FactHandle[] handles) { + FactHandle mostRecent = handles[0]; + for ( int i = 1; i < handles.length; i++ ) { + FactHandle eachHandle = handles[i]; + + if ( eachHandle.getRecency() > mostRecent.getRecency()) { + mostRecent = eachHandle; + } + } + return mostRecent; + } + + private FactHandle getMostRecentFact(FactHandle[] handles, FactHandle handle) { + FactHandle mostRecent = null; + + for ( int i = 0; i < handles.length; i++ ) { + FactHandle eachHandle = handles[i]; + + if ( mostRecent == null && eachHandle.getRecency() < handle.getRecency() ) { + mostRecent = eachHandle; + } + + if ( mostRecent != null && eachHandle.getRecency() > mostRecent.getRecency() && eachHandle.getRecency() < handle.getRecency() ) { + mostRecent = eachHandle; + } + } + return (mostRecent != null) ? mostRecent : handle; + } + + } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCancelledEvent.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -54,7 +54,7 @@ } public String toString() { - //return "[ActivationCancelled: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; - return "[ActivationCancelled: rule=" + getActivation().getRule().getName() + "]"; + return "<==[ActivationCancelled(" + getActivation().getActivationNumber() + "): rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + //return "<==[ActivationCancelled: rule=" + getActivation().getRule().getName() + "]"; } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/ActivationCreatedEvent.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -54,7 +54,12 @@ } public String toString() { - return "[ActivationCreated: rule=" + getActivation().getRule().getName() + "]"; - //return "[ActivationCreated: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + return "==>[ActivationCreated(" + getActivation().getActivationNumber() + "): rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; +// if (getActivation().getRule().getName().equals("fiSeating")) { +// return "==>[ActivationCreated: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; +// } else { +// return "==>[ActivationCreated: rule=" + getActivation().getRule().getName() + "]"; +// } + } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/AfterActivationFiredEvent.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -55,6 +55,6 @@ public String toString() { //return "[AfterActivationFired: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; - return "[AfterActivationFired: rule=" + getActivation().getRule().getName() + "]"; + return "[AfterActivationFired(" + getActivation().getActivationNumber() + "): rule=" + getActivation().getRule().getName() + "]"; } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/event/BeforeActivationFiredEvent.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -56,7 +56,7 @@ } public String toString() { - //return "[BeforeActivationFired: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; - return "[BeforeActivationFired: rule=" + getActivation().getRule().getName() + "]"; + return "[BeforeActivationFired: rule=" + getActivation().getRule().getName() + "; tuple=" + getActivation().getTuple() + "]"; + //return "[BeforeActivationFired(" + getActivation().getActivationNumber() + "): rule=" + getActivation().getRule().getName() + "]"; } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Agenda.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Agenda.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Agenda.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -156,7 +156,8 @@ Duration dur = rule.getDuration(); - AgendaItem item = new AgendaItem( tuple, + AgendaItem item = new AgendaItem( context.getPropagationNumber(), + tuple, context, rule ); Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/AgendaItem.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/AgendaItem.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/AgendaItem.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -70,12 +70,9 @@ private PropagationContext context; - // ** The Counter */ - private static long counter; - - private long activationNumber; - private boolean retract; + + public long activationNumber; // ------------------------------------------------------------ // Constructors @@ -89,13 +86,14 @@ * @param rule * The rule. */ - AgendaItem(ReteTuple tuple, + AgendaItem(long activationNumber, + ReteTuple tuple, PropagationContext context, Rule rule) { this.tuple = tuple; this.context = context; this.rule = rule; - this.activationNumber = AgendaItem.counter++; + this.activationNumber = activationNumber; } // ------------------------------------------------------------ @@ -175,14 +173,18 @@ } public long getActivationNumber() { - return this.activationNumber; + return this.activationNumber; } public String toString() { - return "[" + this.rule.getName() + " " + this.tuple + "]"; + return "[Activation rule=" + this.rule.getName() + ", tuple=" + this.tuple + "]"; } public boolean equals(Object object) { + if ( object == this ) { + return true; + } + if ( (object == null) || !(object instanceof AgendaItem) ) { return false; } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/DefaultFactHandleFactory.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/DefaultFactHandleFactory.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/DefaultFactHandleFactory.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -60,4 +60,12 @@ return new FactHandleImpl( id, ++this.counter ); } + + public final void increaseFactHandleRecency(FactHandle factHandle) { + ((FactHandleImpl) factHandle).setRecency( ++this.counter ); + } + + public FactHandleFactory newInstance() { + return new DefaultFactHandleFactory(); + } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleFactory.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleFactory.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleFactory.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -63,4 +63,12 @@ * @return The handle. */ FactHandle newFactHandle(long id); + + public void increaseFactHandleRecency(FactHandle factHandle); + + /** + * + * @return a fresh instance of the fact handle factory, with any IDs reset etc. + */ + FactHandleFactory newInstance(); } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleImpl.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleImpl.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleImpl.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -56,7 +56,7 @@ /** Handle id. */ private long id; - private final long recency; + private long recency; // ---------------------------------------------------------------------- // Constructors @@ -109,7 +109,7 @@ * @see FactHandle */ public String toExternalForm() { - return "[fid:" + this.id + "]"; + return "[fid:" + this.id + ":" + this.recency + "]"; } /** @@ -122,6 +122,10 @@ public long getRecency() { return this.recency; } + + public void setRecency(long recency) { + this.recency = recency; + } public long getId() { return this.id; Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleList.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleList.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/FactHandleList.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -182,6 +182,10 @@ } return true; } + + FactHandle[] getHandles() { + return this.handles; + } /** * Obtains the length of the list. Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/JoinNode.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -71,36 +71,35 @@ PropagationContext context, WorkingMemoryImpl workingMemory) throws FactException { BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this ); - if ( !memory.contains( leftTuple.getKey() ) ) { - TupleMatches tupleMatches = new TupleMatches( leftTuple ); - memory.put( leftTuple.getKey(), - tupleMatches ); + + TupleMatches tupleMatches = new TupleMatches( leftTuple ); + memory.put( leftTuple.getKey(), + tupleMatches ); - int column = getColumn(); - FactHandleImpl handle = null; - ReteTuple merged = null; - TupleSet tupleSet = new TupleSet(); - BetaNodeBinder binder = getJoinNodeBinder(); - Iterator it = memory.getRightMemory().iterator(); - while ( it.hasNext() ) { - handle = (FactHandleImpl) it.next(); - if ( binder.isAllowed( handle, - leftTuple, - workingMemory ) ) { - tupleMatches.addMatch( handle ); + int column = getColumn(); + FactHandleImpl handle = null; + ReteTuple merged = null; + TupleSet tupleSet = new TupleSet(); + BetaNodeBinder binder = getJoinNodeBinder(); + Iterator it = memory.getRightMemory().iterator(); + while ( it.hasNext() ) { + handle = (FactHandleImpl) it.next(); + if ( binder.isAllowed( handle, + leftTuple, + workingMemory ) ) { + tupleMatches.addMatch( handle ); - merged = new ReteTuple( leftTuple, - new ReteTuple( column, - handle, - workingMemory ) ); - tupleSet.addTuple( merged ); - } + merged = new ReteTuple( leftTuple, + new ReteTuple( column, + handle, + workingMemory ) ); + tupleSet.addTuple( merged ); } - - propagateAssertTuples( tupleSet, - context, - workingMemory ); } + + propagateAssertTuples( tupleSet, + context, + workingMemory ); } /** @@ -116,38 +115,36 @@ PropagationContext context, WorkingMemoryImpl workingMemory) throws FactException { BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this ); - if ( !memory.contains( handle ) ) { - memory.add( handle ); + memory.add( handle ); - ReteTuple leftTuple = null; - TupleMatches tupleMatches = null; - ReteTuple merged = null; + ReteTuple leftTuple = null; + TupleMatches tupleMatches = null; + ReteTuple merged = null; - ReteTuple rightTuple = new ReteTuple( getColumn(), - handle, - workingMemory ); - TupleSet tupleSet = new TupleSet(); - BetaNodeBinder binder = getJoinNodeBinder(); - Iterator it = memory.getLeftMemory().values().iterator(); + ReteTuple rightTuple = new ReteTuple( getColumn(), + handle, + workingMemory ); + TupleSet tupleSet = new TupleSet(); + BetaNodeBinder binder = getJoinNodeBinder(); + Iterator it = memory.getLeftMemory().values().iterator(); - while ( it.hasNext() ) { - tupleMatches = (TupleMatches) it.next(); - leftTuple = tupleMatches.getTuple(); - if ( binder.isAllowed( object, - handle, - leftTuple, - workingMemory ) ) { - tupleMatches.addMatch( handle ); - merged = new ReteTuple( leftTuple, - rightTuple ); - tupleSet.addTuple( merged ); - } + while ( it.hasNext() ) { + tupleMatches = (TupleMatches) it.next(); + leftTuple = tupleMatches.getTuple(); + if ( binder.isAllowed( object, + handle, + leftTuple, + workingMemory ) ) { + tupleMatches.addMatch( handle ); + merged = new ReteTuple( leftTuple, + rightTuple ); + tupleSet.addTuple( merged ); } - - propagateAssertTuples( tupleSet, - context, - workingMemory ); } + + propagateAssertTuples( tupleSet, + context, + workingMemory ); } /** Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/NotNode.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/NotNode.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -115,8 +115,7 @@ BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this ); if ( !memory.contains( handle ) ) { memory.add( handle ); - - TupleSet assertTupleSet = null; + List retractKeyList = null; BetaNodeBinder binder = getJoinNodeBinder(); @@ -135,12 +134,7 @@ int size = tupleMatches.getMatches().size(); - if ( size == 0 ) { - if (assertTupleSet == null) { - assertTupleSet = new TupleSet(); - } - assertTupleSet.addTuple( leftTuple ); - } else if ( previousSize == 0 && size == 1 ) { + if ( previousSize == 0 && size != 0 ) { // If we previously had size of 0 and now its one we need to remove any created activations if (retractKeyList == null) { retractKeyList = new ArrayList(); @@ -149,12 +143,6 @@ } } - if (assertTupleSet != null) { - propagateAssertTuples( assertTupleSet, - context, - workingMemory ); - } - if (retractKeyList != null) { propagateRetractTuples( retractKeyList, context, @@ -202,24 +190,28 @@ FactException { BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this ); - if ( memory.contains( handle ) ) { - TupleMatches tupleMatches = null; - TupleSet tupleSet = new TupleSet(); + if ( memory.contains( handle ) ) { + TupleSet tupleSet = null; memory.remove( handle ); - Iterator it = memory.getLeftMemory().values().iterator(); - - while ( it.hasNext() ) { - tupleMatches = (TupleMatches) it.next(); + + for ( Iterator it = memory.getLeftMemory().values().iterator(); it.hasNext(); ) { + TupleMatches tupleMatches = (TupleMatches) it.next(); + int previousSize = tupleMatches.getMatches().size(); tupleMatches.removeMatch( handle ); - - if ( tupleMatches.getMatches().size() == 0 ) { + + if ( previousSize != 0 && tupleMatches.getMatches().size() == 0) { + if ( tupleSet == null ) { + tupleSet = new TupleSet(); + } tupleSet.addTuple( tupleMatches.getTuple() ); } } - propagateAssertTuples( tupleSet, - context, - workingMemory ); + if ( tupleSet != null ) { + propagateAssertTuples( tupleSet, + context, + workingMemory ); + } } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/PropagationContextImpl.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/PropagationContextImpl.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/PropagationContextImpl.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -7,19 +7,27 @@ public class PropagationContextImpl implements PropagationContext { - private int type; + private final int type; - private Rule rule; + private final Rule rule; - private Activation activation; + private final Activation activation; + + private final long propagationNumber; - public PropagationContextImpl(int type, + public PropagationContextImpl(long number, + int type, Rule rule, Activation activation) { this.type = type; this.rule = rule; this.activation = activation; + this.propagationNumber = number; } + + public long getPropagationNumber() { + return this.propagationNumber; + } /* * (non-Javadoc) Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -93,7 +93,7 @@ public String toString() { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < this.key.size(); i++) { - buffer.append( this.key.get( i ) + " : " + get(i) + "\n" ); + buffer.append( this.key.get( i ) + " : " + get(i) + ", " ); } return buffer.toString(); } @@ -110,6 +110,10 @@ TupleKey getKey() { return this.key; } + + public FactHandle[] getFactHandles() { + return this.key.getFactHandles(); + } /** * Determine if this tuple depends upon a specified object. @@ -138,6 +142,9 @@ */ public Object get(int col) { FactHandle handle = this.key.get( col ); + if ( handle == null) { + return null; + } return get( handle ); } @@ -163,19 +170,4 @@ public WorkingMemory getWorkingMemory() { return this.workingMemory; } - - public long getMostRecentFactTimeStamp() { - if ( this.mostRecentFact == null ) { - this.mostRecentFact = this.key.getMostRecentFact(); - } - return this.mostRecentFact.getRecency(); - } - - public long getLeastRecentFactTimeStamp() { - if ( this.leastRecentFact == null ) { - this.leastRecentFact = this.key.getLeastRecentFact(); - } - return this.leastRecentFact.getRecency(); - } - } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/RuleBaseImpl.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/RuleBaseImpl.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/RuleBaseImpl.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -107,6 +107,14 @@ // ------------------------------------------------------------ // Constructors // ------------------------------------------------------------ + + public RuleBaseImpl(ConflictResolver conflictResolver){ + this( conflictResolver, + new DefaultFactHandleFactory(), + new HashSet(), + new HashMap(), + new RuleBaseContext() ); + } /** * Construct. @@ -183,6 +191,10 @@ public FactHandleFactory getFactHandleFactory() { return this.factHandleFactory; } + + public FactHandleFactory newFactHandleFactory() { + return this.factHandleFactory.newInstance(); + } /** * @see RuleBase Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TupleKey.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TupleKey.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TupleKey.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -128,46 +128,10 @@ public boolean containsAll(TupleKey that) { return this.handles.containsAll( that.handles ); } - - public FactHandleImpl getMostRecentFact() { - FactHandleImpl mostRecent = null; - long currentRecency = Long.MIN_VALUE; - FactHandleImpl eachHandle; - long recency; - - for ( int i = this.handles.size() - 1; i >= 0; i-- ) { - eachHandle = (FactHandleImpl) this.handles.get( i ); - if ( eachHandle != null ) { - recency = eachHandle.getRecency(); - if ( recency > currentRecency ) { - currentRecency = recency; - mostRecent = eachHandle; - } - } - } - - return mostRecent; + + FactHandle[] getFactHandles() { + return this.handles.getHandles(); } - - public FactHandleImpl getLeastRecentFact() { - FactHandleImpl leastRecent = null; - long currentRecency = Long.MAX_VALUE; - FactHandleImpl eachHandle; - long recency; - - for ( int i = this.handles.size() - 1; i >= 0; i-- ) { - eachHandle = (FactHandleImpl) this.handles.get( i ); - if ( eachHandle != null ) { - recency = eachHandle.getRecency(); - if ( recency < currentRecency ) { - currentRecency = recency; - leastRecent = eachHandle; - } - } - } - - return leastRecent; - } public int size() { return this.handles.size(); @@ -196,4 +160,5 @@ public int hashCode() { return this.handles.hashCode(); } + } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/WorkingMemoryImpl.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -122,12 +122,16 @@ /** The <code>RuleBase</code> with which this memory is associated. */ private final RuleBaseImpl ruleBase; + + private final FactHandleFactory handleFactory; /** Rule-firing agenda. */ private final Agenda agenda; /** Flag to determine if a rule is currently being fired. */ private boolean firing; + + private long propagationIdCounter; // ------------------------------------------------------------ // Constructors @@ -143,6 +147,7 @@ this.ruleBase = ruleBase; this.agenda = new Agenda( this, ruleBase.getConflictResolver() ); + this.handleFactory = this.ruleBase.newFactHandleFactory(); } // ------------------------------------------------------------ @@ -192,10 +197,10 @@ */ FactHandle newFactHandle() { if ( !this.factHandlePool.isEmpty() ) { - return this.ruleBase.getFactHandleFactory().newFactHandle( this.factHandlePool.pop() ); + return this.handleFactory.newFactHandle( this.factHandlePool.pop() ); } - return this.ruleBase.getFactHandleFactory().newFactHandle(); + return this.handleFactory.newFactHandle(); } /** @@ -472,7 +477,8 @@ handles.add( handle ); } - PropagationContext propagationContext = new PropagationContextImpl( PropagationContext.ASSERTION, + PropagationContext propagationContext = new PropagationContextImpl( ++this.propagationIdCounter, + PropagationContext.ASSERTION, rule, activation ); @@ -585,7 +591,8 @@ removePropertyChangeListener( handle ); PropagationContext propagationContext = - new PropagationContextImpl( PropagationContext.RETRACTION, + new PropagationContextImpl( ++this.propagationIdCounter, + PropagationContext.RETRACTION, rule, activation ); @@ -636,10 +643,12 @@ Rule rule, Activation activation) throws FactException { Object originalObject = removeObject( handle ); - + if ( originalObject == null ) { throw new NoSuchFactObjectException( handle ); } + + this.handleFactory.increaseFactHandleRecency( handle ); putObject( handle, object ); @@ -652,7 +661,8 @@ handle ); } - PropagationContext propagationContext = new PropagationContextImpl( PropagationContext.MODIFICATION, + PropagationContext propagationContext = new PropagationContextImpl( ++this.propagationIdCounter, + PropagationContext.MODIFICATION, rule, activation ); Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/DefaultKnowledgeHelper.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/DefaultKnowledgeHelper.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/DefaultKnowledgeHelper.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -88,10 +88,12 @@ } public void retractObject(Object object) throws FactException { - FactHandle handle = this.tuple.getFactHandleForObject( object ); - + retractObject( this.tuple.getFactHandleForObject( object ) ); + } + + public void retractObject(FactHandle handle) throws FactException { this.tuple.getWorkingMemory().retractObject( handle ); - } + } public String getRuleName() { return this.rule.getName(); Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -125,6 +125,8 @@ * Wraps and returns any exception that may occur. */ void retractObject(Object object) throws FactException; + + void retractObject(FactHandle handle) throws FactException; /** * @return - The rule name Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/PropagationContext.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/PropagationContext.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/PropagationContext.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -8,10 +8,12 @@ public static final int RETRACTION = 1; public static final int MODIFICATION = 2; - public abstract Rule getRuleOrigin(); + public long getPropagationNumber(); + + public Rule getRuleOrigin(); - public abstract Activation getActivationOrigin(); + public Activation getActivationOrigin(); - public abstract int getType(); + public int getType(); } \ No newline at end of file Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/Tuple.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/Tuple.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/Tuple.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -85,6 +85,8 @@ FactHandle getFactHandleForObject(Object object); FactHandle getFactHandleForDeclaration(Declaration declaration); + + FactHandle[] getFactHandles(); /** * Returns a reference to the <code>WorkingMemory</code> associated with @@ -94,9 +96,5 @@ */ WorkingMemory getWorkingMemory(); - long getMostRecentFactTimeStamp(); - - long getLeastRecentFactTimeStamp(); - // long getConditionTimeStamp(int i); } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/visualize/ReteooLayout.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/visualize/ReteooLayout.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/visualize/ReteooLayout.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -20,106 +20,110 @@ import edu.uci.ics.jung.visualization.VertexLocationFunction; public class ReteooLayout extends AbstractLayout { - - public final static String COORDS = "drools.ReteooLayout.coords"; - - private static final int COLUMN_SPACE = 20; - private static final int ROW_HEIGHT_MULTIPLIER = 3; - - private RowList rowList; - - private VertexFunctions vertexFunctions; - private int columnWidth; - private int rowHeight; - - public ReteooLayout(Graph g, VertexFunctions vertexFunctions, RowList rowList) { + + public final static String COORDS = "drools.ReteooLayout.coords"; + + private static final int COLUMN_SPACE = 20; + private static final int ROW_HEIGHT_MULTIPLIER = 3; + + private RowList rowList; + + private VertexFunctions vertexFunctions; + private int columnWidth; + private int rowHeight; + + public ReteooLayout(Graph g, + VertexFunctions vertexFunctions, + RowList rowList) { super( g ); this.vertexFunctions = vertexFunctions; - this.rowList = rowList; + this.rowList = rowList; computeSize(); } - + public VertexFunctions getVertexFunctions() { return this.vertexFunctions; } - + public int getColumnWidth() { return columnWidth; } - + public int getRowHeight() { return rowHeight; } - + public int getPreferredWidth() { return rowList.getWidth() * columnWidth; } - + public int getPreferredHeight() { return rowList.getDepth() * getRowHeight() * ROW_HEIGHT_MULTIPLIER; } protected void computeSize() { Set vertices = getGraph().getVertices(); - - for ( Iterator vertexIter = vertices.iterator() ; vertexIter.hasNext() ; ) { - Vertex vertex = (Vertex) vertexIter.next(); - + + for ( Iterator vertexIter = vertices.iterator(); vertexIter.hasNext(); ) { + Vertex vertex = (Vertex) vertexIter.next(); + int width = vertexFunctions.getShapeDimension( vertex ).width; int height = vertexFunctions.getShapeDimension( vertex ).height; - + if ( width > columnWidth ) { columnWidth = width; } - + if ( height > rowHeight ) { - rowHeight = height; + rowHeight = height; } } - + columnWidth = columnWidth + COLUMN_SPACE; } - protected void initialize_local_vertex( Vertex vertex ) { + protected void initialize_local_vertex(Vertex vertex) { int row = rowList.getRow( vertex ); int col = rowList.getColumn( vertex ); - - int widthPx = this.getCurrentSize().width; + + int widthPx = this.getCurrentSize().width; int heightPx = this.getCurrentSize().height; - + int rowWidth = rowList.getWidth( row ); - + int columnWidthPx = getColumnWidth(); int rowHeightPx = getRowHeight(); - + Coordinates coords = new Coordinates(); - - double x = ( col * columnWidthPx ); - double y = ( row * ( rowHeightPx * ROW_HEIGHT_MULTIPLIER ) ); - - x = x + ( widthPx / 2 ) - ( ( rowWidth - 1 ) * ( columnWidthPx / 2 ) ); - y = y + ( rowHeightPx/2 ) + 3; - + + double x = (col * columnWidthPx); + double y = (row * (rowHeightPx * ROW_HEIGHT_MULTIPLIER)); + + x = x + (widthPx / 2) - ((rowWidth - 1) * (columnWidthPx / 2)); + y = y + (rowHeightPx / 2) + 3; + coords.setX( x ); coords.setY( y ); - + //System.err.println( vertex + " -> " + coords.getX() + "," + coords.getY() + " / " + row + "," + col ); - - vertex.setUserDatum( COORDS, coords, new UserDataContainer.CopyAction.Shared() ); + + vertex.setUserDatum( COORDS, + coords, + new UserDataContainer.CopyAction.Shared() ); } - + public double getX(Vertex vertex) { - System.err.println( "getX" ); + //System.err.println( "getX" ); return getCoordinates( vertex ).getX(); } - + public double getY(Vertex vertex) { - System.err.println( "getY" ); + //System.err.println( "getY" ); return getCoordinates( vertex ).getY(); } - + public Coordinates getCoordinates(ArchetypeVertex vertex) { - System.err.println( vertex + " --> " + (Coordinates) vertex.getUserDatum( COORDS ) ); + //System.err.println( vertex + " --> " + (Coordinates) vertex.getUserDatum( COORDS ) ); return (Coordinates) vertex.getUserDatum( COORDS ); } Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/MockFactHandle.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/MockFactHandle.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/MockFactHandle.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -73,4 +73,9 @@ public long getId() { return this.id; } + + public long getRecency() { + // TODO Auto-generated method stub + return 0; + } } Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -26,6 +26,9 @@ import org.drools.RuleIntegrationException; import org.drools.RuleSetIntegrationException; import org.drools.WorkingMemory; +import org.drools.conflict.CompositeConflictResolver; +import org.drools.conflict.RecencyConflictResolver; +import org.drools.conflict.SalienceConflictResolver; import org.drools.event.ActivationCancelledEvent; import org.drools.event.ActivationCreatedEvent; import org.drools.event.BeforeActivationFiredEvent; @@ -51,6 +54,7 @@ import org.drools.spi.ClassFieldExtractor; import org.drools.spi.ClassObjectType; import org.drools.spi.BaseEvaluator; +import org.drools.spi.ConflictResolver; import org.drools.spi.Consequence; import org.drools.spi.ConsequenceException; import org.drools.spi.Constraint; @@ -117,7 +121,7 @@ } - public void test1() throws DuplicateRuleNameException, + public void testManners() throws DuplicateRuleNameException, InvalidRuleException, IntrospectionException, RuleIntegrationException, @@ -135,11 +139,10 @@ ruleSet.addRule( getContinueProcessing() ); ruleSet.addRule( getAllDone() ); - final RuleBaseImpl ruleBase = new RuleBaseImpl(); + final RuleBaseImpl ruleBase = new RuleBaseImpl( new CompositeConflictResolver(new ConflictResolver[]{SalienceConflictResolver.getInstance(), RecencyConflictResolver.getInstance() } ) ); ruleBase.addRuleSet( ruleSet ); -// final ReteooJungViewer viewer = new ReteooJungViewer(ruleBase); -// +// final ReteooJungViewer viewer = new ReteooJungViewer(ruleBase); // javax.swing.SwingUtilities.invokeLater(new Runnable() { // public void run() { // viewer.showGUI(); @@ -148,29 +151,31 @@ WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - InputStream is = getClass().getResourceAsStream( "/manners16.dat" ); + InputStream is = getClass().getResourceAsStream( "/manners8.dat" ); List list = getInputObjects( is ); for ( Iterator it = list.iterator(); it.hasNext(); ) { - FactHandle handle = workingMemory.assertObject( it.next() ); + Object object = it.next(); + System.err.println( object ); + workingMemory.assertObject( object ); } - workingMemory.addEventListener( new DebugWorkingMemoryEventListener() ); + //workingMemory.addEventListener( new DebugWorkingMemoryEventListener() ); -// workingMemory.addEventListener( new DebugAgendaEventListener() ); + //workingMemory.addEventListener( new DebugAgendaEventListener() ); - workingMemory.addEventListener( new DefaultAgendaEventListener() { - public void activationCreated(ActivationCreatedEvent event) { - System.err.println( event ); - } - - public void activationCancelled(ActivationCancelledEvent event) { - System.err.println( event ); - } - - public void beforeActivationFired(BeforeActivationFiredEvent event) { - System.err.println( event ); - } - } ); +// workingMemory.addEventListener( new DefaultAgendaEventListener() { +// public void activationCreated(ActivationCreatedEvent event) { +// System.err.println( event ); +// } +// +// public void activationCancelled(ActivationCancelledEvent event) { +// System.err.println( event ); +// } +// +// public void beforeActivationFired(BeforeActivationFiredEvent event) { +// System.err.println( event ); +// } +// } ); workingMemory.assertObject( new Count( 1 ) ); // @@ -301,7 +306,7 @@ context.setState( Context.ASSIGN_SEATS ); drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), context ); - //System.out.println( "assign first seat : " + seating + " : " + path ); + System.out.println( "assign first seat : " + seating + " : " + path ); } catch ( Exception e ) { @@ -444,7 +449,7 @@ leftGuestColumn.addConstraint( getBoundVariableConstraint( leftGuestColumn, "sex", rightGuestSexDeclaration, - objectEqualEvaluator ) ); + objectNotEqualEvaluator ) ); leftGuestColumn.addConstraint( getBoundVariableConstraint( rightGuestColumn, "hobby", @@ -559,17 +564,27 @@ rightGuestHobby ); drools.assertObject( chosen ); - count.setValue( count.getValue() + 1 ); + +// if ( count.getValue() == 5 ) { +// drools.retractObject( tuple.getFactHandleForDeclaration( countDeclaration ) ); +// } else { +// drools.modifyObject( tuple.getFactHandleForDeclaration( countDeclaration ), +// count ); +// } + drools.modifyObject( tuple.getFactHandleForDeclaration( countDeclaration ), - count ); + count ); + context.setState( Context.MAKE_PATH ); drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), context ); System.err.println( "find seating : " + seating + " : " + path + " : " + chosen ); + + } catch ( Exception e ) { throw new ConsequenceException( e ); @@ -794,6 +809,10 @@ Seating seating = (Seating) tuple.get( seatingDeclaration ); seating.setPathDone( true ); + + if ( seating.getId() == 6 ) { + System.out.println("pause"); + } drools.modifyObject( tuple.getFactHandleForDeclaration( seatingDeclaration ), seating ); @@ -840,7 +859,8 @@ // context : Context( state == Context.CHECK_DONE ) // ----------- Column contextColumn = new Column( 0, - contextType ); + contextType, + "context" ); contextColumn.addConstraint( getLiteralConstraint( contextColumn, "state", @@ -893,7 +913,7 @@ drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), context ); - //System.out.println( "are we done yet" ); + System.err.println( "We Are Done!!!" ); } catch ( Exception e ) { throw new ConsequenceException( e ); @@ -974,12 +994,16 @@ } /** + * <pre> + * rule all_done() { + * Context context; + * when { + * context : Context( state == Context.PRINT_RESULTS ) + * } then { + * } + * } + * </pre> * - * rule all_done() { Context context; when { context : Context( state == - * Context.PRINT_RESULTS ) } then { - * } } - * - * * @return * @throws IntrospectionException * @throws InvalidRuleException @@ -1009,7 +1033,7 @@ public void invoke(Activation activation) throws ConsequenceException { try { - System.out.println( "all done" ); + System.err.println( "all done" ); } catch ( Exception e ) { throw new ConsequenceException( e ); Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java 2006-01-18 04:44:09 UTC (rev 2128) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java 2006-01-18 05:38:22 UTC (rev 2129) @@ -59,7 +59,8 @@ */ public class AgendaTest extends DroolsTestCase { - PropagationContext initContext = new PropagationContextImpl( PropagationContext.ASSERTION, + PropagationContext initContext = new PropagationContextImpl( 0, + PropagationContext.ASSERTION, ... [truncated message content] |