[jboss-svn-commits] JBL Code SVN: r26543 - in labs/jbossrules/branches/DroolsChance/drools-core: src/main/java/org/drools and 14 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu May 14 23:45:06 EDT 2009
Author: dsotty
Date: 2009-05-14 23:45:05 -0400 (Thu, 14 May 2009)
New Revision: 26543
Added:
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImperfectAgendaGroup.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImperfectAgendaGroupFactory.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/NegationOperator.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalDiscountOperator.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalDoubleMPOperator.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalXorOperator.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleDoubleMPOperator.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleIdentityOperator.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleLukasAnd.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleLukasOr.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleProbSumOr.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleVeryModifier.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleXor.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/DiscountOperatorInstaller.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/DoubleMPOperatorInstaller.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EqvOperatorInstaller.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/XorOperatorInstaller.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectForAnyBuilder.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Forany.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/util/DependencyExaminer.java
Modified:
labs/jbossrules/branches/DroolsChance/drools-core/.classpath
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/BaseEvaluator.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/BetaConstraints.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImplicationBetaConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/LogicalDependency.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/IDegreeFactory.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/IntervalDegreeFactory.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/SimpleDegreeFactory.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleAverage.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleEquiv.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleMaxOr.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/fuzzy/evaluators/FuzzyNumericEvaluator.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/fuzzy/evaluators/RandomEvaluator.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/impl/KnowledgeBaseProviderImpl.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/AndOperatorInstaller.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeEvaluation.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeEvaluationTemplate.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EvalRecord.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/Evaluation.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectAgendaItem.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectExistsNode.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectRuleBase.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ModusPonensNode.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ObservableRightTupleMemoryWrapper.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/OperandSet.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/OperatorInstaller.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/Rete.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/SetCompositeEvaluation.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectForallBuilder.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectGroupElementBuilder.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectReteooRuleBuilder.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AbstractCompositeConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Accumulate.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AndConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Collect.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/EntryPoint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/EvalCondition.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Forall.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/From.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/GroupElement.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/GroupElementFactory.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/MutableTypeConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/OrConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Pattern.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Rule.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/RuleConditionElement.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/VariableConstraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/VariableRestriction.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/runtime/rule/impl/AgendaImpl.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/Constraint.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java
labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/Restriction.java
Log:
Major bugfix and extension
Modified: labs/jbossrules/branches/DroolsChance/drools-core/.classpath
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/.classpath 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/.classpath 2009-05-15 03:45:05 UTC (rev 26543)
@@ -4,7 +4,8 @@
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-6-sun-1.6.0.10"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -31,6 +31,7 @@
import org.drools.base.FireAllRulesRuleBaseUpdateListener;
import org.drools.common.AgendaGroupFactory;
import org.drools.common.ArrayAgendaGroupFactory;
+import org.drools.common.ImperfectAgendaGroupFactory;
import org.drools.common.PriorityQueueAgendaGroupFactory;
import org.drools.concurrent.DefaultExecutorService;
import org.drools.conf.AlphaThresholdOption;
@@ -133,8 +134,8 @@
private String executorService;
private String consequenceExceptionHandler;
private String ruleBaseUpdateHandler;
+ private boolean imperfect;
-
private EventProcessingMode eventProcessingMode;
@@ -157,6 +158,8 @@
private transient ClassLoader classLoader;
+
+
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject( chainedProperties );
out.writeBoolean( immutable );
@@ -299,8 +302,10 @@
setMaxThreads( StringUtils.isEmpty( value ) ? -1 : Integer.parseInt( value ) );
} else if ( name.equals( "drools.eventProcessingMode" ) ) {
setEventProcessingMode( EventProcessingMode.determineAssertBehaviour( StringUtils.isEmpty( value ) ? "cloud" : value ) );
- } else if ( name.equals( "drools.imperfect.factory" ) ) {
+ } else if ( name.equals( "org.drools.chance.factory" ) ) {
setFactoryName(value);
+ } else if ( name.equals( "org.drools.chance.enable" ) ) {
+ setImperfectActive(Boolean.parseBoolean(value));
}
}
@@ -350,7 +355,7 @@
return Integer.toString( getMaxThreads() );
} else if ( name.equals( "drools.eventProcessingMode" ) ) {
return getEventProcessingMode().toExternalForm();
- } else if ( name.equals( "drools.imperfect.factory" ) ) {
+ } else if ( name.equals( "org.drools.chance.factory" ) ) {
return getFactoryName();
}
@@ -454,10 +459,16 @@
setEventProcessingMode( EventProcessingMode.determineAssertBehaviour( this.chainedProperties.getProperty( "drools.eventProcessingMode",
"cloud" ) ) );
- setFactoryName(this.chainedProperties.getProperty("drools.imperfect.factory", "org.drools.degrees.factory.SimpleDegreeFactory"));
+ setFactoryName(this.chainedProperties.getProperty("org.drools.chance.factory", "org.drools.degrees.factory.SimpleDegreeFactory"));
+
+ setImperfectActive( Boolean.valueOf( this.chainedProperties.getProperty("org.drools.chance.enable", "false")).booleanValue());
}
- /**
+ private void setImperfectActive(boolean booleanValue) {
+ this.imperfect = booleanValue;
+ }
+
+ /**
* Makes the configuration object immutable. Once it becomes immutable,
* there is no way to make it mutable again.
* This is done to keep consistency.
@@ -628,11 +639,18 @@
return PriorityQueueAgendaGroupFactory.getInstance();
}
} else {
- return PriorityQueueAgendaGroupFactory.getInstance();
+ if (! isImperfect())
+ return PriorityQueueAgendaGroupFactory.getInstance();
+ else
+ return ImperfectAgendaGroupFactory.getInstance();
}
}
- public SequentialAgenda getSequentialAgenda() {
+ public boolean isImperfect() {
+ return imperfect;
+ }
+
+ public SequentialAgenda getSequentialAgenda() {
return this.sequentialAgenda;
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/BaseEvaluator.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/BaseEvaluator.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/BaseEvaluator.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -174,8 +174,9 @@
Object left) {
return factory.fromBoolean(this.evaluateCachedRight(workingMemory, context, left));
}
+
+
-
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -291,7 +291,7 @@
this.consequenceDegree = deg;
}
- public void inject(ArgList args, String field, String op, String value) {
+ public void injectKey(ArgList args, String field, String op, String value) {
System.out.println("\n"+this.getClass()+" : KH injects a rule for degree "+getConsequenceDegree());
workingMemory.inject(this.getRule().getName(),
args,
@@ -305,16 +305,16 @@
return consequenceDegree;
}
- public void inject(Object arg, String field, String op, String value) {
- this.inject(new ArgList(arg), field, op, value);
+ public void injectKey(Object arg, String field, String op, String value) {
+ this.injectKey(new ArgList(arg), field, op, value);
}
- public void inject(Object[] args, String field, String op, String value) {
- this.inject(new ArgList(args), field, op, value);
+ public void injectKey(Object[] args, String field, String op, String value) {
+ this.injectKey(new ArgList(args), field, op, value);
}
- public void inject(Object arg, String key) {
+ public void injectKey(Object arg, String key) {
workingMemory.inject(this.getRule().getName(),
new ArgList(arg),
new ConstraintKey(key),
@@ -322,7 +322,7 @@
}
- public void inject(Object[] args, String key) {
+ public void injectKey(Object[] args, String key) {
workingMemory.inject(this.getRule().getName(),
new ArgList(args),
new ConstraintKey(key),
@@ -337,6 +337,41 @@
public void setEvaluation(Evaluation eval) {
this.evaluation = eval;
}
+
+
+
+ public void injectId(Object arg, String id) {
+ ConstraintKey key = workingMemory.retrieveKeyForId(id);
+ workingMemory.inject(this.getRule().getName(),
+ new ArgList(arg),
+ key,
+ getConsequenceDegree());
+ }
+
+ public void injectId(Object[] args, String id) {
+ ConstraintKey key = workingMemory.retrieveKeyForId(id);
+ workingMemory.inject(this.getRule().getName(),
+ new ArgList(args),
+ key,
+ getConsequenceDegree());
+ }
+
+ public void inject(Object arg, String field, String op, String value) {
+ injectKey(arg,field,op,value);
+
+ }
+
+ public void inject(Object[] args, String field, String op, String value) {
+ injectKey(args,field,op,value);
+ }
+
+ public void inject(Object arg, String key) {
+ injectKey(arg,key);
+ }
+
+ public void inject(Object[] args, String key) {
+ injectKey(args,key);
+ }
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/base/SequentialKnowledgeHelper.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -212,7 +212,7 @@
- public void inject(ArgList args, String field, String op, String value) {
+ public void injectKey(ArgList args, String field, String op, String value) {
// TODO Auto-generated method stub
}
@@ -227,21 +227,21 @@
}
- public void inject(Object arg, String field, String op, String value) {
- this.inject(new ArgList(arg), field, op, value);
+ public void injectKey(Object arg, String field, String op, String value) {
+ this.injectKey(new ArgList(arg), field, op, value);
}
- public void inject(Object[] args, String field, String op, String value) {
- this.inject(new ArgList(args), field, op, value);
+ public void injectKey(Object[] args, String field, String op, String value) {
+ this.injectKey(new ArgList(args), field, op, value);
}
- public void inject(Object arg, String key) {
+ public void injectKey(Object arg, String key) {
// TODO Auto-generated method stub
}
- public void inject(Object[] args, String key) {
+ public void injectKey(Object[] args, String key) {
// TODO Auto-generated method stub
}
@@ -255,4 +255,34 @@
// TODO Auto-generated method stub
}
+
+ public void injectId(Object arg, String key) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void injectId(Object[] args, String key) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void inject(Object arg, String field, String op, String value) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void inject(Object[] args, String field, String op, String value) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void inject(Object arg, String key) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void inject(Object[] args, String key) {
+ // TODO Auto-generated method stub
+
+ }
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -1987,6 +1987,11 @@
return;
}
+
+ public ConstraintKey retrieveKeyForId(String id) {
+ ConstraintKey ck = this.ruleBase.getRete().retrieveKeyForId(id);
+ return ck;
+ }
private Evaluation prepareEval(String ruleName, ArgList args, ConstraintKey key,
IDegree degree, IGammaNode node) {
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/BetaConstraints.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/BetaConstraints.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/BetaConstraints.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -65,5 +65,7 @@
public Collection<ConstraintKey> getAllConstraintKeys();
public EvaluationTemplate getEvalTemplate(ConstraintKey key);
+
+ public boolean isCutter();
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/BinaryHeapQueueAgendaGroup.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -98,7 +98,7 @@
}
public void add(final Activation activation) {
- this.queue.enqueue( (Queueable) activation );
+ this.queue.enqueue( (Queueable) activation );
}
public Activation getNext() {
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DefaultAgenda.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DefaultAgenda.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DefaultAgenda.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -353,6 +353,7 @@
}
agendaGroup.add( activation );
+
} else {
// There is a RuleFlowNode so add it there, instead of the Agenda
InternalRuleFlowGroup rfg = (InternalRuleFlowGroup) this.getRuleFlowGroup( activation.getRule().getRuleFlowGroup() );
@@ -398,7 +399,83 @@
return true;
}
+
+
+
+ public boolean addActivation(final ImperfectAgendaItem activation) {
+ // set the focus if rule autoFocus is true
+ if ( activation.getRule().getAutoFocus() ) {
+ this.setFocus( activation.getRule().getAgendaGroup() );
+ }
+ // adds item to activation group if appropriate
+ addItemToActivationGroup( activation );
+
+ InternalAgendaGroup agendaGroup = (InternalAgendaGroup) this.getAgendaGroup( activation.getRule().getAgendaGroup() );
+ activation.setAgendaGroup( agendaGroup );
+
+ if ( activation.getRule().getRuleFlowGroup() == null ) {
+ // No RuleFlowNode so add it directly to the Agenda
+
+ // do not add the activation if the rule is "lock-on-active" and the
+ // AgendaGroup is active
+ // we must check the context to determine if its a new tuple or an
+ // exist re-activated tuple as part of the retract
+ if ( activation.getPropagationContext().getType() == PropagationContext.MODIFICATION ) {
+
+ if ( activation.getRule().isLockOnActive() && agendaGroup.isActive() ) {
+ Activation justifier = activation.getPropagationContext().removeRetractedTuple( activation.getRule(),
+ (LeftTuple) activation.getTuple() );
+
+ if ( justifier == null ) {
+ // This rule is locked and active, do not allow new
+ // tuples to activate
+ return false;
+ } else if ( activation.getRule().hasLogicalDependency() ) {
+ copyLogicalDependencies( activation.getPropagationContext(),
+ workingMemory,
+ activation,
+ justifier );
+ }
+ } else if ( activation.getRule().hasLogicalDependency() ) {
+ Activation justifier = activation.getPropagationContext().removeRetractedTuple( activation.getRule(),
+ (LeftTuple) activation.getTuple() );
+ copyLogicalDependencies( activation.getPropagationContext(),
+ workingMemory,
+ activation,
+ justifier );
+ }
+
+ } else if ( activation.getRule().isLockOnActive() && agendaGroup.isActive() ) {
+ return false;
+ }
+
+ agendaGroup.add( activation );
+
+ }
+
+ // making sure we re-evaluate agenda in case we are waiting for activations
+ synchronized ( this.halt ) {
+ this.halt.notifyAll();
+ }
+ return true;
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
private void copyLogicalDependencies(final PropagationContext context,
final InternalWorkingMemory workingMemory,
final AgendaItem item,
@@ -932,7 +1009,7 @@
try {
//TODO:
- //System.out.println(this.getClass()+"Hacked fireActivation to insert consequence degree");
+ System.out.println(this.getClass()+"Hacked fireActivation to insert consequence degree");
if (activation instanceof ImperfectAgendaItem) {
this.knowledgeHelper.setConsequenceDegree(((ImperfectAgendaItem) activation).getDegree());
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DefaultBetaConstraints.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -415,5 +415,12 @@
return null;
}
-
+ public boolean isCutter() {
+ org.drools.util.Iterator iter = this.constraints.iterator();
+ for (int j = 0; j < this.constraints.size(); j++) {
+ if ( ((BetaConstraints) iter.next()).isCutter() )
+ return true;
+ }
+ return false;
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -371,5 +371,8 @@
ans = constraint1.getEvalTemplate(key);
return ans;
}
+ public boolean isCutter() {
+ return constraint0.isCutter() || constraint1.isCutter();
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/EmptyBetaConstraints.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -181,5 +181,9 @@
public EvaluationTemplate getEvalTemplate(ConstraintKey key) {
return null;
}
+
+ public boolean isCutter() {
+ return false;
+ }
}
\ No newline at end of file
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImperfectAgendaGroup.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImperfectAgendaGroup.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImperfectAgendaGroup.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,202 @@
+package org.drools.common;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.drools.RuntimeDroolsException;
+import org.drools.degrees.IDegree;
+import org.drools.reteoo.Evaluation;
+import org.drools.reteoo.ImperfectAgendaItem;
+import org.drools.spi.Activation;
+
+import sun.security.x509.AVA;
+
+public class ImperfectAgendaGroup implements InternalAgendaGroup {
+
+
+ private boolean active;
+
+ private LinkedList<ImperfectAgendaItem> store = new LinkedList<ImperfectAgendaItem>();
+
+ private String name;
+
+
+ public ImperfectAgendaGroup(String name, InternalRuleBase ruleBase) {
+ this.name = name;
+ }
+
+ public void add(Activation activation) {
+
+ ImperfectAgendaItem agItem = ((ImperfectAgendaItem) activation);
+
+ int tgt = activation.hashCode();
+ Iterator iter = store.iterator();
+ System.out.print("Set is made of : ");
+ while (iter.hasNext()) {
+ ImperfectAgendaItem impAit = (ImperfectAgendaItem) iter.next();
+ int code = impAit.hashCode();
+ IDegree deg = impAit.getDegree();
+ System.out.print(code + "/"+deg+" ( " + (tgt == code) + ")\t");
+ }
+
+ int idx = store.indexOf(agItem);
+ if (idx != -1) {
+
+ ImperfectAgendaItem oldAct = store.get(idx);
+ store.remove(idx);
+
+ org.drools.util.LinkedList deps = oldAct.getLogicalDependencies();
+ if (deps != null) {
+ org.drools.util.Iterator depIter = deps.iterator();
+ while (depIter.hasNext())
+ agItem.addLogicalDependency((LogicalDependency) depIter.next() );
+ System.out.println("Moved deps from old activ");
+ }
+
+
+ System.out.println("Replaced old activ");
+ }
+
+ System.out.println("added activation " + agItem.getEvaluation().hashCode() + " with degree " + agItem.getDegree());
+ store.add(agItem);
+ agItem.setActivated(true);
+
+ System.out.println("After adding activation: ");
+ System.out.println(this.getStatus());
+ System.out.println();
+ }
+
+ public void clear() {
+ this.store.clear();
+ }
+
+ public Activation getNext() {
+
+
+ System.out.println("Before getting next :");
+ System.out.println(this.getStatus());
+ System.out.println();
+
+ Activation activ = store.iterator().next();
+ int tgt = activ.hashCode();
+ System.out.print("\n Looking for : "+activ.hashCode());
+
+ Iterator iter = store.iterator();
+ System.out.print("Set is made of : ");
+ while (iter.hasNext()) {
+ int code = iter.next().hashCode();
+ System.out.print(code + "( " + (tgt == code) + "\t");
+ }
+
+
+ store.remove(activ);
+
+ System.out.println("Afer getting next");
+ System.out.println(this.getStatus());
+ System.out.println();
+ return activ;
+ }
+
+ public Activation[] getQueue() {
+ throw new RuntimeDroolsException("nt here");
+// Activation[] ans = new Activation[store.size()];
+// int j = 0;
+// for (Activation act : store.values())
+// ans[j++] = act;
+//
+// System.out.println(this.getStatus());
+// System.out.println();
+//
+// return ans;
+ }
+
+ public void setActive(boolean activate) {
+ this.active = activate;
+ }
+
+ public org.drools.runtime.rule.Activation[] getActivations() {
+ throw new RuntimeDroolsException("nt here");
+// org.drools.runtime.rule.Activation[] ans = (org.drools.runtime.rule.Activation[])
+// this.store.values().toArray( new ImperfectAgendaItem[this.store.size()] );
+//
+// System.out.println(this.getStatus());
+// System.out.println();
+//
+// return ans;
+ }
+
+ public boolean isActive() {
+ return isActive();
+ }
+
+ public boolean isEmpty() {
+ return this.store.size() == 0;
+ }
+
+ public int size() {
+ return this.store.size();
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ store = (LinkedList<ImperfectAgendaItem>) in.readObject();
+ active = in.readBoolean();
+
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(store);
+ out.writeBoolean(active);
+
+
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setFocus() {
+ throw new UnsupportedOperationException("No agenda focusing");
+ }
+
+ public boolean remove(Activation act) {
+ return this.store.remove(act);
+
+ }
+
+
+
+ public String getStatus() {
+ StringBuilder sb = new StringBuilder(this.getName()+"\n");
+
+
+ Iterator<ImperfectAgendaItem> iter = store.iterator();
+
+ while (iter.hasNext()) {
+ sb.append("\t" + iter.next());
+ }
+
+// for (Evaluation eval : store.keySet()) {
+// if (store.get(eval) == null) {
+// System.out.println(eval.equals(eval));
+// System.out.println(store.get(eval));
+// System.out.println(store.containsKey(eval));
+// System.out.println("???");
+// System.out.println(store.containsKey(eval));
+// }
+// sb.append((store.get(eval).toString()));
+// }
+ return sb.toString();
+
+ }
+
+}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImperfectAgendaGroupFactory.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImperfectAgendaGroupFactory.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImperfectAgendaGroupFactory.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,17 @@
+package org.drools.common;
+
+
+public class ImperfectAgendaGroupFactory implements AgendaGroupFactory {
+
+ private static ImperfectAgendaGroupFactory INSTANCE = new ImperfectAgendaGroupFactory();
+
+ public InternalAgendaGroup createAgendaGroup(String name,
+ InternalRuleBase ruleBase) {
+ return new ImperfectAgendaGroup(name, ruleBase);
+ }
+
+ public static AgendaGroupFactory getInstance() {
+ return INSTANCE;
+ }
+
+}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImplicationBetaConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImplicationBetaConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/ImplicationBetaConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -259,5 +259,19 @@
+
+
+
+ public boolean isCutter() {
+ return false;
+ }
+
+
+
+
+
+
+
+
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InstanceEqualsConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -138,7 +138,7 @@
}
final InstanceEqualsConstraint other = (InstanceEqualsConstraint) object;
- return this.otherPattern.equals( other.otherPattern );
+ return this.otherPattern.equals( other.otherPattern ) && (this.isCutter() == other.isCutter());
}
public static class InstanceEqualsConstraintContextEntry
@@ -208,6 +208,8 @@
private ConstraintKey singletonKey = null;
private EvaluationTemplate template;
+
+ private boolean cutter;
public ConstraintKey getConstraintKey() {
if (singletonKey == null) {
@@ -237,5 +239,13 @@
factory.getNullHandlingStrategy());
return template;
}
+
+ public boolean isCutter() {
+ return cutter;
+ }
+
+ public void setCutter(boolean cut) {
+ cutter = cut;
+ }
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InstanceNotEqualsConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -133,7 +133,7 @@
}
final InstanceNotEqualsConstraint other = (InstanceNotEqualsConstraint) object;
- return this.otherPattern.equals( other.otherPattern );
+ return this.otherPattern.equals( other.otherPattern ) && (this.isCutter() == other.isCutter());
}
public Object clone() {
@@ -208,6 +208,8 @@
private ConstraintKey singletonKey = null;
private EvaluationTemplate template;
+
+ private boolean cutter;
public ConstraintKey getConstraintKey() {
if (singletonKey == null) {
@@ -242,6 +244,14 @@
factory.getNullHandlingStrategy());
return template;
}
+
+ public boolean isCutter() {
+ return cutter;
+ }
+
+ public void setCutter(boolean cut) {
+ cutter = cut;
+ }
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/InternalWorkingMemoryActions.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -18,6 +18,7 @@
import org.drools.FactException;
import org.drools.FactHandle;
+import org.drools.reteoo.ConstraintKey;
import org.drools.rule.Rule;
import org.drools.spi.Activation;
@@ -54,4 +55,6 @@
final Rule rule,
final Activation activation);
+ public ConstraintKey retrieveKeyForId(String id);
+
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/LogicalDependency.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/LogicalDependency.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/LogicalDependency.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -56,10 +56,13 @@
}
final LogicalDependency other = (LogicalDependency) object;
- return (this.getJustifier() == other.getJustifier() && this.getFactHandle() == other.getFactHandle());
+ boolean just = this.getJustifier().equals(other.getJustifier());
+ boolean hand = this.getFactHandle().equals(other.getFactHandle());
+ return ( just && hand );
}
public int hashCode() {
+// System.out.println("Logical dep hashcode "+this.justifier.hashCode());
return this.justifier.hashCode();
}
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -495,5 +495,8 @@
return ans;
}
+ public boolean isCutter() {
+ return constraint0.isCutter() || constraint1.isCutter() || constraint2.isCutter() || constraint3.isCutter();
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -292,5 +292,9 @@
public EvaluationTemplate getEvalTemplate(ConstraintKey key) {
return this.constraint.getEvalTemplate(key);
}
+
+ public boolean isCutter() {
+ return constraint.isCutter();
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -427,5 +427,9 @@
ans = constraint2.getEvalTemplate(key);
return ans;
}
+
+ public boolean isCutter() {
+ return constraint0.isCutter() || constraint1.isCutter() || constraint2.isCutter();
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TruthMaintenanceSystem.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -19,9 +19,12 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.util.Calendar;
+import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
+import java.util.Timer;
import org.drools.FactException;
import org.drools.marshalling.impl.MarshallerReaderContext;
@@ -268,6 +271,8 @@
this.tms.getJustifiedMap().remove( handle.getId() );
// this needs to be scheduled so we don't upset the current
// working memory operation
+ System.out.println("Retracting "+handle.toString()+"at" + Calendar.getInstance().getTimeInMillis());
+
workingMemory.retract( this.handle,
false,
true,
@@ -326,6 +331,12 @@
this.justifiedMap.put( handle.getId(),
set );
}
+ System.out.println("Adding a dep NOde "+node.hashCode() + " set contains "+set.contains(node));
+ for (Object o : set) {
+ LogicalDependency l = (LogicalDependency) o;
+ System.out.println("Set contains "+l + " code : " +l.hashCode());
+ System.out.println(l.equals(node));
+ }
set.add( node );
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/common/TupleStartEqualsConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -134,8 +134,10 @@
}
public boolean equals(final Object object) {
- if ( object instanceof TupleStartEqualsConstraint ) {
- return true;
+ if ( object instanceof TupleStartEqualsConstraint) {
+ TupleStartEqualsConstraint other = (TupleStartEqualsConstraint) object;
+
+ return this.isCutter() == other.isCutter();
}
return false;
}
@@ -212,6 +214,8 @@
private ConstraintKey singletonKey = null;
private EvaluationTemplate template;
+
+ private boolean cutter;
public ConstraintKey getConstraintKey() {
if (singletonKey == null) {
@@ -245,4 +249,12 @@
}
+ public boolean isCutter() {
+ return cutter;
+ }
+
+ public void setCutter(boolean cut) {
+ cutter = cut;
+ }
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/IDegreeFactory.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/IDegreeFactory.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/IDegreeFactory.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -36,7 +36,9 @@
public IDegreeCombiner getEquivOperator();
+ public IDegreeCombiner getXorOperator();
+
public IDegreeCombiner getAggregator();
@@ -66,7 +68,48 @@
public IMergeStrategy getMergeStrategy();
public INullHandlingStrategy getNullHandlingStrategy();
+
+
+ public IDegreeCombiner getDoubleMPOperator();
+
+
+ public IDegreeCombiner getDiscountOperator();
+ public IDegreeCombiner getHedgeOperator();
+
+
+
+
+ public IDegreeCombiner getModusPonensOperator(String params);
+
+ public IDegreeCombiner getDoubleMPOperator(String params);
+
+
+ public IDegreeCombiner getDiscountOperator(String params);
+
+
+ public IDegreeCombiner getEquivOperator(String params);
+
+
+ public IDegreeCombiner getXorOperator(String params);
+
+
+ public IDegreeCombiner getOrOperator(String params);
+
+
+ public IDegreeCombiner getAndOperator(String params);
+
+
+
+
+
+ public IDegreeCombiner getHedgeOperator(String params);
+
+
+ public IDegree buildDegree(String priorStr);
+
+
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/IntervalDegreeFactory.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/IntervalDegreeFactory.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/IntervalDegreeFactory.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -7,6 +7,8 @@
import org.drools.degrees.operators.INullHandlingStrategy;
import org.drools.degrees.operators.intervals.DefaultIntervalMergeStrategy;
import org.drools.degrees.operators.intervals.DefaultIntervalNullHandlingStrategy;
+import org.drools.degrees.operators.intervals.IntervalDiscountOperator;
+import org.drools.degrees.operators.intervals.IntervalDoubleMPOperator;
import org.drools.degrees.operators.intervals.IntervalEquivOperator;
import org.drools.degrees.operators.intervals.IntervalExistsOperator;
import org.drools.degrees.operators.intervals.IntervalForAnyOperator;
@@ -18,6 +20,8 @@
import org.drools.degrees.operators.intervals.IntervalMinAndOperator;
import org.drools.degrees.operators.intervals.IntervalModusPonensOperator;
import org.drools.degrees.operators.intervals.IntervalNegationOperator;
+import org.drools.degrees.operators.intervals.IntervalXorOperator;
+import org.drools.reteoo.DoubleMPOperatorInstaller;
import org.drools.reteoo.filters.DefaultIntervalFilterStrategy;
import org.drools.reteoo.filters.IFilterStrategy;
@@ -70,6 +74,11 @@
public IDegreeCombiner getEquivOperator() {
return new IntervalEquivOperator();
}
+
+
+ public IDegreeCombiner getXorOperator() {
+ return new IntervalXorOperator();
+ }
public IDegreeCombiner getExistsOperator() {
return new IntervalExistsOperator();
@@ -111,4 +120,72 @@
return new IntervalLukasOrOperator();
}
+ public IDegreeCombiner getDiscountOperator() {
+ return new IntervalDiscountOperator();
+ }
+
+ public IDegreeCombiner getDoubleMPOperator() {
+ return new IntervalDoubleMPOperator();
+ }
+
+
+
+
+
+ public IDegreeCombiner getAndOperator(String params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public IDegreeCombiner getDiscountOperator(String params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public IDegreeCombiner getDoubleMPOperator(String params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public IDegreeCombiner getEquivOperator(String params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public IDegreeCombiner getOrOperator(String params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public IDegreeCombiner getXorOperator(String params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public IDegreeCombiner getHedgeOperator() {
+ throw new UnsupportedOperationException("Not yet...");
+ }
+
+ public IDegreeCombiner getHedgeOperator(String params) {
+ throw new UnsupportedOperationException("Not yet...");
+ }
+
+ public IDegree buildDegree(String priorStr) {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException("Not yet...");
+ }
+
+ public IDegreeCombiner getModusPonensOperator(String params) {
+ if (params == null)
+ return getModusPonensOp();
+
+ if (params.equals("implication")) {
+ return getModusPonensOp();
+ } else if (params.equals("equivalence")) {
+ return getDoubleMPOperator();
+ } else
+ return getModusPonensOp();
+
+ }
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/SimpleDegreeFactory.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/SimpleDegreeFactory.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/factory/SimpleDegreeFactory.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -8,13 +8,20 @@
import org.drools.degrees.operators.INullHandlingStrategy;
import org.drools.degrees.operators.simple.SimpleAverage;
import org.drools.degrees.operators.simple.SimpleDotAnd;
+import org.drools.degrees.operators.simple.SimpleDoubleMPOperator;
import org.drools.degrees.operators.simple.SimpleEquiv;
import org.drools.degrees.operators.simple.SimpleExists;
+import org.drools.degrees.operators.simple.SimpleIdentityOperator;
+import org.drools.degrees.operators.simple.SimpleLukasAnd;
+import org.drools.degrees.operators.simple.SimpleLukasOr;
import org.drools.degrees.operators.simple.SimpleMaxOr;
import org.drools.degrees.operators.simple.SimpleMinAnd;
import org.drools.degrees.operators.simple.SimpleNot;
import org.drools.degrees.operators.simple.SimpleMergeStrategy;
import org.drools.degrees.operators.simple.SimpleNullHandlingStrategy;
+import org.drools.degrees.operators.simple.SimpleProbSumOr;
+import org.drools.degrees.operators.simple.SimpleVeryModifier;
+import org.drools.degrees.operators.simple.SimpleXor;
import org.drools.reteoo.filters.IFilterStrategy;
import org.drools.reteoo.filters.SimpleFilterStrategy;
@@ -69,6 +76,10 @@
public IDegreeCombiner getEquivOperator() {
return new SimpleEquiv();
}
+
+ public IDegreeCombiner getXorOperator() {
+ return new SimpleXor();
+ }
public IDegreeCombiner getAggregator() {
return new SimpleMaxOr();
@@ -129,11 +140,97 @@
}
public IDegreeCombiner getForAnyOperator() {
- return new SimpleAverage();
+ return new SimpleAverage();
+ //return new SimpleExists();
}
public IDegreeCombiner getForallOperator() {
return this.getAndOperator();
}
+ public IDegreeCombiner getDiscountOperator() {
+ return new SimpleIdentityOperator();
+ }
+
+ public IDegreeCombiner getDoubleMPOperator() {
+ return new SimpleDoubleMPOperator();
+ }
+
+
+
+
+
+ public IDegreeCombiner getAndOperator(String params) {
+ if (params == null)
+ return getAndOperator();
+ if (params.equals("Lukas"))
+ return new SimpleLukasAnd();
+ else if (params.equals("Prod"))
+ return new SimpleDotAnd();
+ else if (params.equals("Min"))
+ return new SimpleMinAnd();
+ else return getAndOperator();
+ }
+
+ public IDegreeCombiner getDiscountOperator(String params) {
+ throw new UnsupportedOperationException("Not yet ready to do this :"+ params);
+ }
+
+ public IDegreeCombiner getDoubleMPOperator(String params) {
+ throw new UnsupportedOperationException("Not yet ready to do this :"+ params);
+ }
+
+ public IDegreeCombiner getEquivOperator(String params) {
+ throw new UnsupportedOperationException("Not yet ready to do this :"+ params);
+ }
+
+ public IDegreeCombiner getOrOperator(String params) {
+ if (params == null)
+ return getOrOperator();
+
+ if (params.equals("Lukas"))
+ return new SimpleLukasOr();
+ else if (params.equals("Plus"))
+ return new SimpleProbSumOr();
+ else if (params.equals("Max"))
+ return new SimpleMaxOr();
+ else return getOrOperator();
+ }
+
+ public IDegreeCombiner getXorOperator(String params) {
+ throw new UnsupportedOperationException("Not yet ready to do this :"+ params);
+ }
+
+
+
+ public IDegreeCombiner getHedgeOperator() {
+ return new SimpleVeryModifier();
+ }
+
+ public IDegreeCombiner getHedgeOperator(String params) {
+ if (params.equals("very")) {
+ return new SimpleVeryModifier();
+ } else {
+ return new SimpleVeryModifier();
+ }
+
+ }
+
+ public IDegree buildDegree(String priorStr) {
+ return new SimpleDegree(Float.parseFloat(priorStr));
+ }
+
+ public IDegreeCombiner getModusPonensOperator(String params) {
+ if (params == null)
+ return getModusPonensOp();
+
+ if (params.equals("implication")) {
+ return getModusPonensOp();
+ } else if (params.equals("equivalence")) {
+ return getDoubleMPOperator();
+ } else
+ return getModusPonensOp();
+
+ }
+
}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/NegationOperator.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/NegationOperator.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/NegationOperator.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,34 @@
+package org.drools.degrees.operators;
+
+import java.util.Collection;
+
+import org.drools.degrees.IDegree;
+
+public abstract class NegationOperator implements IDegreeCombiner {
+
+
+
+
+ protected IDegreeCombiner operator;
+
+ public void setOperator(IDegreeCombiner op) {
+ this.operator = op;
+ }
+
+ public IDegree eval(IDegree[] args) {
+ return negate(operator.eval(args));
+ }
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+ return negate(operator.eval(args));
+ }
+
+ public String getName() {
+ return "-"+operator.getName();
+ }
+
+
+ protected abstract IDegree negate(IDegree arg);
+
+
+}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalDiscountOperator.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalDiscountOperator.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalDiscountOperator.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,43 @@
+package org.drools.degrees.operators.intervals;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.drools.degrees.IDegree;
+import org.drools.degrees.IntervalDegree;
+import org.drools.degrees.SimpleDegree;
+import org.drools.degrees.factory.SimpleDegreeFactory;
+import org.drools.degrees.operators.IDegreeCombiner;
+
+public class IntervalDiscountOperator implements IDegreeCombiner {
+
+ public IDegree eval(IDegree[] args) {
+ if (args == null || args.length < 2)
+ return SimpleDegreeFactory.UNKNOWN;
+
+ IntervalDegree ival = (IntervalDegree) args[0];
+ SimpleDegree disc = args[1].getDegree();
+ float alfa = disc.getValue();
+
+
+ return new IntervalDegree(ival.getTau()*alfa, 1 - ival.getPhi()*alfa);
+ }
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+ if (args == null || args.size() < 2)
+ return SimpleDegreeFactory.UNKNOWN;
+ Iterator<? extends IDegree> iter= args.iterator();
+
+ IntervalDegree ival = (IntervalDegree) iter.next();
+ SimpleDegree disc = iter.next().getDegree();
+ float alfa = disc.getValue();
+
+
+ return new IntervalDegree(ival.getTau()*alfa, 1 - ival.getPhi()*alfa);
+ }
+
+ public String getName() {
+ return "i_discount";
+ }
+
+}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalDoubleMPOperator.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalDoubleMPOperator.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalDoubleMPOperator.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,47 @@
+package org.drools.degrees.operators.intervals;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.drools.degrees.IDegree;
+import org.drools.degrees.IntervalDegree;
+import org.drools.degrees.SimpleDegree;
+import org.drools.degrees.factory.SimpleDegreeFactory;
+import org.drools.degrees.operators.IDegreeCombiner;
+import org.drools.time.Interval;
+
+public class IntervalDoubleMPOperator implements IDegreeCombiner {
+
+ public IDegree eval(IDegree[] args) {
+ if (args == null || args.length < 2)
+ return SimpleDegreeFactory.UNKNOWN;
+
+ IntervalDegree prem = (IntervalDegree) args[0];
+ IntervalDegree impl = (IntervalDegree) args[1];
+
+ float tau = Math.min(prem.getTau(),impl.getTau());
+ float phi = Math.min(prem.getPhi(),impl.getTau());
+
+ return new IntervalDegree(tau, phi);
+
+ }
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+ if (args == null || args.size() < 2)
+ return SimpleDegreeFactory.UNKNOWN;
+ Iterator<? extends IDegree> iter= args.iterator();
+
+ IntervalDegree prem = (IntervalDegree) iter.next();
+ IntervalDegree impl = (IntervalDegree) iter.next();
+
+ float tau = Math.min(prem.getTau(),impl.getTau());
+ float phi = Math.min(prem.getPhi(),impl.getTau());
+
+ return new IntervalDegree(tau, phi);
+ }
+
+ public String getName() {
+ return "i_dblMP";
+ }
+
+}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalXorOperator.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalXorOperator.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/intervals/IntervalXorOperator.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,47 @@
+package org.drools.degrees.operators.intervals;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.drools.degrees.IDegree;
+import org.drools.degrees.IntervalDegree;
+import org.drools.degrees.factory.IntervalDegreeFactory;
+import org.drools.degrees.operators.IDegreeCombiner;
+
+public class IntervalXorOperator implements IDegreeCombiner {
+
+ public IDegree eval(IDegree[] args) {
+ if (args == null || args.length < 2)
+ return IntervalDegreeFactory.UNKNOWN;
+
+ IntervalDegree a1 = (IntervalDegree) args[0];
+ IntervalDegree a2 = (IntervalDegree) args[1];
+
+ if (a1.getUpp() < a2.getLow() || a2.getUpp() < a1.getLow())
+ return IntervalDegreeFactory.FALSE;
+
+ float maxDist = Math.max(a2.getUpp()-a1.getLow(),a1.getUpp()-a2.getLow());
+ return new IntervalDegree(0,maxDist);
+
+ }
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+ if (args == null || args.size() < 2)
+ return IntervalDegreeFactory.UNKNOWN;
+
+ Iterator<? extends IDegree> iter = args.iterator();
+ IntervalDegree a1 = (IntervalDegree) iter.next();
+ IntervalDegree a2 = (IntervalDegree) iter.next();
+
+ if (a1.getUpp() < a2.getLow() || a2.getUpp() < a1.getLow())
+ return IntervalDegreeFactory.FALSE;
+
+ float maxDist = Math.max(a2.getUpp()-a1.getLow(),a1.getUpp()-a2.getLow());
+ return new IntervalDegree(0,maxDist);
+ }
+
+ public String getName() {
+ return "i_equiv";
+ }
+
+}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleAverage.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleAverage.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleAverage.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -9,7 +9,26 @@
public final class SimpleAverage implements IDegreeCombiner {
+
+ public IDegree eval(IDegree[] args) {
+ if (args == null || args.length == 0)
+ return SimpleDegree.UNKNOWN();
+
+ float ans = 0;
+ int n = 0;
+ for (IDegree deg : args) {
+ SimpleDegree d = deg.getDegree();
+ ans += d.getValue();
+ n++;
+ }
+
+ return new SimpleDegree(ans / n);
+ }
+
+
+
+ /*
public IDegree eval(IDegree[] args) {
float acc = 0;
float wgts = 0;
@@ -34,6 +53,7 @@
return new SimpleDegree(acc);
}
+*/
public IDegree eval(Collection<? extends IDegree> args) {
// TODO Auto-generated method stub
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleDoubleMPOperator.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleDoubleMPOperator.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleDoubleMPOperator.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,51 @@
+package org.drools.degrees.operators.simple;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.drools.degrees.IDegree;
+import org.drools.degrees.SimpleDegree;
+import org.drools.degrees.factory.SimpleDegreeFactory;
+import org.drools.degrees.operators.IDegreeCombiner;
+
+public class SimpleDoubleMPOperator implements IDegreeCombiner {
+
+ public IDegree eval(IDegree[] args) {
+ if (args == null || args.length < 2)
+ return SimpleDegreeFactory.UNKNOWN;
+
+ IDegree prem = args[0];
+ IDegree impl = args[1];
+
+ //float mp1 = Math.min(prem.getDegree().getValue(),impl.getDegree().getValue());
+ //float mp2 = 1 - Math.min(1 - prem.getDegree().getValue(),impl.getDegree().getValue());
+
+ float mp1 = prem.getDegree().getValue()*impl.getDegree().getValue();
+ float mp2 = 1 - (1 - prem.getDegree().getValue())*(impl.getDegree().getValue());
+
+ return new SimpleDegree(Math.min(mp1, mp2));
+
+ }
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+ if (args == null || args.size() < 2)
+ return SimpleDegreeFactory.UNKNOWN;
+ Iterator<? extends IDegree> iter= args.iterator();
+
+ IDegree prem = iter.next();
+ IDegree impl = iter.next();
+
+ //float mp1 = Math.min(prem.getDegree().getValue(),impl.getDegree().getValue());
+ //float mp2 = 1 - Math.min(1 - prem.getDegree().getValue(),impl.getDegree().getValue());
+
+ float mp1 = prem.getDegree().getValue()*impl.getDegree().getValue();
+ float mp2 = 1 - (1 - prem.getDegree().getValue())*(impl.getDegree().getValue());
+
+ return new SimpleDegree(Math.min(mp1, mp2));
+ }
+
+ public String getName() {
+ return "dblMP";
+ }
+
+}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleEquiv.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleEquiv.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleEquiv.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -1,9 +1,13 @@
package org.drools.degrees.operators.simple;
import java.util.Collection;
+import java.util.Iterator;
import org.drools.degrees.IDegree;
+import org.drools.degrees.IntervalDegree;
import org.drools.degrees.SimpleDegree;
+import org.drools.degrees.factory.IntervalDegreeFactory;
+import org.drools.degrees.factory.SimpleDegreeFactory;
import org.drools.degrees.operators.IDegreeCombiner;
public class SimpleEquiv implements IDegreeCombiner {
@@ -18,8 +22,18 @@
public IDegree eval(Collection<? extends IDegree> args) {
- // TODO Auto-generated method stub
- return null;
+
+ if (args == null || args.size() < 2)
+ return SimpleDegreeFactory.UNKNOWN;
+
+ Iterator<? extends IDegree> iter = args.iterator();
+ SimpleDegree a1 = (SimpleDegree) iter.next();
+ SimpleDegree a2 = (SimpleDegree) iter.next();
+
+ return new SimpleDegree( 1 - Math.abs(
+ a1.getDegree().getValue()
+ - a2.getDegree().getValue())
+ );
}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleIdentityOperator.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleIdentityOperator.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleIdentityOperator.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,63 @@
+package org.drools.degrees.operators.simple;
+
+import java.util.Collection;
+
+import org.drools.degrees.IDegree;
+import org.drools.degrees.SimpleDegree;
+import org.drools.degrees.operators.IDegreeCombiner;
+
+public final class SimpleIdentityOperator implements IDegreeCombiner {
+
+
+
+ public IDegree eval(IDegree[] args) {
+ if (args == null || args.length == 0)
+ return SimpleDegree.UNKNOWN();
+
+ return args[0];
+ }
+
+
+
+
+ /*
+ public IDegree eval(IDegree[] args) {
+ float acc = 0;
+ float wgts = 0;
+// SimpleDotAnd op = new SimpleDotAnd();
+
+
+ // So the number of elements is actually twice
+ for (int j = 0; j < args.length; j = j+3) {
+ SimpleDegree integrand = (SimpleDegree) args[j];
+// SimpleDegree constraint = (SimpleDegree) args[j+1];
+ SimpleDegree weight = (SimpleDegree) args[j+2];
+
+ float w = weight.getValue();
+
+ if (w > wgts) {
+ wgts = weight.getValue();
+ acc = integrand.getValue();
+ }
+
+
+ }
+
+ return new SimpleDegree(acc);
+ }
+*/
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+ if (args == null || args.size() == 0)
+ return SimpleDegree.UNKNOWN();
+
+ return args.iterator().next();
+ }
+
+ public String getName() {
+ return "identity";
+ }
+
+
+
+}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleLukasAnd.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleLukasAnd.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleLukasAnd.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,43 @@
+package org.drools.degrees.operators.simple;
+
+import java.util.Collection;
+
+import org.drools.degrees.IDegree;
+import org.drools.degrees.SimpleDegree;
+import org.drools.degrees.operators.IDegreeCombiner;
+
+
+public class SimpleLukasAnd implements IDegreeCombiner {
+
+
+ public IDegree eval(IDegree[] args) {
+ if (args == null || args.length == 0)
+ return SimpleDegree.UNKNOWN();
+
+ float ans = 1;
+ for (IDegree deg : args) {
+ SimpleDegree d = deg.getDegree();
+ ans += d.getValue() - 1;
+ }
+
+ return new SimpleDegree(Math.max(0,ans));
+ }
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+ if (args == null || args.size() == 0)
+ return SimpleDegree.UNKNOWN();
+
+ float ans = 1;
+ for (IDegree deg : args) {
+ SimpleDegree d = deg.getDegree();
+ ans += d.getValue() - 1;
+ }
+
+ return new SimpleDegree(Math.max(0,ans));
+ }
+
+ public String getName() {
+ return "lukAnd";
+ }
+
+}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleLukasOr.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleLukasOr.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleLukasOr.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,44 @@
+package org.drools.degrees.operators.simple;
+
+import java.util.Collection;
+
+import org.drools.degrees.IDegree;
+import org.drools.degrees.SimpleDegree;
+import org.drools.degrees.operators.IDegreeCombiner;
+
+
+public class SimpleLukasOr implements IDegreeCombiner {
+
+
+ public IDegree eval(IDegree[] args) {
+ if (args == null || args.length == 0)
+ return SimpleDegree.UNKNOWN();
+
+ float ans = 0;
+ for (IDegree deg : args) {
+ SimpleDegree d = deg.getDegree();
+ ans += d.getValue();
+ }
+
+ return new SimpleDegree(Math.min(1,ans));
+ }
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+ if (args == null || args.size() == 0)
+ return SimpleDegree.UNKNOWN();
+
+
+ float ans = 0;
+ for (IDegree deg : args) {
+ SimpleDegree d = deg.getDegree();
+ ans += d.getValue();
+ }
+
+ return new SimpleDegree(Math.min(1,ans));
+ }
+
+ public String getName() {
+ return "lukasOr";
+ }
+
+}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleMaxOr.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleMaxOr.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleMaxOr.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -24,8 +24,16 @@
}
public IDegree eval(Collection<? extends IDegree> args) {
- // TODO Auto-generated method stub
- return null;
+ if (args == null || args.size() == 0)
+ return SimpleDegree.UNKNOWN();
+
+ float ans = 0;
+ for (IDegree deg : args) {
+ SimpleDegree d = deg.getDegree();
+ ans = Math.max(ans,d.getValue());
+ }
+
+ return new SimpleDegree(ans);
}
public String getName() {
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleProbSumOr.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleProbSumOr.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleProbSumOr.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,31 @@
+package org.drools.degrees.operators.simple;
+
+import java.util.Collection;
+
+import org.drools.degrees.IDegree;
+import org.drools.degrees.SimpleDegree;
+import org.drools.degrees.operators.IDegreeCombiner;
+
+
+public class SimpleProbSumOr implements IDegreeCombiner {
+
+
+ public IDegree eval(IDegree[] args) {
+ if (args == null || args.length == 0)
+ return SimpleDegree.UNKNOWN();
+
+ throw new UnsupportedOperationException("Still to be done");
+ }
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+ if (args == null || args.size() == 0)
+ return SimpleDegree.UNKNOWN();
+
+ throw new UnsupportedOperationException("Still to be done");
+ }
+
+ public String getName() {
+ return "probSumOr";
+ }
+
+}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleVeryModifier.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleVeryModifier.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleVeryModifier.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,37 @@
+package org.drools.degrees.operators.simple;
+
+import java.util.Collection;
+
+import org.drools.degrees.IDegree;
+import org.drools.degrees.SimpleDegree;
+import org.drools.degrees.operators.IDegreeCombiner;
+
+
+public class SimpleVeryModifier implements IDegreeCombiner {
+
+
+ public IDegree eval(IDegree[] args) {
+ if (args == null || args.length == 0)
+ return SimpleDegree.UNKNOWN();
+
+ float arg = args[0].getDegree().getValue();
+
+
+ return new SimpleDegree(arg*arg);
+ }
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+ if (args == null || args.size() == 0)
+ return SimpleDegree.UNKNOWN();
+
+ float arg = args.iterator().next().getDegree().getValue();
+
+
+ return new SimpleDegree(arg*arg);
+ }
+
+ public String getName() {
+ return "very";
+ }
+
+}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleXor.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleXor.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/degrees/operators/simple/SimpleXor.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,44 @@
+package org.drools.degrees.operators.simple;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.drools.degrees.IDegree;
+import org.drools.degrees.SimpleDegree;
+import org.drools.degrees.factory.SimpleDegreeFactory;
+import org.drools.degrees.operators.IDegreeCombiner;
+
+public class SimpleXor implements IDegreeCombiner {
+
+
+ public IDegree eval(IDegree[] args) {
+ return new SimpleDegree( Math.abs(
+ args[0].getDegree().getValue()
+ - args[1].getDegree().getValue())
+ );
+ }
+
+
+ public IDegree eval(Collection<? extends IDegree> args) {
+
+ if (args == null || args.size() < 2)
+ return SimpleDegreeFactory.UNKNOWN;
+
+ Iterator<? extends IDegree> iter = args.iterator();
+ SimpleDegree a1 = (SimpleDegree) iter.next();
+ SimpleDegree a2 = (SimpleDegree) iter.next();
+
+ return new SimpleDegree( Math.abs(
+ a1.getDegree().getValue()
+ - a2.getDegree().getValue())
+ );
+ }
+
+
+ public String getName() {
+ return "distXor";
+ }
+
+
+
+}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/fuzzy/evaluators/FuzzyNumericEvaluator.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/fuzzy/evaluators/FuzzyNumericEvaluator.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/fuzzy/evaluators/FuzzyNumericEvaluator.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -1,17 +1,14 @@
package org.drools.fuzzy.evaluators;
-import java.io.File;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.lang.reflect.InvocationTargetException;
-import java.rmi.server.Skeleton;
import java.util.StringTokenizer;
import org.drools.RuntimeDroolsException;
-import org.drools.WorkingMemory;
import org.drools.base.BaseImperfectEvaluator;
import org.drools.base.ValueType;
import org.drools.base.evaluators.Operator;
@@ -20,7 +17,6 @@
import org.drools.degrees.factory.IDegreeFactory;
import org.drools.fuzzy.evaluators.membership.INumericSetMembershipFunction;
import org.drools.fuzzy.evaluators.membership.SkepticNumericMembershipFunction;
-import org.drools.reteoo.ImperfectRuleBase;
import org.drools.rule.VariableRestriction.VariableContextEntry;
import org.drools.spi.FieldValue;
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/fuzzy/evaluators/RandomEvaluator.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/fuzzy/evaluators/RandomEvaluator.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/fuzzy/evaluators/RandomEvaluator.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -48,6 +48,9 @@
}
+ public String toString() {
+ return "random";
+ }
@@ -55,7 +58,6 @@
-
public IDegree evaluate(InternalWorkingMemory workingMemory,
IDegreeFactory factory, InternalReadAccessor extractor,
Object object, FieldValue value) {
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/impl/KnowledgeBaseProviderImpl.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/impl/KnowledgeBaseProviderImpl.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/impl/KnowledgeBaseProviderImpl.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -32,15 +32,17 @@
- public KnowledgeBase newKnowledgeBase() {
- System.out.println("WARNING "+this.getClass().getName()+ " HACKED METHOD TO ACTIVATE IMPERFECTION");
- return new KnowledgeBaseImpl( RuleBaseFactory.newRuleBase(RuleBase.IMPERFECT_RETEOO) );
- //return new KnowledgeBaseImpl( RuleBaseFactory.newRuleBase(RuleBase.RETEOO) );
+ public KnowledgeBase newKnowledgeBase() {
+ //return new KnowledgeBaseImpl( RuleBaseFactory.newRuleBase(RuleBase.IMPERFECT_RETEOO) );
+ return new KnowledgeBaseImpl( RuleBaseFactory.newRuleBase(RuleBase.RETEOO) );
}
public KnowledgeBase newKnowledgeBase(KnowledgeBaseConfiguration conf) {
- System.out.println("WARNING "+this.getClass().getName()+ " HACKED METHOD TO ACTIVATE IMPERFECTION");
- return new KnowledgeBaseImpl( RuleBaseFactory.newRuleBase(RuleBase.IMPERFECT_RETEOO, ( RuleBaseConfiguration ) conf ) );
+ System.out.println("WARNING "+this.getClass().getName()+ " HACKED METHOD TO ACTIVATE IMPERFECTION");
+ if (conf.isImperfect()) {
+ return new KnowledgeBaseImpl( RuleBaseFactory.newRuleBase(RuleBase.IMPERFECT_RETEOO, ( RuleBaseConfiguration ) conf ) );
+ } else
+ return new KnowledgeBaseImpl( RuleBaseFactory.newRuleBase(RuleBase.RETEOO, ( RuleBaseConfiguration ) conf ) );
}
public Environment newEnvironment() {
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -122,6 +122,7 @@
for (ConstraintKey key : keys)
context.getRuleBase().getRete().indexGammaNode(key,this);
+
}
@@ -241,8 +242,15 @@
System.out.println("Alpha evaluation trial "+record.expand());
- //Merge is automatical, so now we decide what to do
- switch (this.filterStrat.doTry(record)) {
+ int verdict;
+
+ if (this.constraint.isCutter() && record.getDegree().equals(factory.False()))
+ verdict = IFilterStrategy.DROP;
+ else
+ verdict = this.filterStrat.doTry(record);
+
+
+ switch (verdict) {
case IFilterStrategy.DROP :
//time to die
System.out.println("Alpha FAIL : DROP record");
@@ -277,7 +285,16 @@
public void update(Observable watcher, Object info) {
EvalRecord record = (EvalRecord) watcher;
System.out.println("**************************************************************UPDATE @ALPHA NODE");
- switch (this.filterStrat.doTry(record)) {
+
+ int verdict;
+
+ if (this.constraint.isCutter() && record.getDegree().equals(record.getFactory().False()))
+ verdict = IFilterStrategy.DROP;
+ else
+ verdict = this.filterStrat.doTry(record);
+
+
+ switch (verdict) {
case IFilterStrategy.DROP :
record.deleteObserver(this);
return;
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/AndOperatorInstaller.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/AndOperatorInstaller.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/AndOperatorInstaller.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -1,21 +1,6 @@
package org.drools.reteoo;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-
-
-import org.drools.RuntimeDroolsException;
-import org.drools.common.BaseNode;
-import org.drools.common.InternalWorkingMemory;
-import org.drools.common.PropagationContextImpl;
import org.drools.common.RuleBasePartitionId;
-import org.drools.degrees.factory.IDegreeFactory;
-import org.drools.reteoo.AccumulateNode.AccumulateMemory;
-import org.drools.reteoo.CollectNode.CollectMemory;
-import org.drools.spi.PropagationContext;
-import org.drools.spi.Tuple;
-import org.drools.util.Iterator;
public class AndOperatorInstaller
extends OperatorInstaller
@@ -25,21 +10,11 @@
public AndOperatorInstaller(LeftTupleSource source, int arity, int id, RuleBasePartitionId partitionId, boolean isPartitionEnabled) {
- super(source, arity, id, partitionId, isPartitionEnabled);
+ super(source, arity, id, partitionId, isPartitionEnabled);
+
}
-
-
-
-
-
-
-
-
-
-
-
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ClassObjectTypeConf.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -75,6 +75,12 @@
BuildContext context = new BuildContext( ruleBase,
((ReteooRuleBase) ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator() );
context.setCurrentEntryPoint( entryPoint );
+ if (ruleBase instanceof ImperfectRuleBase) {
+ context.setDependencies(((ImperfectRuleBase) ruleBase).getDependencies());
+ }
+
+
+
if ( DroolsQuery.class == clazz ) {
context.setTupleMemoryEnabled( false );
context.setObjectTypeNodeMemoryEnabled( false );
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeEvaluation.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeEvaluation.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeEvaluation.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -97,10 +97,12 @@
int j = 0;
for (Evaluation eval : getOperands()) {
- args[j++] = eval.getDegree();
+ args[j++] = eval == null ? this.getNullHandlingStrat().convertNull() : eval.getDegree();
}
}
+
+
IDegree opDeg = this.operator.eval(args);
updateOpRate();
boolean newContrib = this.addDegree(Evaluation.EVAL, opDeg, getOpRate(),true);
@@ -154,6 +156,46 @@
//this.setArgCode(this.getArgCode()^operand.getArgCode());
}
+
+
+
+
+ public void removeOperand(int position) {
+ if (position >= 0) {
+
+
+ Evaluation operand = operands.get(position);
+
+ System.out.println("Removing "+operand.expand());
+
+ operand.deleteObserver(this);
+
+ System.out.println(operands.size());
+ operands.set(position,null);
+ System.out.println(operands.size());
+
+ this.getArgs().delete(operand.getArgs());
+
+ }
+
+ int j = operands.size();
+ while (j > 0 && operands.get(j-1) == null)
+ j = j-1;
+
+ operands.setSize(j);
+
+ System.out.println(operands.size());
+ System.out.println();
+
+
+ //this.setArgCode(this.getArgCode()^operand.getArgCode());
+ }
+
+
+
+
+
+
public Collection<Evaluation> getEvalTree() {
Collection<Evaluation> ans = new ArrayList<Evaluation>(2*operands.size());
for (Evaluation eval : operands)
@@ -186,7 +228,7 @@
} else {
float delta = 0;
for (Evaluation child : this.getOperands()) {
- delta += child.getInfoRate();
+ delta += child == null ? 0 : child.getInfoRate();
}
setOpRate(delta / (1.0f*this.operands.size()));
}
@@ -204,7 +246,8 @@
this.notifyObservers(arg);
}
} else {
- boolean newContrib = combine();
+ //boolean newContrib =
+ combine();
}
//this.notifyObservers(this);
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeEvaluationTemplate.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeEvaluationTemplate.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeEvaluationTemplate.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -48,25 +48,29 @@
public Evaluation spawn(Evaluation[] evalDegree) {
- return new CompositeEvaluation(id,key,deps,evalDegree,operator,mergeStrat,nullStrat,new ArgList());
+ return new CompositeEvaluation(id,key.clone(),deps,evalDegree,operator,mergeStrat,nullStrat,new ArgList());
}
public Evaluation spawn(ArgList args) {
- return new CompositeEvaluation(id,key,deps,children.values().toArray(new Evaluation[children.values().size()]),operator,mergeStrat,nullStrat,args);
+ return new CompositeEvaluation(id,key.clone(),deps,children.values().toArray(new Evaluation[children.values().size()]),operator,mergeStrat,nullStrat,args);
}
public Evaluation spawn(int N) {
- return new CompositeEvaluation(id,key,deps,N,operator,mergeStrat,nullStrat,new ArgList());
+ return new CompositeEvaluation(id,key.clone(),deps,N,operator,mergeStrat,nullStrat,new ArgList());
}
public Evaluation spawn(OperandSet args, BetaConstraints joinConstraints) {
- return new SetCompositeEvaluation(id,key,deps,operator,args,mergeStrat,nullStrat,joinConstraints);
+ return new SetCompositeEvaluation(id,key.clone(),deps,operator,args,mergeStrat,nullStrat,joinConstraints);
}
protected IDegreeCombiner getOperator() {
return operator;
}
+
+ public String getOperatorName() {
+ return operator.getName();
+ }
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -112,6 +112,11 @@
doPropagateRetractLeftTuple( context, workingMemory, child, child.getLeftTupleSink() );
child.unlinkFromRightParent();
child.unlinkFromLeftParent();
+
+ System.out.println(this.getClass() + "HACKED TO DETACH RECORD OBSERVER");
+ if (child instanceof ImperfectLeftTuple)
+ ((ImperfectLeftTuple) child).getRecord().deleteObservers();
+
child = temp;
}
}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/DiscountOperatorInstaller.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/DiscountOperatorInstaller.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/DiscountOperatorInstaller.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,20 @@
+package org.drools.reteoo;
+
+import org.drools.common.RuleBasePartitionId;
+
+public class DiscountOperatorInstaller
+ extends OperatorInstaller
+ implements LeftTupleSink {
+
+ protected LeftTupleSource source;
+
+
+ public DiscountOperatorInstaller(LeftTupleSource source, int arity, int id, RuleBasePartitionId partitionId, boolean isPartitionEnabled) {
+ super(source, arity, id, partitionId, isPartitionEnabled);
+
+ }
+
+
+
+
+}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/DoubleMPOperatorInstaller.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/DoubleMPOperatorInstaller.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/DoubleMPOperatorInstaller.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,20 @@
+package org.drools.reteoo;
+
+import org.drools.common.RuleBasePartitionId;
+
+public class DoubleMPOperatorInstaller
+ extends OperatorInstaller
+ implements LeftTupleSink {
+
+ protected LeftTupleSource source;
+
+
+ public DoubleMPOperatorInstaller(LeftTupleSource source, int arity, int id, RuleBasePartitionId partitionId, boolean isPartitionEnabled) {
+ super(source, arity, id, partitionId, isPartitionEnabled);
+
+ }
+
+
+
+
+}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EntryPointNode.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -330,7 +330,7 @@
ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
for ( int i = 0, length = cachedNodes.length; i < length; i++ ) {
- System.out.println(this.getClass() + " dispatching obj to node "+i);
+ System.out.println(this.getClass() + " dispatching obj"+ (handle.getObject().getClass().getSimpleName()) + "to node "+cachedNodes[i].hashCode());
EvalRecord record = new EvalRecord(this.getId(),factory.getAndOperator(),factory.getMergeStrategy(),factory.getNullHandlingStrategy(),new ArgList());
cachedNodes[i].assertObject(handle,
context,
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EqvOperatorInstaller.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EqvOperatorInstaller.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EqvOperatorInstaller.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,33 @@
+package org.drools.reteoo;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+
+import org.drools.RuntimeDroolsException;
+import org.drools.common.BaseNode;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.common.PropagationContextImpl;
+import org.drools.common.RuleBasePartitionId;
+import org.drools.degrees.factory.IDegreeFactory;
+import org.drools.reteoo.AccumulateNode.AccumulateMemory;
+import org.drools.reteoo.CollectNode.CollectMemory;
+import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
+import org.drools.util.Iterator;
+
+public class EqvOperatorInstaller
+ extends OperatorInstaller
+ implements LeftTupleSink {
+
+ protected LeftTupleSource source;
+
+
+ public EqvOperatorInstaller(LeftTupleSource source, int arity, int id, RuleBasePartitionId partitionId, boolean isPartitionEnabled) {
+ super(source, arity, id, partitionId, isPartitionEnabled);
+ }
+
+}
+
+
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EvalRecord.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EvalRecord.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/EvalRecord.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -144,7 +144,8 @@
addedEval.deleteObserver(this);
addedEval.addObserver(this);
- ((DynamicConstraintKey) this.getKey()).addArg(eval.getKey());
+ if (newEval)
+ ((DynamicConstraintKey) this.getKey()).addArg(eval.getKey());
combine();
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/Evaluation.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/Evaluation.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/Evaluation.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -103,9 +103,9 @@
boolean newContrib = false;
for (String source : moreDegrees.keySet()) {
- System.out.println("Trying to merge degrees for source "+ source + "+1");
IDegree evalDeg = moreDegrees.get(source);
- if (evalDeg != null) {
+ if (evalDeg != null) {
+ System.out.println("Trying to merge degrees for source "+ source + "+1");
/*
confidence.put(source, conf.get(source));
@@ -338,6 +338,8 @@
public boolean equals(Object other) {
if (other == null)
return false;
+ if (other == this)
+ return true;
if (other instanceof Evaluation) {
Evaluation otherEv = (Evaluation) other;
return this.key.equals(otherEv.key) && this.args.equals(otherEv.args);
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectAgendaItem.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectAgendaItem.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectAgendaItem.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -1,6 +1,7 @@
package org.drools.reteoo;
import org.drools.common.AgendaItem;
+import org.drools.common.ImperfectAgendaGroup;
import org.drools.degrees.IDegree;
import org.drools.rule.GroupElement;
import org.drools.rule.Rule;
@@ -25,6 +26,38 @@
}
public Evaluation getEvaluation() {
+
return eval;
}
+
+
+ public int hashCode() {
+ return eval.hashCode()^this.getRule().hashCode();
+ }
+
+ public boolean equals(Object other) {
+ if (other == null)
+ return false;
+ if (other == this)
+ return true;
+ if (other instanceof ImperfectAgendaItem) {
+ Evaluation ev1 = this.eval;
+ Evaluation ev2 = ((ImperfectAgendaItem) other).eval;
+ boolean ans = ev1.equals(ev2);
+ return ans && this.getRule().equals(((ImperfectAgendaItem) other).getRule());
+ } else
+ return false;
+
+ }
+
+ public String toString() {
+ return "[Activation rule=" + this.getRule().getName() + ", code =" + this.eval.hashCode() + " degree = " +this.degree + "]";
+ }
+
+ public void remove() {
+ ((ImperfectAgendaGroup) this.getAgendaGroup()).remove(this);
+ }
+
+
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectExistsNode.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectExistsNode.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectExistsNode.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -11,6 +11,7 @@
import org.drools.common.ImperfectFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.common.TupleStartEqualsConstraint;
+import org.drools.degrees.SimpleDegree;
import org.drools.degrees.factory.IDegreeFactory;
import org.drools.degrees.operators.IDegreeCombiner;
import org.drools.degrees.operators.IMergeStrategy;
@@ -93,7 +94,10 @@
PropagationContext propagationContext,
InternalWorkingMemory workingMemory, IDegreeFactory factory,
EvalRecord record) {
+
+
+
final RightTuple rightTuple = new ImperfectRightTuple( factHandle,
this, record );
@@ -168,12 +172,12 @@
RightTupleMemory rtMem = memory.getRightTupleMemory();
- ObservableRightTupleMemoryWrapper wMemory = (ObservableRightTupleMemoryWrapper) rtMem;
+ ObservableRightTupleMemoryWrapper wrappedMemory = (ObservableRightTupleMemoryWrapper) rtMem;
- OperandSet opSet = new OperandSet(leftTuple,wMemory,this.constraints,memory.getContext(),workingMemory,factory);
+ OperandSet opSet = new OperandSet(leftTuple,wrappedMemory,this.constraints,memory.getContext(),workingMemory,factory, sink, this, context);
- EvalRecord mainRecord = leftTuple.getRecord();
+ EvalRecord mainRecord = leftTuple.getRecord().clone();
this.constraints.updateFromTuple( memory.getContext(),
@@ -187,8 +191,13 @@
opSet.addObserver( eval);
+
mainRecord.addEvaluation(eval);
+
+
+
+
System.out.println("Situation at EXISTS eval"+mainRecord.expand());
@@ -197,6 +206,8 @@
case IFilterStrategy.DROP :
// System.out.println("Exist FAIL at assertTuple: DROP record");
// return;
+
+
case IFilterStrategy.HOLD : //TODO: HOLD
System.out.println("HOLD RULES @EXIST NODE"+this.getId());
@@ -212,6 +223,14 @@
case IFilterStrategy.PASS :
System.out.println("Exist PASS at assertTuple: propagate record");
+ mainRecord.setLeftTuple(leftTuple);
+ mainRecord.setFactory(factory);
+ mainRecord.setPropagationContext(context);
+ mainRecord.setWorkingMemory(workingMemory);
+
+ mainRecord.deleteObserver(this);
+
+
this.sink.propagateAssertLeftTuple( leftTuple,
context,
workingMemory,
@@ -256,14 +275,23 @@
case IFilterStrategy.DROP :
// System.out.println("Exist FAIL at assertTuple: DROP record");
// return;
+
+
//
case IFilterStrategy.HOLD : //TODO: HOLD
System.out.println("HOLD RULES @EXIST NODE"+this.getId());
- System.out.println("Situation is "+mainRecord.expand());
+ System.out.println("Situation is "+mainRecord.expand());
+
+
+ mainRecord.addObserver(this);
+
break;
case IFilterStrategy.PASS :
System.out.println("Exist PASS at assertTuple: propagate record");
+
+ mainRecord.deleteObserver(this);
+
this.sink.propagateAssertLeftTuple( mainRecord.getLeftTuple(),
mainRecord.getPropagationContext(),
mainRecord.getWorkingMemory(),
@@ -281,9 +309,24 @@
+ public void retractRightTuple(final RightTuple rightTuple,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+
+
+ final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+// behavior.retractRightTuple( memory.getBehaviorContext(),
+// rightTuple,
+// workingMemory );
+ ObservableRightTupleMemoryWrapper wrapper = ((ObservableRightTupleMemoryWrapper) memory.getRightTupleMemory());
+ wrapper.remove( rightTuple, context);
+
+ }
+
+
public String toString() {
return "[Imp_ExistsNode - " +this.constraints.toString() + "]";
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectRuleBase.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectRuleBase.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ImperfectRuleBase.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -1,5 +1,11 @@
package org.drools.reteoo;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.drools.FactException;
import org.drools.FactHandle;
import org.drools.RuleBaseConfiguration;
@@ -11,6 +17,9 @@
import org.drools.degrees.factory.SimpleDegreeFactory;
import org.drools.degrees.factory.SimpleFuzzyDegreeFactory;
import org.drools.rule.EntryPoint;
+import org.drools.rule.InvalidPatternException;
+import org.drools.rule.Package;
+import org.drools.rule.Rule;
import org.drools.spi.FactHandleFactory;
import org.drools.spi.PropagationContext;
@@ -18,6 +27,7 @@
private IDegreeFactory degreeFactory = null;
+ private Map<ConstraintKey,Set<String>> dependencies = new HashMap<ConstraintKey, Set<String>>();
/**
* Default constructor - for Externalizable. This should never be used by a user, as it
@@ -83,7 +93,7 @@
factHandleFactory
);
- String factoryName = config.getProperty("drools.imperfect.factory");
+ String factoryName = config.getProperty("org.drools.chance.factory");
IDegreeFactory factory = null;
try {
factory = (IDegreeFactory) Class.forName(factoryName).newInstance();
@@ -152,4 +162,18 @@
record);
}
+
+
+ protected synchronized void addRule(final Rule rule) throws InvalidPatternException {
+ // This adds the rule. ReteBuilder has a reference to the WorkingMemories and will propagate any existing facts.
+ super.addRule( rule );
+ for (ConstraintKey key : rule.getDependencies().keySet()) {
+ this.dependencies.put(key,rule.getDependencies().get(key));
+ }
+ }
+
+ public Map<ConstraintKey,Set<String>> getDependencies() {
+ return dependencies;
+ }
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -72,9 +72,11 @@
private GammaMemory gammaMemory;
+ private boolean isCutter;
+
public JoinNode() {
}
@@ -106,6 +108,12 @@
Collection<ConstraintKey> keys = this.constraints.getAllConstraintKeys();
for (ConstraintKey key : keys)
context.getRuleBase().getRete().indexGammaNode(key,this);
+
+ if (context.isCutter()) {
+ this.isCutter = true;
+ context.setCutter(false);
+ }
+ this.isCutter = this.isCutter || this.constraints.isCutter();
}
System.out.println(this.getClass().getName() + "(id "+id+") constructor hacked to add filter strategy");
@@ -114,6 +122,12 @@
}
+
+ public boolean equals(final Object object) {
+ return super.equals(object) &&
+ (this.isCutter == ((JoinNode) object).isCutter);
+ }
+
/**
* Assert a new <code>ReteTuple</code>. The right input of
* <code>FactHandleInput</code>'s is iterated and joins attemped, via the
@@ -195,9 +209,12 @@
if (keys != null) {
// Evaluation evalTest = factHandle.getPropertyDegree(keys[0]);
// if (evalTest == null) {
- Evaluation[] evals = this.constraints.isSatisfiedCachedRight( memory.getContext(),
- leftTuple,
- factory );
+// Evaluation[] evals = this.constraints.isSatisfiedCachedRight( memory.getContext(),
+// leftTuple,
+// factory );
+
+ Evaluation[] evals = this.constraints.isSatisfiedCachedLeft(memory.getContext(), factHandle, factory);
+
//B-constraints are 0 to N
//Each is evaluated and, if it is the first time, added to the object's handle
if (evals != null) {
@@ -239,11 +256,19 @@
System.out.println("Situation at join eval"+mainRecord.expand());
-
- switch (this.filterStrat.doTry(mainRecord)) {
+
+ int verdict;
+
+ if (this.isCutter && mainRecord.getDegree().equals(factory.False()))
+ verdict = IFilterStrategy.DROP;
+ else
+ verdict = this.filterStrat.doTry(mainRecord);
+
+
+ switch (verdict) {
case IFilterStrategy.DROP :
System.out.println("Beta FAIL at assertTuple: DROP record");
- return;
+ continue;
case IFilterStrategy.HOLD : //TODO: HOLD
System.out.println("HOLD RULES @JOIN NODE"+this.getId());
@@ -255,8 +280,8 @@
mainRecord.setPropagationContext(context);
mainRecord.setWorkingMemory(workingMemory);
mainRecord.addObserver(this);
-
- break;
+ continue;
+ //break;
case IFilterStrategy.PASS :
System.out.println("Beta PASS at assertTuple: propagate record");
@@ -268,8 +293,8 @@
mainRecord,
this.tupleMemoryEnabled );
- break;
- default : return;
+ //break;
+ default : continue;
}
@@ -441,7 +466,15 @@
System.out.println("Situation at join eval"+mainRecord.expand());
- switch (this.filterStrat.doTry(mainRecord)) {
+ int verdict;
+
+ if (this.isCutter && mainRecord.getDegree().equals(factory.False()))
+ verdict = IFilterStrategy.DROP;
+ else
+ verdict = this.filterStrat.doTry(mainRecord);
+
+
+ switch (verdict) {
case IFilterStrategy.DROP :
System.out.println("Beta DROP at assertobject");
return;
@@ -497,7 +530,16 @@
return;
System.out.println("**************************************************************UPDATE @JOIN NODE");
- switch (this.filterStrat.doTry(record)) {
+
+ int verdict;
+
+ if (this.isCutter && record.getDegree().equals(record.getFactory().False()))
+ verdict = IFilterStrategy.DROP;
+ else
+ verdict = this.filterStrat.doTry(record);
+
+
+ switch (verdict) {
case IFilterStrategy.DROP :
record.deleteObserver(this);
return;
@@ -560,8 +602,15 @@
behavior.retractRightTuple( memory.getBehaviorContext(),
rightTuple,
workingMemory );
- memory.getRightTupleMemory().remove( rightTuple );
+ RightTupleMemory rtMem = memory.getRightTupleMemory();
+ if (! rtMem.contains(rightTuple))
+ return;
+
+ rtMem.remove( rightTuple );
+ if (rightTuple instanceof ImperfectRightTuple) {
+ ((ImperfectRightTuple) rightTuple).getRecord().deleteObserver(this);
+ }
if ( rightTuple.getBetaChildren() != null ) {
this.sink.propagateRetractRightTuple( rightTuple,
context,
@@ -586,6 +635,11 @@
final InternalWorkingMemory workingMemory) {
final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
memory.getLeftTupleMemory().remove( leftTuple );
+
+ if (leftTuple instanceof ImperfectLeftTuple) {
+ ((ImperfectLeftTuple) leftTuple).getRecord().deleteObserver(this);
+ }
+
if ( leftTuple.getBetaChildren() != null ) {
this.sink.propagateRetractLeftTuple( leftTuple,
context,
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -58,6 +58,8 @@
private ObjectSinkNode nextRightTupleSinkNode;
private boolean leftTupleMemoryEnabled;
+
+ private boolean isCutter = false;
public LeftInputAdapterNode() {
@@ -80,6 +82,10 @@
context.getRuleBase().getConfiguration().isMultithreadEvaluation() );
this.objectSource = source;
this.leftTupleMemoryEnabled = context.isTupleMemoryEnabled();
+ if (context.isCutter()) {
+ this.isCutter = true;
+ context.setCutter(false);
+ }
}
public void readExternal(ObjectInput in) throws IOException,
@@ -157,6 +163,9 @@
EvalRecord record) {
if ( !workingMemory.isSequential() ) {
+ if (isCutter && record.getDegree().equals(factory.False()))
+ return;
+
this.sink.createAndPropagateAssertLeftTuple( factHandle,
context,
workingMemory,
@@ -250,7 +259,7 @@
final LeftInputAdapterNode other = (LeftInputAdapterNode) object;
- return this.objectSource.equals( other.objectSource );
+ return this.objectSource.equals( other.objectSource ) && (this.isCutter == other.isCutter);
}
public Object createMemory(final RuleBaseConfiguration config) {
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ModusPonensNode.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ModusPonensNode.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ModusPonensNode.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -16,16 +16,22 @@
import org.drools.common.InternalWorkingMemory;
import org.drools.degrees.IDegree;
import org.drools.degrees.factory.IDegreeFactory;
+import org.drools.degrees.operators.IDegreeCombiner;
import org.drools.reteoo.builder.BuildContext;
import org.drools.reteoo.filters.IFilterStrategy;
import org.drools.rule.Behavior;
import org.drools.rule.ContextEntry;
+import org.drools.rule.Rule;
import org.drools.spi.PropagationContext;
public class ModusPonensNode extends JoinNode {
+ private IDegreeCombiner mPOperator;
+
+
+
public ModusPonensNode(final int id,
final LeftTupleSource leftInput,
final Behavior[] behaviors,
@@ -39,13 +45,15 @@
behaviors,
context);
- Map<String,String> ruleDetails = context.getRule().getMetaAttributes();
+// Map<String,String> ruleDetails = context.getRule().getMetaAttributes();
- String dstr = ruleDetails.get("degree");
- if (dstr != null)
- ((ImplicationBetaConstraint) this.constraints).setPriorDegree(factory.buildDegree(Float.parseFloat(dstr)));
+ Rule rule = context.getRule();
+
+ String priorStr = rule.getPriorDescription();
+ if (priorStr != null)
+ ((ImplicationBetaConstraint) this.constraints).setPriorDegree(factory.buildDegree(priorStr));
- String fstr = ruleDetails.get("filterStrat");
+ String fstr = rule.getFilterStrategy();
try {
if (fstr != null) {
IFilterStrategy overrideStrat = (IFilterStrategy) Class.forName(fstr).newInstance();
@@ -56,6 +64,7 @@
throw new RuntimeDroolsException(e);
}
+ setMPOperator(factory.getModusPonensOperator(rule.getEntailMode()));
}
@@ -86,9 +95,15 @@
EvalRecord premiseRecord = leftTuple.getRecord();
ContextEntry adHocCtx = new MPContextEntry(leftTuple);
- Evaluation implEval = this.constraints.isSatisfiedCachedRight( new ContextEntry[] {adHocCtx},
- leftTuple,
- factory )[0];
+// Evaluation implEval = this.constraints.isSatisfiedCachedRight( new ContextEntry[] {adHocCtx},
+// leftTuple,
+// factory )[0];
+
+ ImperfectFactHandle handle = new ImperfectFactHandle();
+ ImperfectRightTuple dummyRT = new ImperfectRightTuple(handle,this,null);
+
+ Evaluation implEval = this.constraints.isSatisfiedCachedLeft( new ContextEntry[] {adHocCtx}, handle, factory)[0];
+
ArgList args = leftTuple.getArgList();
Collection<Evaluation> storedEvals = this.getGammaMemory().retrieve(args);
@@ -100,7 +115,7 @@
- EvalRecord mpRecord = new EvalRecord(this.id,factory.getModusPonensOp(),factory.getMergeStrategy(),factory.getNullHandlingStrategy(),new ArgList());
+ EvalRecord mpRecord = new EvalRecord(this.id,getMPOperator(),factory.getMergeStrategy(),factory.getNullHandlingStrategy(),new ArgList());
Evaluation core = premiseRecord.getOperands().iterator().next();
core.deleteObserver(premiseRecord);
mpRecord.addEvaluation(core);
@@ -138,7 +153,8 @@
mpRecord.setWorkingMemory(workingMemory);
- this.sink.propagateAssertLeftTuple( leftTuple,
+ this.sink.propagateAssertLeftTuple( leftTuple,
+ dummyRT,
context,
workingMemory,
factory,
@@ -161,6 +177,16 @@
+ protected IDegreeCombiner getMPOperator() {
+ return mPOperator;
+ }
+
+ protected void setMPOperator(IDegreeCombiner op) {
+ mPOperator = op;
+ }
+
+
+
public void update(Observable watcher, Object info) {
EvalRecord record = null;
@@ -173,7 +199,7 @@
System.out.println("**************************************************************UPDATE @MP NODE");
switch (this.filterStrat.doTry(record)) {
case IFilterStrategy.DROP :
- record.deleteObserver(this);
+ //record.deleteObserver(this);
return;
case IFilterStrategy.HOLD :
@@ -194,7 +220,8 @@
record,
this.tupleMemoryEnabled );
else
- this.sink.propagateAssertLeftTuple( record.getLeftTuple(),
+ this.sink.propagateAssertLeftTuple( record.getLeftTuple(),
+ new ImperfectRightTuple(new ImperfectFactHandle(),this,null),
record.getPropagationContext(),
record.getWorkingMemory(),
record.getFactory(),
@@ -209,6 +236,25 @@
+ public void retractLeftTuple(final LeftTuple leftTuple,
+ final PropagationContext context,
+ final InternalWorkingMemory workingMemory) {
+
+
+/* The child of leftTuple is observed by MP */
+// if (leftTuple instanceof ImperfectLeftTuple) {
+// System.out.println(this.getClass() + "HACKED TO DETACH RECORD OBSERVER");
+// ((ImperfectLeftTuple) leftTuple).getRecord().deleteObserver(this);
+// }
+
+ final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+ memory.getLeftTupleMemory().remove( leftTuple );
+ if ( leftTuple.getBetaChildren() != null ) {
+ this.sink.propagateRetractLeftTuple( leftTuple,
+ context,
+ workingMemory );
+ }
+ }
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -20,7 +20,13 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
+import java.util.Observable;
+import java.util.Observer;
import java.util.Set;
import org.drools.RuleBaseConfiguration;
@@ -37,6 +43,7 @@
import org.drools.degrees.factory.IDegreeFactory;
import org.drools.reteoo.ReteooWorkingMemory.WorkingMemoryReteExpireAction;
import org.drools.reteoo.builder.BuildContext;
+import org.drools.reteoo.filters.IFilterStrategy;
import org.drools.rule.Declaration;
import org.drools.rule.EntryPoint;
import org.drools.rule.EvalCondition;
@@ -75,7 +82,9 @@
implements
ObjectSink,
Externalizable,
- NodeMemory
+ NodeMemory,
+ IGammaNode,
+ Observer
{
// ------------------------------------------------------------
@@ -98,9 +107,17 @@
private transient ExpireJob job = new ExpireJob();
- private EvaluationTemplate template;
+ private EvaluationTemplate template;
+ private GammaMemory gamma;
+
+ private String label;
+ private IFilterStrategy filterStrat;
+
+ private ConstraintKey singletonKey;
+
+
public ObjectTypeNode() {
}
@@ -126,15 +143,67 @@
this.objectType = objectType;
setObjectMemoryEnabled( context.isObjectTypeNodeMemoryEnabled() );
- //TODO:
+
+ }
+
+
+ public void setImperfectStructures(final BuildContext context) {
+ //TODO:
//System.out.println(this.getClass()+" Hacked to add class constraint evaluation");
if (context.getRuleBase() instanceof ImperfectRuleBase) {
IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
- this.template = new SingleEvaluationTemplate(this.getId(),this.getConstraintKey(),new HashSet<String>(),factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+ this.filterStrat = factory.getDefaultStrategy();
+
+ ConstraintKey key = this.getConstraintKey();
+
+
+ this.template = buildEvaluationTemplate(context.getDependencies(),factory);
+ this.gamma = new GammaMemory();
+ context.getRuleBase().getRete().indexGammaNode(key,this);
}
}
- public void readExternal(ObjectInput in) throws IOException,
+ public EvaluationTemplate buildEvaluationTemplate(Map<ConstraintKey,Set<String>> dependencies, IDegreeFactory factory) {
+
+ Set<String> deps;
+
+ String label = this.getLabel();
+ Set<String> aliasedDeps = null;
+ if (dependencies != null && label != null) {
+ ConstraintKey tester = new ConstraintKey();
+ tester.setAlias(label);
+ aliasedDeps = dependencies.remove(tester);
+
+ if (aliasedDeps != null) {
+ ConstraintKey properKey = this.getConstraintKey();
+ Set<String> previousDeps = dependencies.remove(properKey);
+
+ if (previousDeps != null)
+ aliasedDeps.addAll(previousDeps);
+
+ properKey.setAlias(label);
+
+ dependencies.put(properKey, aliasedDeps);
+ }
+ }
+
+
+ if (dependencies == null)
+ deps = Collections.emptySet();
+ else
+ deps = dependencies.get(this.getConstraintKey());
+
+
+ EvaluationTemplate templ = new SingleEvaluationTemplate(
+ this.getId(),
+ getConstraintKey(),
+ deps,
+ factory.getMergeStrategy(),
+ factory.getNullHandlingStrategy());
+ return templ;
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
super.readExternal( in );
objectType = (ObjectType) in.readObject();
@@ -514,11 +583,22 @@
public ConstraintKey getConstraintKey() {
- String cName = ((ClassObjectType) this.objectType).getClassName();
- return new ConstraintKey("class","==",cName);
+ if (singletonKey == null) {
+ String cName = ((ClassObjectType) this.objectType).getClassName();
+ singletonKey = new ConstraintKey("class","==",cName);
+ }
+ return singletonKey;
}
+
+
+
+
+
+
+
+
public void assertObject(ImperfectFactHandle factHandle,
PropagationContext context,
InternalWorkingMemory workingMemory, IDegreeFactory factory,
@@ -529,36 +609,188 @@
// we do this after the shadowproxy update, just so that its up to date for the future
return;
}
+
+ if ( this.objectMemoryEnabled ) {
+ final ObjectHashSet memory = (ObjectHashSet) workingMemory.getNodeMemory( this );
+ memory.add( factHandle,
+ false );
+ }
+
+
+ if (factHandle instanceof InitialFactHandle) {
+ this.sink.propagateAssertObject(factHandle,
+ context,
+ workingMemory,
+ factory,
+ null);
+ return;
+ }
+
//TODO Test for class membership...
ConstraintKey key = getConstraintKey();
+
+ Collection<Evaluation> storedEvals = this.gamma.retrieve(new ArgList(factHandle.getObject()));
+
Evaluation eval = factHandle.getPropertyDegree(key);
if (eval == null) {
- eval = this.template.spawn(factory.True(),new ArgList(factHandle.getObject()));
+ eval = this.template.spawn(storedEvals == null ? factory.True() : factory.False(),new ArgList(factHandle.getObject()));
factHandle.addPropertyDegree(eval);
- }
+ }
+
record.addEvaluation(eval);
+ if (storedEvals != null) {
+ record.addEvaluations(storedEvals);
+ factHandle.addPropertyDegrees(storedEvals);
+ }
- if (factHandle instanceof InitialFactHandle)
- record = null;
+
- if ( this.objectMemoryEnabled ) {
- final ObjectHashSet memory = (ObjectHashSet) workingMemory.getNodeMemory( this );
- memory.add( factHandle,
- false );
- }
- this.sink.propagateAssertObject( factHandle,
- context,
- workingMemory,
- factory,
- record);
-
+
+
+
+
+
+
+ System.out.println("Type evaluation trial "+record.expand());
+
+ int verdict;
+
+ if (record.getDegree().equals(factory.False())) {
+ //TypeNode is implicitly cutter
+ verdict = IFilterStrategy.DROP;
+ } else if (record == null) {
+ //InitialFact is passed
+ verdict = IFilterStrategy.PASS;
+ } else {
+ //Normal test
+ verdict = this.filterStrat.doTry(record);
+ }
+
+ switch (verdict) {
+ case IFilterStrategy.DROP :
+ //time to die
+ System.out.println("Type FAIL : DROP record");
+ return;
+
+ case IFilterStrategy.HOLD :
+ System.out.println("WARNING::::::::::::::::::::::::::: OBJECT HELD AT TYPE NODE "+this.getConstraintKey());
+ System.out.println("Situation is "+record.expand());
+ record.setFactHandle(factHandle);
+ record.setFactory(factory);
+ record.setPropagationContext(context);
+ record.setWorkingMemory(workingMemory);
+ record.addObserver(this);
+ //wait for more1
+ return;
+
+ case IFilterStrategy.PASS :
+ //go on
+ System.out.println("Alpha PASS ");
+ this.sink.propagateAssertObject(factHandle,
+ context,
+ workingMemory,
+ factory,
+ record);
+ break;
+ default : return;
+ }
+
}
+
+ public void update(Observable watcher, Object arg) {
+ EvalRecord record = (EvalRecord) watcher;
+ System.out.println("**************************************************************UPDATE @ALPHA NODE");
+
+ int verdict;
+
+ if (record.getDegree().equals(record.getFactory().False()))
+ verdict = IFilterStrategy.DROP;
+ else
+ verdict = this.filterStrat.doTry(record);
+
+
+ switch (verdict) {
+ case IFilterStrategy.DROP :
+ record.deleteObserver(this);
+ return;
+
+ case IFilterStrategy.HOLD :
+ //do nothing
+ return;
+
+ case IFilterStrategy.PASS :
+ //go on
+ record.deleteObserver(this);
+ //throw new RuntimeException("Awakened objeect");
+ //TODO
+ this.sink.propagateAssertObject(record.getFactHandle(),
+ record.getPropagationContext(),
+ record.getWorkingMemory(),
+ record.getFactory(),
+ record);
+ //break;
+ default : return;
+
+ }
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ public EvaluationTemplate getEvaluationTemplate(ConstraintKey key) {
+ return template;
+ }
+
+ public Collection<Evaluation> getStoredEvals(ArgList args) {
+ return getGammaMemory().retrieve(args);
+ }
+
+ private GammaMemory getGammaMemory() {
+ return gamma;
+ }
+
+ public void storeEvaluation(ArgList args, Evaluation prepareEval) {
+ getGammaMemory().store(args, prepareEval);
+ }
+
+ /**
+ * @param label the label to set
+ */
+ public void setLabel(String label) {
+ this.label = label;
+ this.getConstraintKey().setAlias(label);
+ System.err.println(this.getClass()+" set label "+ label);
+ }
+
+ /**
+ * @return the label
+ */
+ public String getLabel() {
+ return label;
+ }
+
+
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ObservableRightTupleMemoryWrapper.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ObservableRightTupleMemoryWrapper.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/ObservableRightTupleMemoryWrapper.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -7,6 +7,7 @@
import org.drools.FactHandle;
import org.drools.degrees.factory.IDegreeFactory;
+import org.drools.spi.PropagationContext;
import org.drools.util.Iterator;
public class ObservableRightTupleMemoryWrapper extends Observable
@@ -14,7 +15,20 @@
private RightTupleMemory memory;
+ private boolean adding;
+ private boolean removing;
+ private PropagationContext propContext;
+
+ public boolean isAdding() {
+ return adding;
+ }
+
+ public boolean isRemoving() {
+ return removing;
+ }
+
+
public ObservableRightTupleMemoryWrapper(RightTupleMemory wrapped) {
this.memory = wrapped;
}
@@ -51,9 +65,11 @@
public void add(RightTuple rightTuple) {
+ this.adding = true;
memory.add(rightTuple);
- this.setChanged();
- this.notifyObservers(rightTuple);
+ this.setChanged();
+ this.notifyObservers(rightTuple);
+ this.adding = false;
}
public boolean contains(RightTuple rightTuple) {
@@ -77,11 +93,21 @@
}
- public void remove(RightTuple rightTuple) {
+
+ public void remove(RightTuple rightTuple, PropagationContext context) {
+ this.removing = true;
+ this.setPropContext(context);
memory.remove(rightTuple);
- this.setChanged();
- this.notifyObservers(rightTuple);
+ this.setChanged();
+ this.notifyObservers(rightTuple);
+ this.removing = false;
+ this.setPropContext(null);
}
+
+ public void remove(RightTuple rightTuple) {
+ this.remove(rightTuple, null);
+ }
+
public int size() {
return memory.size();
@@ -89,6 +115,22 @@
+ /**
+ * @param propContext the propContext to set
+ */
+ public void setPropContext(PropagationContext propContext) {
+ this.propContext = propContext;
+ }
+
+ /**
+ * @return the propContext
+ */
+ public PropagationContext getPropContext() {
+ return propContext;
+ }
+
+
+
class HandleIterator implements java.util.Iterator<FactHandle> {
private Iterator iterator;
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/OperandSet.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/OperandSet.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/OperandSet.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -14,20 +14,39 @@
import org.drools.degrees.factory.IDegreeFactory;
import org.drools.rule.ContextEntry;
import org.drools.runtime.rule.WorkingMemory;
+import org.drools.spi.PropagationContext;
public class OperandSet extends Observable implements Observer {
private ObservableRightTupleMemoryWrapper memory;
- private ContextEntry[] context;
+ private ContextEntry context[];
private IDegreeFactory factory;
- private LeftTuple tuple;
+ private ImperfectLeftTuple tuple;
private InternalWorkingMemory workMem;
+ private LeftTupleSinkPropagator sink;
+ private PropagationContext propContext;
+ private ImperfectExistsNode node;
+
private BetaConstraints joinConstraints;
- public OperandSet(LeftTuple lTuple, ObservableRightTupleMemoryWrapper mem, BetaConstraints constraints, ContextEntry[] context, InternalWorkingMemory wmem, IDegreeFactory factory) {
+ private boolean adding;
+ private boolean removing;
+
+
+ public boolean isAdding() {
+ return adding;
+ }
+
+ public boolean isRemoving() {
+ return removing;
+ }
+
+
+
+ public OperandSet(ImperfectLeftTuple lTuple, ObservableRightTupleMemoryWrapper mem, BetaConstraints constraints, ContextEntry[] context, InternalWorkingMemory wmem, IDegreeFactory factory, LeftTupleSinkPropagator sink, ImperfectExistsNode node, PropagationContext pCtx) {
this.tuple = lTuple;
this.memory = mem;
this.memory.addObserver(this);
@@ -35,6 +54,10 @@
this.context = context;
this.joinConstraints = constraints;
this.workMem = wmem;
+ this.sink = sink;
+
+ this.node = node;
+ this.propContext = pCtx;
}
public LinkedList<Evaluation> getEvaluations() {
@@ -63,34 +86,118 @@
- public void update(Observable arg0, Object newArg) {
+ public void update(Observable sender, Object newArg) {
+ ImperfectRightTuple impRT;
- if (newArg instanceof ImperfectRightTuple) {
- ImperfectRightTuple impRT = (ImperfectRightTuple) newArg;
- EvalRecord record = impRT.getRecord().clone();
+ if (sender instanceof ObservableRightTupleMemoryWrapper) {
- joinConstraints.updateFromTuple(getContext(), workMem, tuple);
- if (! (joinConstraints instanceof EmptyBetaConstraints)) {
- Evaluation[] newEvals = joinConstraints.isSatisfiedCachedRight(context, tuple, factory);
- for (Evaluation newEv : newEvals) {
- if (! newEv.getKey().toString().equals("starts(tuple,...)"))
- record.addEvaluation(newEv);
- }
- }
- joinConstraints.resetTuple(getContext());
-
- this.setChanged();
- this.notifyObservers(record);
-
+ ObservableRightTupleMemoryWrapper wrapper = (ObservableRightTupleMemoryWrapper) sender;
+ if (newArg instanceof ImperfectRightTuple) {
+ impRT = (ImperfectRightTuple) newArg;
+
+ if (wrapper.isAdding()) {
+ this.adding = true;
- } else {
-
+
+ EvalRecord record = impRT.getRecord().clone();
- }
+
+
+ joinConstraints.updateFromTuple(getContext(), workMem, tuple);
+ if (! (joinConstraints instanceof EmptyBetaConstraints)) {
+ Evaluation[] newEvals = joinConstraints.isSatisfiedCachedRight(context, tuple, factory);
+ for (Evaluation newEv : newEvals) {
+ if (! newEv.getKey().toString().equals("starts(tuple,...)"))
+ record.addEvaluation(newEv);
+ }
+ }
+ joinConstraints.resetTuple(getContext());
+
+ this.setChanged();
+ this.notifyObservers(record);
+
+
+ this.adding = false;
+
+ } else if (wrapper.isRemoving()) {
+ this.removing = true;
+
+ impRT = ((ImperfectRightTuple) newArg);
+
+
+ if (wrapper.size() == 0) {
+
+
+ this.setChanged();
+ this.notifyObservers(impRT.getRecord());
+
+ this.deleteObservers();
+
+
+
+ if ( tuple.getBetaChildren() != null ) {
+ this.sink.propagateRetractLeftTuple( tuple,
+ wrapper.getPropContext(),
+ workMem );
+ System.out.println("Killed children");
+ }
+
+
+
+
+
+
+ this.removing = false;
+
+
+
+ // Now regenerate the tuple for a new prop...
+ EvalRecord mainRecord = ((ImperfectLeftTuple) tuple).getRecord();
+ EvalRecord propRecord = mainRecord.clone();
+
+ SetCompositeEvaluation newEval = (SetCompositeEvaluation) node.template.spawn(this,node.constraints);
+ propRecord.addEvaluation(newEval);
+ this.addObserver(newEval);
+
+ propRecord.setLeftTuple(tuple);
+ propRecord.setFactory(factory);
+ propRecord.setPropagationContext(propContext);
+ propRecord.setWorkingMemory(workMem);
+
+ node.update(this,propRecord);
+
+ System.out.println();
+
+
+
+ } else {
+
+ this.setChanged();
+ this.notifyObservers(impRT.getRecord());
+
+ this.removing = false;
+ }
+
+
+
+
+
+ }
+
+ } else {
+
+
+ }
+ }
}
+ public String toString() {
+ return "OpSet " + size();
+ }
+
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/OperatorInstaller.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/OperatorInstaller.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/OperatorInstaller.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -24,16 +24,26 @@
import org.drools.spi.Tuple;
import org.drools.util.Iterator;
-public abstract class OperatorInstaller
- extends LeftTupleSource
- implements LeftTupleSink {
+public class OperatorInstaller
+ extends LeftTupleSource
+ implements LeftTupleSinkNode {
protected LeftTupleSource source;
protected int arity;
private CompositeEvaluationTemplate template;
+
+
+ private LeftTupleSinkNode previousTupleSinkNode;
+ private LeftTupleSinkNode nextTupleSinkNode;
+ private ObjectSinkNode previousObjectSinkNode;
+ private ObjectSinkNode nextObjectSinkNode;
+
+
+
+
public OperatorInstaller(LeftTupleSource source, int arity, int id, RuleBasePartitionId partitionId, boolean isPartitionEnabled) {
super(id, partitionId, isPartitionEnabled);
this.arity = arity;
@@ -153,7 +163,7 @@
workingMemory,
factory,
record,
- false);
+ true);
}
@@ -171,9 +181,8 @@
}
public void retractLeftTuple(LeftTuple leftTuple,
- PropagationContext context, InternalWorkingMemory workingMemory) {
- //TODO
- //Nothing to do yet
+ PropagationContext context, InternalWorkingMemory workingMemory) {
+ this.sink.propagateRetractLeftTuple(leftTuple, context, workingMemory);
}
public void setLeftTupleMemoryEnabled(boolean tupleMemoryEnabled) {
@@ -189,5 +198,57 @@
public LeftTupleSource getParentSource() {
return this.source;
}
+
+
+
+
+
+
+
+
+ /**
+ * Returns the next node
+ * @return
+ * The next TupleSinkNode
+ */
+ public LeftTupleSinkNode getNextLeftTupleSinkNode() {
+ return this.nextTupleSinkNode;
+ }
+
+ /**
+ * Sets the next node
+ * @param next
+ * The next TupleSinkNode
+ */
+ public void setNextLeftTupleSinkNode(final LeftTupleSinkNode next) {
+ this.nextTupleSinkNode = next;
+ }
+
+ /**
+ * Returns the previous node
+ * @return
+ * The previous TupleSinkNode
+ */
+ public LeftTupleSinkNode getPreviousLeftTupleSinkNode() {
+ return this.previousTupleSinkNode;
+ }
+
+ /**
+ * Sets the previous node
+ * @param previous
+ * The previous TupleSinkNode
+ */
+ public void setPreviousLeftTupleSinkNode(final LeftTupleSinkNode previous) {
+ this.previousTupleSinkNode = previous;
+ }
+
+
+
+
+
+
+
+
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/Rete.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/Rete.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/Rete.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
+import org.drools.RuntimeDroolsException;
import org.drools.common.BaseNode;
import org.drools.common.DroolsObjectInputStream;
import org.drools.common.ImperfectFactHandle;
@@ -76,7 +77,10 @@
private transient InternalRuleBase ruleBase;
- private Map<ConstraintKey,IGammaNode> constraintIndex;
+ private Map<ConstraintKey,IGammaNode> constraintIndex = new HashMap<ConstraintKey, IGammaNode>();
+
+ private Map<String, ConstraintKey> constraintIds = new HashMap<String, ConstraintKey>();
+
public Rete() {
this( null );
@@ -90,9 +94,7 @@
super( 0, RuleBasePartitionId.MAIN_PARTITION, ruleBase != null ? ruleBase.getConfiguration().isMultithreadEvaluation() : false );
this.entryPoints = Collections.synchronizedMap( new HashMap<EntryPoint, EntryPointNode>() );
this.ruleBase = ruleBase;
-
- this.constraintIndex = new HashMap<ConstraintKey, IGammaNode>();
-
+
}
// ------------------------------------------------------------
@@ -276,7 +278,15 @@
public void indexGammaNode(ConstraintKey key, IGammaNode node) {
- this.constraintIndex.put(key, node);
+ if (! constraintIndex.containsKey(key)) {
+ this.constraintIndex.put(key, node);
+
+ this.constraintIds.put(key.getAlias(), key);
+ }
+ else {
+ if (! node.equals(constraintIndex.get(key)))
+ throw new RuntimeDroolsException("Found duplicate key: this may be a know issue");
+ }
}
public IGammaNode getNode(ConstraintKey key) {
@@ -287,6 +297,16 @@
public ConstraintKey getConstraintKey() {
return new ConstraintKey("RETE");
}
+
+ public ConstraintKey retrieveKeyForId(String id) {
+ return this.constraintIds.get(id);
+ }
+ public void storeKeyId(String id, ConstraintKey key) {
+ if (this.constraintIds.containsKey(id))
+ throw new RuntimeDroolsException("Duplicate identifier found "+id);
+ this.constraintIds.put(id, key);
+ }
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -316,6 +316,9 @@
final Activation activation = leftTuple.getActivation();
+
+
+
// activation can be null if the LeftTuple previous propagated into a no-loop
if ( activation == null ) {
return;
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/SetCompositeEvaluation.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/SetCompositeEvaluation.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/SetCompositeEvaluation.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -83,35 +83,56 @@
- public void update(Observable o, Object arg) {
- System.out.println("UPDATE HAS BEEN CALLED ON SETVAL by "+ o.toString());
+ public void update(Observable source, Object arg) {
+ System.out.println("UPDATE HAS BEEN CALLED ON SETVAL by "+ source.toString());
- if (arg instanceof EvalRecord) {
+
+ if (arg instanceof EvalRecord && source instanceof OperandSet) {
+
+ OperandSet wrapper = (OperandSet) source;
Evaluation eval = (Evaluation) arg;
- System.out.println(eval.expand());
-
-
- if (! this.operands.contains(eval)) {
- //this.operands.add(impRT.getRecord());
+ if (wrapper.isAdding()) {
- setOperand(this.operands.size(), eval);
- System.out.println(eval.expand());
+ System.out.println(eval.expand());
+
+
+ if (! this.operands.contains(eval)) {
+ //this.operands.add(impRT.getRecord());
+
+ setOperand(this.operands.size(), eval);
+ System.out.println(eval.expand());
+
+ //Just to notify the new arg...
+ //setChanged();
+ //this.notifyObservers(eval.getArgs());
+ }
+
+ //
+
+
+ System.out.println(eval.expand());
+ combine();
+
+ System.out.println();
+// setChanged();
+// this.notifyObservers();
+
+ } else if (wrapper.isRemoving()) {
+
+ int idx = this.operands.indexOf(eval);
+ removeOperand(idx);
+ combine();
+
+// setChanged();
+// this.notifyObservers(eval);
- //Just to notify the new arg...
- setChanged();
- this.notifyObservers(eval.getArgs());
}
- //
+ } else if (arg instanceof ArgList) {
+ this.getArgs().merge((ArgList) arg);
- System.out.println(eval.expand());
- combine();
-// setChanged();
-// this.notifyObservers();
- } else if (arg instanceof ArgList) {
- this.getArgs().merge((ArgList) arg);
} else {
throw new RuntimeDroolsException("Only Records & Args accepted by quantifiers, so far. received "+arg.getClass());
@@ -121,10 +142,34 @@
}
+ public int hashCode() {
+ return this.getKey().hashCode();
+ }
+ public boolean equals(Object other) {
+ if (other == null)
+ return false;
+ else if (other == this)
+ return true;
+ else if (other instanceof SetCompositeEvaluation) {
+ SetCompositeEvaluation sce = (SetCompositeEvaluation) other;
+ boolean ans = true;
+ ans = ans && this.getKey().equals(sce.getKey());
+ if (this.operands.size() > 0 && sce.operands.size() > 0) {
+ Evaluation ev1 = this.operands.get(0);
+ Evaluation ev2 = sce.operands.get(0);
+ if (ev1 == null || ev2 == null)
+ return false;
+
+ return ans && ev1.getKey().equals(ev2.getKey());
+ } else {
+ return false;
+ }
+ } else
+ return false;
+ }
-
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -71,7 +71,12 @@
LeftTuple temp = child.getLeftParentNext();
doPropagateRetractLeftTuple( context, workingMemory, child, child.getLeftTupleSink() );
child.unlinkFromRightParent();
- child.unlinkFromLeftParent();
+ child.unlinkFromLeftParent();
+
+ System.out.println(this.getClass() + "HACKED TO DETACH RECORD OBSERVER");
+ if (child instanceof ImperfectLeftTuple)
+ ((ImperfectLeftTuple) child).getRecord().deleteObservers();
+
child = temp;
}
}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/XorOperatorInstaller.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/XorOperatorInstaller.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/XorOperatorInstaller.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,33 @@
+package org.drools.reteoo;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+
+import org.drools.RuntimeDroolsException;
+import org.drools.common.BaseNode;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.common.PropagationContextImpl;
+import org.drools.common.RuleBasePartitionId;
+import org.drools.degrees.factory.IDegreeFactory;
+import org.drools.reteoo.AccumulateNode.AccumulateMemory;
+import org.drools.reteoo.CollectNode.CollectMemory;
+import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
+import org.drools.util.Iterator;
+
+public class XorOperatorInstaller
+ extends OperatorInstaller
+ implements LeftTupleSink {
+
+ protected LeftTupleSource source;
+
+
+ public XorOperatorInstaller(LeftTupleSource source, int arity, int id, RuleBasePartitionId partitionId, boolean isPartitionEnabled) {
+ super(source, arity, id, partitionId, isPartitionEnabled);
+ }
+
+
+}
+
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -102,9 +102,11 @@
private boolean negated;
+ private boolean cutter = false;
+
private Map<ConstraintKey,Set<String>> dependencies;
@@ -481,4 +483,18 @@
return dependencies;
}
+ /**
+ * @param cutter the cutter to set
+ */
+ public void setCutter(boolean cutter) {
+ this.cutter = cutter;
+ }
+
+ /**
+ * @return the cutter
+ */
+ public boolean isCutter() {
+ return cutter;
+ }
+
}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectForAnyBuilder.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectForAnyBuilder.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectForAnyBuilder.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,72 @@
+package org.drools.reteoo.builder;
+
+import java.util.Iterator;
+
+import org.drools.reteoo.builder.BuildContext;
+import org.drools.reteoo.builder.BuildUtils;
+import org.drools.reteoo.builder.ReteooComponentBuilder;
+import org.drools.rule.Forall;
+import org.drools.rule.Forany;
+import org.drools.rule.GroupElement;
+import org.drools.rule.GroupElementFactory;
+import org.drools.rule.Pattern;
+import org.drools.rule.RuleConditionElement;
+
+public class ImperfectForAnyBuilder implements ReteooComponentBuilder {
+ /**
+ * @inheritDoc
+ */
+ public void build(final BuildContext context,
+ final BuildUtils utils,
+ final RuleConditionElement rce) {
+ final Forany forany = (Forany) rce;
+
+ // forany can be translated into
+ // Average* { Discount ( << integrand, constraint >> , weight) }
+ // so we just do that:
+
+
+ RuleConditionElement temp = forany.getIntegrand();
+ if (forany.getConstraint() != null) {
+ GroupElement dmp = GroupElementFactory.newDblMPInstance();
+ dmp.addChild(forany.getIntegrand());
+ dmp.addChild(forany.getConstraint());
+ temp = dmp;
+ }
+
+ if (forany.getWeight() != null) {
+ GroupElement dsc = GroupElementFactory.newDiscountInstance();
+ dsc.addChild(temp);
+ dsc.addChild(forany.getWeight());
+ temp = dsc;
+ }
+
+
+ GroupElement avg = GroupElementFactory.newAvgInstance();
+ avg.addChild(temp);
+
+
+ // get builder for the CEs
+ final ReteooComponentBuilder builder = utils.getBuilderFor( avg );
+
+ // builds the CEs
+ builder.build( context,
+ utils,
+ avg );
+ }
+
+
+
+
+
+
+
+ /**
+ * @inheritDoc
+ */
+ public boolean requiresLeftActivation(final BuildUtils utils,
+ final RuleConditionElement rce) {
+ return true;
+ }
+
+}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectForallBuilder.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectForallBuilder.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectForallBuilder.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -68,21 +68,20 @@
} else if ( forall.getRemainingPatterns().size() > 1 ) {
- and.addChild(base);
-
-
- for ( final Iterator it = forall.getRemainingPatterns().iterator(); it.hasNext(); ) {
- andInner.addChild( (Pattern) it.next() );
- }
-
- existsInner.addChild( andInner );
- notInner.addChild(existsInner);
- and.addChild(notInner);
+// and.addChild(base);
+//
+//
+// for ( final Iterator it = forall.getRemainingPatterns().iterator(); it.hasNext(); ) {
+// andInner.addChild( (Pattern) it.next() );
+// }
+//
+// existsInner.addChild( andInner );
+// notInner.addChild(existsInner);
+// and.addChild(notInner);
+//
+// exists.addChild(and);
- exists.addChild(and);
-
- /*
and.addChild(base);
for ( final Iterator it = forall.getRemainingPatterns().iterator(); it.hasNext(); ) {
and.addChild( (Pattern) it.next() );
@@ -90,7 +89,7 @@
notInner.addChild(and);
exists.addChild(notInner);
- */
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectGroupElementBuilder.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectGroupElementBuilder.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectGroupElementBuilder.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -17,6 +17,9 @@
import org.drools.degrees.operators.IDegreeCombiner;
import org.drools.degrees.operators.NegationOperator;
import org.drools.reteoo.AndOperatorInstaller;
+import org.drools.reteoo.DiscountOperatorInstaller;
+import org.drools.reteoo.DoubleMPOperatorInstaller;
+import org.drools.reteoo.EqvOperatorInstaller;
import org.drools.reteoo.ExistsNode;
import org.drools.reteoo.ImperfectExistsNode;
import org.drools.reteoo.ImperfectRuleBase;
@@ -28,6 +31,7 @@
import org.drools.reteoo.OperatorInstaller;
import org.drools.reteoo.OrOperatorInstaller;
import org.drools.reteoo.RightInputAdapterNode;
+import org.drools.reteoo.XorOperatorInstaller;
import org.drools.rule.Behavior;
import org.drools.rule.GroupElement;
import org.drools.rule.Pattern;
@@ -49,8 +53,32 @@
new ImperfectOrBuilder() );
this.getGeBuilders().put( GroupElement.NOT,
new ImperfectNotBuilder() );
+
+ this.getGeBuilders().put( GroupElement.XOR,
+ new ImperfectXorBuilder() );
+
+ this.getGeBuilders().put( GroupElement.EQV,
+ new ImperfectEqvBuilder() );
+
this.getGeBuilders().put( GroupElement.EXISTS,
new ImperfectExistsBuilder() );
+
+// this.getGeBuilders().put( GroupElement.FORANY,
+// new ImperfectForAnyBuilder() );
+
+ this.getGeBuilders().put( GroupElement.AVG,
+ new ImperfectForAnyNodeBuilder() );
+
+ this.getGeBuilders().put( GroupElement.DISC,
+ new ImperfectDiscountBuilder() );
+
+ this.getGeBuilders().put( GroupElement.DMP,
+ new ImperfectDoubleMPBuilder() );
+
+ this.getGeBuilders().put( GroupElement.HEDGE,
+ new ImperfectHedgeBuilder() );
+
+
}
@@ -60,235 +88,448 @@
+ private abstract static class ImperfectOperatorArgsBuilder
+ implements
+ ReteooComponentBuilder {
+
+ protected abstract IDegreeCombiner getOperator(IDegreeFactory factory, String params);
-
+ /**
+ * @inheritDoc
+ *
+ * And group elements just iterate over their children
+ * selecting and calling the build procedure for each one
+ *
+ */
+ public void build(final BuildContext context,
+ final BuildUtils utils,
+ final RuleConditionElement rce) {
- private static class ImperfectAndBuilder
- implements
- ReteooComponentBuilder {
-
- /**
- * @inheritDoc
- *
- * And group elements just iterate over their children
- * selecting and calling the build procedure for each one
- *
- */
- public void build(final BuildContext context,
- final BuildUtils utils,
- final RuleConditionElement rce) {
-
+
+ final GroupElement ge = (GroupElement) rce;
+
+
+
+
+ IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
+
+ IDegreeCombiner operator;
+ if (context.isNegated()) {
+ operator = factory.getNegationOperator();
+ ((NegationOperator) operator).setOperator(getOperator(factory, ge.getParam()));
+ context.toggleNegated();
-
- IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
-
- IDegreeCombiner operator;
- if (context.isNegated()) {
- operator = factory.getNegationOperator();
- ((NegationOperator) operator).setOperator(factory.getAndOperator());
- context.toggleNegated();
-
- } else {
- operator = factory.getAndOperator();
- }
-
-
- final GroupElement ge = (GroupElement) rce;
+ } else {
+ operator = getOperator(factory, ge.getParam());
+ }
+
+
+
- // iterate over each child and build it
- for ( final Iterator it = ge.getChildren().iterator(); it.hasNext(); ) {
+ // iterate over each child and build it
+ for ( final Iterator it = ge.getChildren().iterator(); it.hasNext(); ) {
- final RuleConditionElement child = (RuleConditionElement) it.next();
+ final RuleConditionElement child = (RuleConditionElement) it.next();
- final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+ final ReteooComponentBuilder builder = utils.getBuilderFor( child );
- builder.build( context,
- utils,
- child );
+ builder.build( context,
+ utils,
+ child );
+
+ if (child.isCutter()) {
+ context.setCutter(true);
+ }
+
+
+ // if a previous object source was bound, but no tuple source
+ if ( context.getObjectSource() != null && context.getTupleSource() == null ) {
+ // adapt it to a Tuple source
+ context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+ new LeftInputAdapterNode( context.getNextId(),
+ context.getObjectSource(),
+ context ) ) );
- // if a previous object source was bound, but no tuple source
- if ( context.getObjectSource() != null && context.getTupleSource() == null ) {
- // adapt it to a Tuple source
- context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
- new LeftInputAdapterNode( context.getNextId(),
- context.getObjectSource(),
- context ) ) );
+ context.setObjectSource( null );
+ }
- context.setObjectSource( null );
- }
+ // if there was a previous tuple source, then a join node is needed
+ if ( context.getObjectSource() != null && context.getTupleSource() != null ) {
+ // so, create the tuple source and clean up the constraints and object source
+ final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
+ context.getBetaconstraints(),
+ false );
- // if there was a previous tuple source, then a join node is needed
- if ( context.getObjectSource() != null && context.getTupleSource() != null ) {
- // so, create the tuple source and clean up the constraints and object source
- final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
- context.getBetaconstraints(),
- false );
+ Behavior[] behaviors = createBehaviorArray( context );
- Behavior[] behaviors = createBehaviorArray( context );
-
- context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
- new JoinNode( context.getNextId(),
- context.getTupleSource(),
- context.getObjectSource(),
- betaConstraints,
- behaviors,
- context ) ) );
- context.setBetaconstraints( null );
- context.setObjectSource( null );
- }
+
+ JoinNode joinNode = new JoinNode( context.getNextId(),
+ context.getTupleSource(),
+ context.getObjectSource(),
+ betaConstraints,
+ behaviors,
+ context );
+
+ context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+ joinNode ) );
+ context.setBetaconstraints( null );
+ context.setObjectSource( null );
}
-
- int arity = ge.getChildren().size();
- Object firstChild = ge.getChildren().get(0);
- if (firstChild instanceof Pattern) {
- Pattern pat = (Pattern) firstChild;
- if (pat.getObjectType().isAssignableFrom(new ClassObjectType(InitialFact.class)))
- arity--;
- }
-// if (firstChild.isPatternScopeDelimiter())
-// ;
-
- OperatorInstaller instNode = new AndOperatorInstaller(
- context.getTupleSource(),
- arity,
- context.getNextId(),
- context.getPartitionId(),
- context.getRuleBase().getConfiguration().isMultithreadEvaluation());
-
-
- instNode.buildEvaluationTemplate(operator,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
-
- context.setTupleSource((LeftTupleSource) utils.attachNode(
- context,
- instNode
- ));
-
-
-
}
+
+ int arity = ge.getChildren().size();
+ Object firstChild = ge.getChildren().get(0);
+ if (firstChild instanceof Pattern) {
+ Pattern pat = (Pattern) firstChild;
+ if (pat.getObjectType().isAssignableFrom(new ClassObjectType(InitialFact.class)))
+ arity--;
+ }
+// if (firstChild.isPatternScopeDelimiter())
+// ;
+
+ OperatorInstaller instNode = new OperatorInstaller(
+ context.getTupleSource(),
+ arity,
+ context.getNextId(),
+ context.getPartitionId(),
+ context.getRuleBase().getConfiguration().isMultithreadEvaluation());
+
+
+ instNode.buildEvaluationTemplate(operator,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+
+ context.setTupleSource((LeftTupleSource) utils.attachNode(
+ context,
+ instNode
+ ));
+
+
+
+ }
- public boolean requiresLeftActivation(final BuildUtils utils,
- final RuleConditionElement rce) {
- final GroupElement and = (GroupElement) rce;
+ public boolean requiresLeftActivation(final BuildUtils utils,
+ final RuleConditionElement rce) {
+ final GroupElement and = (GroupElement) rce;
- // need to check this because in the case of an empty rule, the root AND
- // will have no child
- if ( and.getChildren().isEmpty() ) {
- return true;
- }
+ // need to check this because in the case of an empty rule, the root AND
+ // will have no child
+ if ( and.getChildren().isEmpty() ) {
+ return true;
+ }
- final RuleConditionElement child = (RuleConditionElement) and.getChildren().get( 0 );
- final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+ final RuleConditionElement child = (RuleConditionElement) and.getChildren().get( 0 );
+ final ReteooComponentBuilder builder = utils.getBuilderFor( child );
- return builder.requiresLeftActivation( utils,
- child );
- }
+ return builder.requiresLeftActivation( utils,
+ child );
}
+}
+
- private static class ImperfectOrBuilder
- implements
- ReteooComponentBuilder {
+
+
+ private static class ImperfectAndBuilder extends ImperfectOperatorArgsBuilder {
+ @Override
+ protected IDegreeCombiner getOperator(IDegreeFactory factory, String params) {
+ if (params == null)
+ return factory.getAndOperator();
+ else
+ return factory.getAndOperator(params);
+ }
+ }
+
+ private static class ImperfectOrBuilder extends ImperfectOperatorArgsBuilder {
+ @Override
+ protected IDegreeCombiner getOperator(IDegreeFactory factory, String params) {
+ if (params == null)
+ return factory.getOrOperator();
+ else
+ return factory.getOrOperator(params);
+ }
+ }
+
+ private static class ImperfectXorBuilder extends ImperfectOperatorArgsBuilder {
+ @Override
+ protected IDegreeCombiner getOperator(IDegreeFactory factory, String params) {
+ if (params == null)
+ return factory.getXorOperator();
+ else
+ return factory.getXorOperator(params);
+ }
+ }
+
+ private static class ImperfectEqvBuilder extends ImperfectOperatorArgsBuilder {
+ @Override
+ protected IDegreeCombiner getOperator(IDegreeFactory factory, String params) {
+ if (params == null)
+ return factory.getEquivOperator();
+ else
+ return factory.getEquivOperator(params);
+ }
+ }
+
+ private static class ImperfectDiscountBuilder extends ImperfectOperatorArgsBuilder {
+ @Override
+ protected IDegreeCombiner getOperator(IDegreeFactory factory, String params) {
+ if (params == null)
+ return factory.getDiscountOperator();
+ else
+ return factory.getDiscountOperator(params);
+ }
+ }
+
+
+ private static class ImperfectDoubleMPBuilder extends ImperfectOperatorArgsBuilder {
+ @Override
+ protected IDegreeCombiner getOperator(IDegreeFactory factory, String params) {
+ if (params == null)
+ return factory.getDoubleMPOperator();
+ else
+ return factory.getDoubleMPOperator(params);
+ }
+ }
+//
+
-
-
- public void build(final BuildContext context,
- final BuildUtils utils,
- final RuleConditionElement rce) {
-
- IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
-
- IDegreeCombiner operator;
- if (context.isNegated()) {
- operator = factory.getNegationOperator();
- ((NegationOperator) operator).setOperator(factory.getOrOperator());
- context.toggleNegated();
-
- } else {
- operator = factory.getOrOperator();
- }
-
+ private static class ImperfectHedgeBuilder extends ImperfectOperatorArgsBuilder {
+ @Override
+ protected IDegreeCombiner getOperator(IDegreeFactory factory, String params) {
+ if (params == null)
+ return factory.getHedgeOperator();
+ else
+ return factory.getHedgeOperator(params);
+ }
+ }
- final GroupElement ge = (GroupElement) rce;
+
+
+
+//
+// private static class ImperfectAndBuilder
+// implements
+// ReteooComponentBuilder {
+//
+// /**
+// * @inheritDoc
+// *
+// * And group elements just iterate over their children
+// * selecting and calling the build procedure for each one
+// *
+// */
+// public void build(final BuildContext context,
+// final BuildUtils utils,
+// final RuleConditionElement rce) {
+//
+//
+//
+// IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
+//
+// IDegreeCombiner operator;
+// if (context.isNegated()) {
+// operator = factory.getNegationOperator();
+// ((NegationOperator) operator).setOperator(factory.getAndOperator());
+// context.toggleNegated();
+//
+// } else {
+// operator = factory.getAndOperator();
+// }
+//
+//
+// final GroupElement ge = (GroupElement) rce;
+//
+// // iterate over each child and build it
+// for ( final Iterator it = ge.getChildren().iterator(); it.hasNext(); ) {
+//
+// final RuleConditionElement child = (RuleConditionElement) it.next();
+//
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// builder.build( context,
+// utils,
+// child );
+//
+// // if a previous object source was bound, but no tuple source
+// if ( context.getObjectSource() != null && context.getTupleSource() == null ) {
+// // adapt it to a Tuple source
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new LeftInputAdapterNode( context.getNextId(),
+// context.getObjectSource(),
+// context ) ) );
+//
+// context.setObjectSource( null );
+// }
+//
+// // if there was a previous tuple source, then a join node is needed
+// if ( context.getObjectSource() != null && context.getTupleSource() != null ) {
+// // so, create the tuple source and clean up the constraints and object source
+// final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
+// context.getBetaconstraints(),
+// false );
+//
+// Behavior[] behaviors = createBehaviorArray( context );
+//
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new JoinNode( context.getNextId(),
+// context.getTupleSource(),
+// context.getObjectSource(),
+// betaConstraints,
+// behaviors,
+// context ) ) );
+// context.setBetaconstraints( null );
+// context.setObjectSource( null );
+// }
+// }
+//
+// int arity = ge.getChildren().size();
+// Object firstChild = ge.getChildren().get(0);
+// if (firstChild instanceof Pattern) {
+// Pattern pat = (Pattern) firstChild;
+// if (pat.getObjectType().isAssignableFrom(new ClassObjectType(InitialFact.class)))
+// arity--;
+// }
+//// if (firstChild.isPatternScopeDelimiter())
+//// ;
+//
+// OperatorInstaller instNode = new AndOperatorInstaller(
+// context.getTupleSource(),
+// arity,
+// context.getNextId(),
+// context.getPartitionId(),
+// context.getRuleBase().getConfiguration().isMultithreadEvaluation());
+//
+//
+// instNode.buildEvaluationTemplate(operator,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+//
+// context.setTupleSource((LeftTupleSource) utils.attachNode(
+// context,
+// instNode
+// ));
+//
+//
+//
+// }
+//
+// public boolean requiresLeftActivation(final BuildUtils utils,
+// final RuleConditionElement rce) {
+// final GroupElement and = (GroupElement) rce;
+//
+// // need to check this because in the case of an empty rule, the root AND
+// // will have no child
+// if ( and.getChildren().isEmpty() ) {
+// return true;
+// }
+//
+// final RuleConditionElement child = (RuleConditionElement) and.getChildren().get( 0 );
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// return builder.requiresLeftActivation( utils,
+// child );
+// }
+// }
+//
+// private static class ImperfectOrBuilder
+// implements
+// ReteooComponentBuilder {
+//
+//
+//
+// public void build(final BuildContext context,
+// final BuildUtils utils,
+// final RuleConditionElement rce) {
+//
+// IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
+//
+// IDegreeCombiner operator;
+// if (context.isNegated()) {
+// operator = factory.getNegationOperator();
+// ((NegationOperator) operator).setOperator(factory.getOrOperator());
+// context.toggleNegated();
+//
+// } else {
+// operator = factory.getOrOperator();
+// }
+//
+//
+// final GroupElement ge = (GroupElement) rce;
+//
+// // iterate over each child and build it
+// for ( final Iterator it = ge.getChildren().iterator(); it.hasNext(); ) {
+//
+// final RuleConditionElement child = (RuleConditionElement) it.next();
+//
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// builder.build( context,
+// utils,
+// child );
+//
+// // if a previous object source was bound, but no tuple source
+// if ( context.getObjectSource() != null && context.getTupleSource() == null ) {
+// // adapt it to a Tuple source
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new LeftInputAdapterNode( context.getNextId(),
+// context.getObjectSource(),
+// context ) ) );
+//
+// context.setObjectSource( null );
+// }
+//
+// // if there was a previous tuple source, then a join node is needed
+// if ( context.getObjectSource() != null && context.getTupleSource() != null ) {
+// // so, create the tuple source and clean up the constraints and object source
+// final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
+// context.getBetaconstraints(),
+// false );
+//
+// Behavior[] behaviors = createBehaviorArray( context );
+//
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new JoinNode( context.getNextId(),
+// context.getTupleSource(),
+// context.getObjectSource(),
+// betaConstraints,
+// behaviors,
+// context ) ) );
+// context.setBetaconstraints( null );
+// context.setObjectSource( null );
+// }
+// }
+//
+// OperatorInstaller instNode = new OrOperatorInstaller(
+// context.getTupleSource(),
+// ge.getChildren().size(),
+// context.getNextId(),
+// context.getPartitionId(),
+// context.getRuleBase().getConfiguration().isMultithreadEvaluation());
+//
+//
+// instNode.buildEvaluationTemplate(operator,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+//
+// context.setTupleSource((LeftTupleSource) utils.attachNode(
+// context,
+// instNode
+// ));
+//
+// }
+//
+// public boolean requiresLeftActivation(final BuildUtils utils,
+// final RuleConditionElement rce) {
+// final GroupElement and = (GroupElement) rce;
+//
+// // need to check this because in the case of an empty rule, the root AND
+// // will have no child
+// if ( and.getChildren().isEmpty() ) {
+// return true;
+// }
+//
+// final RuleConditionElement child = (RuleConditionElement) and.getChildren().get( 0 );
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// return builder.requiresLeftActivation( utils,
+// child );
+// }
+//
+// }
- // iterate over each child and build it
- for ( final Iterator it = ge.getChildren().iterator(); it.hasNext(); ) {
-
- final RuleConditionElement child = (RuleConditionElement) it.next();
-
- final ReteooComponentBuilder builder = utils.getBuilderFor( child );
-
- builder.build( context,
- utils,
- child );
-
- // if a previous object source was bound, but no tuple source
- if ( context.getObjectSource() != null && context.getTupleSource() == null ) {
- // adapt it to a Tuple source
- context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
- new LeftInputAdapterNode( context.getNextId(),
- context.getObjectSource(),
- context ) ) );
-
- context.setObjectSource( null );
- }
-
- // if there was a previous tuple source, then a join node is needed
- if ( context.getObjectSource() != null && context.getTupleSource() != null ) {
- // so, create the tuple source and clean up the constraints and object source
- final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
- context.getBetaconstraints(),
- false );
-
- Behavior[] behaviors = createBehaviorArray( context );
-
- context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
- new JoinNode( context.getNextId(),
- context.getTupleSource(),
- context.getObjectSource(),
- betaConstraints,
- behaviors,
- context ) ) );
- context.setBetaconstraints( null );
- context.setObjectSource( null );
- }
- }
-
- OperatorInstaller instNode = new OrOperatorInstaller(
- context.getTupleSource(),
- ge.getChildren().size(),
- context.getNextId(),
- context.getPartitionId(),
- context.getRuleBase().getConfiguration().isMultithreadEvaluation());
-
-
- instNode.buildEvaluationTemplate(operator,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
-
- context.setTupleSource((LeftTupleSource) utils.attachNode(
- context,
- instNode
- ));
-
- }
-
- public boolean requiresLeftActivation(final BuildUtils utils,
- final RuleConditionElement rce) {
- final GroupElement and = (GroupElement) rce;
-
- // need to check this because in the case of an empty rule, the root AND
- // will have no child
- if ( and.getChildren().isEmpty() ) {
- return true;
- }
-
- final RuleConditionElement child = (RuleConditionElement) and.getChildren().get( 0 );
- final ReteooComponentBuilder builder = utils.getBuilderFor( child );
-
- return builder.requiresLeftActivation( utils,
- child );
- }
-
- }
-
private static class ImperfectNotBuilder
implements
ReteooComponentBuilder {
@@ -438,8 +679,601 @@
return true;
}
}
+
+
+
+
+ private static class ImperfectForAnyNodeBuilder
+ implements
+ ReteooComponentBuilder {
-
-
+ /**
+ * @inheritDoc
+ *
+ * Exists must verify what is the class of its child:
+ *
+ * If it is a pattern, a simple ExistsNode is added to the rulebase
+ * If it is a group element, than a subnetwork must be created
+ */
+ public void build(final BuildContext context,
+ final BuildUtils utils,
+ final RuleConditionElement rce) {
+
+ IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
+
+ IDegreeCombiner operator;
+ if (context.isNegated()) {
+ operator = factory.getNegationOperator();
+ ((NegationOperator) operator).setOperator(factory.getForAnyOperator());
+ context.toggleNegated();
+
+ } else {
+ operator = factory.getForAnyOperator();
+ }
+
+
+ final GroupElement forany = (GroupElement) rce;
+ // EXISTS must save some context info to restore it later
+ final int currentPatternIndex = context.getCurrentPatternOffset();
+ final LeftTupleSource tupleSource = context.getTupleSource();
+
+ // get child
+ final RuleConditionElement child = (RuleConditionElement) forany.getChildren().get( 0 );
+
+ // get builder for child
+ final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+
+ // builds the child
+ builder.build( context,
+ utils,
+ child );
+
+ // if it is a subnetwork
+ if ( context.getObjectSource() == null && context.getTupleSource() != null ) {
+
+ // attach right input adapter node to convert tuple source into an object source
+ context.setObjectSource( (ObjectSource) utils.attachNode( context,
+ new RightInputAdapterNode( context.getNextId(),
+ context.getTupleSource(),
+ context ) ) );
+
+ // restore tuple source from before the start of the sub network
+ context.setTupleSource( tupleSource );
+
+ // create a tuple start equals constraint and set it in the context
+ final TupleStartEqualsConstraint constraint = TupleStartEqualsConstraint.getInstance();
+ final List predicates = new ArrayList();
+ predicates.add( constraint );
+ context.setBetaconstraints( predicates );
+
+ }
+
+ BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
+ context.getBetaconstraints(),
+ false );
+
+
+
+ Behavior[] behaviors = createBehaviorArray( context );
+
+ // then attach the EXISTS node. It will work both as a simple exists node
+ // or as subnetwork join node as the context was set appropriatelly
+ // in each case
+
+
+
+
+ ImperfectExistsNode exNode = new ImperfectExistsNode( context.getNextId(),
+ context.getTupleSource(),
+ context.getObjectSource(),
+ betaConstraints,
+ behaviors,
+ context );
+
+ exNode.buildEvaluationTemplate(operator,context.getRule().getDependencies(),factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+
+ context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+ exNode) );
+ context.setBetaconstraints( null );
+ context.setObjectSource( null );
+
+ // restore pattern index
+ context.setCurrentPatternOffset( currentPatternIndex );
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public boolean requiresLeftActivation(final BuildUtils utils,
+ final RuleConditionElement rce) {
+
+ return true;
+ }
}
+
+
+
+
+
+
+// private static class ImperfectXorBuilder
+// implements
+// ReteooComponentBuilder {
+//
+// /**
+// * @inheritDoc
+// *
+// * And group elements just iterate over their children
+// * selecting and calling the build procedure for each one
+// *
+// */
+// public void build(final BuildContext context,
+// final BuildUtils utils,
+// final RuleConditionElement rce) {
+//
+//
+//
+// IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
+//
+// IDegreeCombiner operator;
+// if (context.isNegated()) {
+// operator = factory.getNegationOperator();
+// ((NegationOperator) operator).setOperator(factory.getXorOperator());
+// context.toggleNegated();
+//
+// } else {
+// operator = factory.getXorOperator();
+// }
+//
+//
+// final GroupElement ge = (GroupElement) rce;
+//
+// // iterate over each child and build it
+// for ( final Iterator it = ge.getChildren().iterator(); it.hasNext(); ) {
+//
+// final RuleConditionElement child = (RuleConditionElement) it.next();
+//
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// builder.build( context,
+// utils,
+// child );
+//
+// // if a previous object source was bound, but no tuple source
+// if ( context.getObjectSource() != null && context.getTupleSource() == null ) {
+// // adapt it to a Tuple source
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new LeftInputAdapterNode( context.getNextId(),
+// context.getObjectSource(),
+// context ) ) );
+//
+// context.setObjectSource( null );
+// }
+//
+// // if there was a previous tuple source, then a join node is needed
+// if ( context.getObjectSource() != null && context.getTupleSource() != null ) {
+// // so, create the tuple source and clean up the constraints and object source
+// final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
+// context.getBetaconstraints(),
+// false );
+//
+// Behavior[] behaviors = createBehaviorArray( context );
+//
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new JoinNode( context.getNextId(),
+// context.getTupleSource(),
+// context.getObjectSource(),
+// betaConstraints,
+// behaviors,
+// context ) ) );
+// context.setBetaconstraints( null );
+// context.setObjectSource( null );
+// }
+// }
+//
+// int arity = ge.getChildren().size();
+// Object firstChild = ge.getChildren().get(0);
+// if (firstChild instanceof Pattern) {
+// Pattern pat = (Pattern) firstChild;
+// if (pat.getObjectType().isAssignableFrom(new ClassObjectType(InitialFact.class)))
+// arity--;
+// }
+//// if (firstChild.isPatternScopeDelimiter())
+//// ;
+//
+// OperatorInstaller instNode = new XorOperatorInstaller(
+// context.getTupleSource(),
+// arity,
+// context.getNextId(),
+// context.getPartitionId(),
+// context.getRuleBase().getConfiguration().isMultithreadEvaluation());
+//
+//
+// instNode.buildEvaluationTemplate(operator,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+//
+// context.setTupleSource((LeftTupleSource) utils.attachNode(
+// context,
+// instNode
+// ));
+//
+//
+//
+// }
+//
+// public boolean requiresLeftActivation(final BuildUtils utils,
+// final RuleConditionElement rce) {
+// final GroupElement xor = (GroupElement) rce;
+//
+// // need to check this because in the case of an empty rule, the root AND
+// // will have no child
+// if ( xor.getChildren().isEmpty() ) {
+// return true;
+// }
+//
+// final RuleConditionElement child = (RuleConditionElement) xor.getChildren().get( 0 );
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// return builder.requiresLeftActivation( utils,
+// child );
+// }
+//}
+//
+//
+//
+//
+// private static class ImperfectEqvBuilder
+// implements
+// ReteooComponentBuilder {
+//
+// /**
+// * @inheritDoc
+// *
+// * And group elements just iterate over their children
+// * selecting and calling the build procedure for each one
+// *
+// */
+// public void build(final BuildContext context,
+// final BuildUtils utils,
+// final RuleConditionElement rce) {
+//
+//
+//
+// IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
+//
+// IDegreeCombiner operator;
+// if (context.isNegated()) {
+// operator = factory.getNegationOperator();
+// ((NegationOperator) operator).setOperator(factory.getEquivOperator());
+// context.toggleNegated();
+//
+// } else {
+// operator = factory.getEquivOperator();
+// }
+//
+//
+// final GroupElement ge = (GroupElement) rce;
+//
+// // iterate over each child and build it
+// for ( final Iterator it = ge.getChildren().iterator(); it.hasNext(); ) {
+//
+// final RuleConditionElement child = (RuleConditionElement) it.next();
+//
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// builder.build( context,
+// utils,
+// child );
+//
+// // if a previous object source was bound, but no tuple source
+// if ( context.getObjectSource() != null && context.getTupleSource() == null ) {
+// // adapt it to a Tuple source
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new LeftInputAdapterNode( context.getNextId(),
+// context.getObjectSource(),
+// context ) ) );
+//
+// context.setObjectSource( null );
+// }
+//
+// // if there was a previous tuple source, then a join node is needed
+// if ( context.getObjectSource() != null && context.getTupleSource() != null ) {
+// // so, create the tuple source and clean up the constraints and object source
+// final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
+// context.getBetaconstraints(),
+// false );
+//
+// Behavior[] behaviors = createBehaviorArray( context );
+//
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new JoinNode( context.getNextId(),
+// context.getTupleSource(),
+// context.getObjectSource(),
+// betaConstraints,
+// behaviors,
+// context ) ) );
+// context.setBetaconstraints( null );
+// context.setObjectSource( null );
+// }
+// }
+//
+// int arity = ge.getChildren().size();
+// Object firstChild = ge.getChildren().get(0);
+// if (firstChild instanceof Pattern) {
+// Pattern pat = (Pattern) firstChild;
+// if (pat.getObjectType().isAssignableFrom(new ClassObjectType(InitialFact.class)))
+// arity--;
+// }
+//// if (firstChild.isPatternScopeDelimiter())
+//// ;
+//
+// OperatorInstaller instNode = new EqvOperatorInstaller(
+// context.getTupleSource(),
+// arity,
+// context.getNextId(),
+// context.getPartitionId(),
+// context.getRuleBase().getConfiguration().isMultithreadEvaluation());
+//
+//
+// instNode.buildEvaluationTemplate(operator,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+//
+// context.setTupleSource((LeftTupleSource) utils.attachNode(
+// context,
+// instNode
+// ));
+//
+//
+//
+// }
+//
+// public boolean requiresLeftActivation(final BuildUtils utils,
+// final RuleConditionElement rce) {
+// final GroupElement eqv = (GroupElement) rce;
+//
+// // need to check this because in the case of an empty rule, the root AND
+// // will have no child
+// if ( eqv.getChildren().isEmpty() ) {
+// return true;
+// }
+//
+// final RuleConditionElement child = (RuleConditionElement) eqv.getChildren().get( 0 );
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// return builder.requiresLeftActivation( utils,
+// child );
+// }
+// }
+//
+//
+//
+//
+//
+//
+//
+//
+// private static class ImperfectDiscountBuilder
+// implements
+// ReteooComponentBuilder {
+//
+//
+//
+// public void build(final BuildContext context,
+// final BuildUtils utils,
+// final RuleConditionElement rce) {
+//
+// IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
+//
+// IDegreeCombiner operator;
+// if (context.isNegated()) {
+// operator = factory.getNegationOperator();
+// ((NegationOperator) operator).setOperator(factory.getDiscountOperator());
+// context.toggleNegated();
+//
+// } else {
+// operator = factory.getDiscountOperator();
+// }
+//
+//
+// final GroupElement ge = (GroupElement) rce;
+//
+// // iterate over each child and build it
+// for ( final Iterator it = ge.getChildren().iterator(); it.hasNext(); ) {
+//
+// final RuleConditionElement child = (RuleConditionElement) it.next();
+//
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// builder.build( context,
+// utils,
+// child );
+//
+// // if a previous object source was bound, but no tuple source
+// if ( context.getObjectSource() != null && context.getTupleSource() == null ) {
+// // adapt it to a Tuple source
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new LeftInputAdapterNode( context.getNextId(),
+// context.getObjectSource(),
+// context ) ) );
+//
+// context.setObjectSource( null );
+// }
+//
+// // if there was a previous tuple source, then a join node is needed
+// if ( context.getObjectSource() != null && context.getTupleSource() != null ) {
+// // so, create the tuple source and clean up the constraints and object source
+// final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
+// context.getBetaconstraints(),
+// false );
+//
+// Behavior[] behaviors = createBehaviorArray( context );
+//
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new JoinNode( context.getNextId(),
+// context.getTupleSource(),
+// context.getObjectSource(),
+// betaConstraints,
+// behaviors,
+// context ) ) );
+// context.setBetaconstraints( null );
+// context.setObjectSource( null );
+// }
+// }
+//
+// OperatorInstaller instNode = new DiscountOperatorInstaller(
+// context.getTupleSource(),
+// ge.getChildren().size(),
+// context.getNextId(),
+// context.getPartitionId(),
+// context.getRuleBase().getConfiguration().isMultithreadEvaluation());
+//
+//
+// instNode.buildEvaluationTemplate(operator,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+//
+// context.setTupleSource((LeftTupleSource) utils.attachNode(
+// context,
+// instNode
+// ));
+//
+// }
+//
+// public boolean requiresLeftActivation(final BuildUtils utils,
+// final RuleConditionElement rce) {
+// final GroupElement and = (GroupElement) rce;
+//
+// // need to check this because in the case of an empty rule, the root AND
+// // will have no child
+// if ( and.getChildren().isEmpty() ) {
+// return true;
+// }
+//
+// final RuleConditionElement child = (RuleConditionElement) and.getChildren().get( 0 );
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// return builder.requiresLeftActivation( utils,
+// child );
+// }
+//
+// }
+//
+//
+//
+//
+//
+// private static class ImperfectDoubleMPBuilder
+// implements
+// ReteooComponentBuilder {
+//
+//
+//
+// public void build(final BuildContext context,
+// final BuildUtils utils,
+// final RuleConditionElement rce) {
+//
+// IDegreeFactory factory = ((ImperfectRuleBase) context.getRuleBase()).getDegreeFactory();
+//
+// IDegreeCombiner operator;
+// if (context.isNegated()) {
+// operator = factory.getNegationOperator();
+// ((NegationOperator) operator).setOperator(factory.getDoubleMPOperator());
+// context.toggleNegated();
+//
+// } else {
+// operator = factory.getDoubleMPOperator();
+// }
+//
+//
+// final GroupElement ge = (GroupElement) rce;
+//
+// // iterate over each child and build it
+// for ( final Iterator it = ge.getChildren().iterator(); it.hasNext(); ) {
+//
+// final RuleConditionElement child = (RuleConditionElement) it.next();
+//
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// builder.build( context,
+// utils,
+// child );
+//
+// // if a previous object source was bound, but no tuple source
+// if ( context.getObjectSource() != null && context.getTupleSource() == null ) {
+// // adapt it to a Tuple source
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new LeftInputAdapterNode( context.getNextId(),
+// context.getObjectSource(),
+// context ) ) );
+//
+// context.setObjectSource( null );
+// }
+//
+// // if there was a previous tuple source, then a join node is needed
+// if ( context.getObjectSource() != null && context.getTupleSource() != null ) {
+// // so, create the tuple source and clean up the constraints and object source
+// final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
+// context.getBetaconstraints(),
+// false );
+//
+// Behavior[] behaviors = createBehaviorArray( context );
+//
+// context.setTupleSource( (LeftTupleSource) utils.attachNode( context,
+// new JoinNode( context.getNextId(),
+// context.getTupleSource(),
+// context.getObjectSource(),
+// betaConstraints,
+// behaviors,
+// context ) ) );
+// context.setBetaconstraints( null );
+// context.setObjectSource( null );
+// }
+// }
+//
+// OperatorInstaller instNode = new DoubleMPOperatorInstaller(
+// context.getTupleSource(),
+// ge.getChildren().size(),
+// context.getNextId(),
+// context.getPartitionId(),
+// context.getRuleBase().getConfiguration().isMultithreadEvaluation());
+//
+//
+// instNode.buildEvaluationTemplate(operator,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+//
+// context.setTupleSource((LeftTupleSource) utils.attachNode(
+// context,
+// instNode
+// ));
+//
+// }
+//
+// public boolean requiresLeftActivation(final BuildUtils utils,
+// final RuleConditionElement rce) {
+// final GroupElement and = (GroupElement) rce;
+//
+// // need to check this because in the case of an empty rule, the root AND
+// // will have no child
+// if ( and.getChildren().isEmpty() ) {
+// return true;
+// }
+//
+// final RuleConditionElement child = (RuleConditionElement) and.getChildren().get( 0 );
+// final ReteooComponentBuilder builder = utils.getBuilderFor( child );
+//
+// return builder.requiresLeftActivation( utils,
+// child );
+// }
+//
+// }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectReteooRuleBuilder.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectReteooRuleBuilder.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/ImperfectReteooRuleBuilder.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -21,6 +21,7 @@
import org.drools.rule.EntryPoint;
import org.drools.rule.EvalCondition;
import org.drools.rule.Forall;
+import org.drools.rule.Forany;
import org.drools.rule.From;
import org.drools.rule.GroupElement;
import org.drools.rule.InvalidPatternException;
@@ -51,6 +52,8 @@
new AccumulateBuilder() );
this.getUtils().addBuilder( Forall.class,
new ImperfectForallBuilder() );
+ this.getUtils().addBuilder( Forany.class,
+ new ImperfectForAnyBuilder() );
this.getUtils().addBuilder( EntryPoint.class,
new EntryPointBuilder() );
}
@@ -75,6 +78,8 @@
final BuildContext context = new BuildContext( rulebase,
idGenerator );
context.setRule( rule );
+ context.setDependencies(rule.getDependencies());
+
// if running in STREAM mode, calculate temporal distance for events
if( EventProcessingMode.STREAM.equals( rulebase.getConfiguration().getEventProcessingMode() ) ) {
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -131,6 +131,12 @@
}
}
+
+ if (pattern.isCutter()) {
+
+ //throw new RuntimeDroolsException("A CuTTING Pattern has been created NOW");
+ }
+
// last thing to do is increment the offset, since if the pattern has a source,
// offset must be overriden
context.incrementCurrentPatternOffset();
@@ -273,6 +279,8 @@
(EntryPointNode) context.getObjectSource(),
objectType,
context );
+
+
if( objectType.isEvent() && EventProcessingMode.STREAM.equals( context.getRuleBase().getConfiguration().getEventProcessingMode() ) ) {
long expirationOffset = 0;
for( TypeDeclaration type : context.getRuleBase().getTypeDeclarations() ) {
@@ -288,8 +296,17 @@
}
}
- context.setObjectSource( (ObjectSource) utils.attachNode( context,
- otn ) );
+ ObjectTypeNode returnedOtn = (ObjectTypeNode) utils.attachNode( context, otn );
+ context.setObjectSource( returnedOtn );
+
+ //Notice that == is called on purpose
+ if (returnedOtn == otn) {
+ if (pattern.getLabel() != null)
+ otn.setLabel(pattern.getLabel());
+ otn.setImperfectStructures(context);
+ }
+
+
for ( final Iterator<Constraint> it = alphaConstraints.iterator(); it.hasNext(); ) {
final AlphaNodeFieldConstraint constraint = (AlphaNodeFieldConstraint) it.next();
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AbstractCompositeConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AbstractCompositeConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AbstractCompositeConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -26,6 +26,7 @@
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.degrees.factory.IDegreeFactory;
+import org.drools.degrees.operators.IDegreeCombiner;
import org.drools.reteoo.CompositeEvaluationTemplate;
import org.drools.reteoo.ConstraintKey;
import org.drools.reteoo.EvaluationTemplate;
@@ -45,6 +46,8 @@
protected AlphaNodeFieldConstraint[] alphaConstraints = new AlphaNodeFieldConstraint[0];
protected BetaNodeFieldConstraint[] betaConstraints = new BetaNodeFieldConstraint[0];
protected Declaration[] requiredDeclarations = new Declaration[0];
+
+ private IDegreeCombiner operator;
public AbstractCompositeConstraint() {
super();
@@ -233,6 +236,9 @@
}
final AbstractCompositeConstraint other = (AbstractCompositeConstraint) object;
+ if (this.isCutter() != other.isCutter())
+ return false;
+
return Arrays.equals( this.alphaConstraints,
other.alphaConstraints ) && Arrays.equals( this.betaConstraints,
other.betaConstraints ) && Arrays.equals( this.requiredDeclarations,
@@ -385,6 +391,38 @@
// }
// }
+ public boolean isCutter() {
+
+ //SHOULD NOT BE CALLED??
+ for (int j = 0; j < alphaConstraints.length; j++)
+ if (alphaConstraints[j].isCutter())
+ return true;
+
+ for (int j = 0; j < betaConstraints.length; j++)
+ if (betaConstraints[j].isCutter())
+ return true;
+
+ return false;
+ }
+
+
+ public void setCutter(boolean cut) {
+ //throw new RuntimeDroolsException("Composite constraint cut is set at constraint level, not at restriction level");
+ }
+
+ /**
+ * @param operator the operator to set
+ */
+ public void setOperator(IDegreeCombiner operator) {
+ this.operator = operator;
+ }
+
+ /**
+ * @return the operator
+ */
+ public IDegreeCombiner getOperator() {
+ return operator;
+ }
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -20,6 +20,10 @@
protected Restriction[] restrictions;
+ private boolean isCutter;
+
+ private String label;
+
public AbstractCompositeRestriction() {
}
@@ -180,5 +184,28 @@
}
}
+
+ /**
+ * @param isCutter the isCutter to set
+ */
+ public void setCutter(boolean isCutter) {
+ this.isCutter = isCutter;
+ }
+ /**
+ * @return the isCutter
+ */
+ public boolean isCutter() {
+ return isCutter;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Accumulate.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Accumulate.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Accumulate.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -279,4 +279,8 @@
return true;
}
+ public boolean isCutter() {
+ return false;
+ }
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AndConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AndConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/AndConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -229,6 +229,7 @@
private ConstraintKey singletonKey = null;
+ private String label;
public ConstraintKey getConstraintKey() {
if (singletonKey == null) {
@@ -239,7 +240,8 @@
cks[j] = this.alphaConstraints[j].getConstraintKey();
for (int j = 0; j < Nb; j++)
cks[Na+j] = this.betaConstraints[j].getConstraintKey();
- singletonKey = new ConstraintKey("and",cks);
+ String opStr = this.getOperator().getName();
+ singletonKey = new ConstraintKey( opStr , cks);
}
return singletonKey;
}
@@ -264,7 +266,15 @@
public EvaluationTemplate buildEvaluationTemplate(int id, Map<ConstraintKey, Set<String>> dependencies, IDegreeFactory factory) {
//BUILD A COMPOSITE TEMPLATE
int N = this.getAlphaConstraints().length + this.getBetaConstraints().length;
- CompositeEvaluationTemplate temp = new CompositeEvaluationTemplate(id,this.getConstraintKey(),dependencies.get(this.getConstraintKey()),N,factory.getAndOperator(),factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+ this.setOperator(factory.getAndOperator(this.getParams()));
+ CompositeEvaluationTemplate temp = new CompositeEvaluationTemplate(
+ id,
+ this.getConstraintKey(),
+ dependencies.get(this.getConstraintKey()),
+ N,
+ this.getOperator(),
+ factory.getMergeStrategy(),
+ factory.getNullHandlingStrategy());
int Na = this.alphaConstraints.length;
int Nb = this.betaConstraints.length;
@@ -284,6 +294,15 @@
// setTemplate(new EvaluationTemplate(id,this.getConstraintKey(),dependencies.get(this.getConstraintKey()),N,factory.getAndOperator(),factory.getMergeStrategy(),factory.getNullHandlingStrategy()));
// }
+
+
+ public String getLabel() {
+ return this.label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Collect.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Collect.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Collect.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -123,4 +123,9 @@
public boolean isPatternScopeDelimiter() {
return true;
}
+
+ public boolean isCutter() {
+ // TODO Auto-generated method stub
+ return false;
+ }
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/EntryPoint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/EntryPoint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/EntryPoint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -158,4 +158,10 @@
public boolean isPatternScopeDelimiter() {
return true;
}
+
+
+ public boolean isCutter() {
+
+ return false;
+ }
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/EvalCondition.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/EvalCondition.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/EvalCondition.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -210,4 +210,8 @@
}
}
+ public boolean isCutter() {
+ return false;
+ }
+
};
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Forall.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Forall.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Forall.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -146,4 +146,8 @@
return true;
}
+ public boolean isCutter() {
+ return false;
+ }
+
}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Forany.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Forany.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Forany.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,160 @@
+package org.drools.rule;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class Forany extends ConditionalElement {
+
+ private RuleConditionElement integrand;
+ private RuleConditionElement constraint;
+ private RuleConditionElement weight;
+
+
+
+
+
+
+
+
+ public Object clone() {
+ Forany ans = new Forany();
+ ans.setIntegrand(this.integrand);
+ ans.setConstraint(this.constraint);
+ ans.setWeight(this.weight);
+ return ans;
+ }
+
+ public Map<String, Declaration> getInnerDeclarations() {
+ final Map<String,Declaration> inner = new HashMap<String, Declaration>( this.integrand.getOuterDeclarations() );
+ if (this.constraint != null)
+ inner.putAll(constraint.getOuterDeclarations());
+ if (this.weight != null)
+ inner.putAll(weight.getOuterDeclarations());
+
+ return inner;
+ }
+
+ public List<RuleConditionElement> getNestedElements() {
+ List<RuleConditionElement> ans = new ArrayList<RuleConditionElement>(3);
+ ans.add(integrand);
+ if (constraint != null) ans.add(constraint);
+ if (weight != null) ans.add(weight);
+ return ans;
+ }
+
+ public Map<String, Declaration> getOuterDeclarations() {
+ return Collections.emptyMap();
+ }
+
+ public boolean isPatternScopeDelimiter() {
+ return true;
+ }
+
+ public Declaration resolveDeclaration(String identifier) {
+ return (Declaration) this.getInnerDeclarations().get( identifier );
+ }
+
+
+
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ integrand = (RuleConditionElement) in.readObject();
+ Object constr = in.readObject();
+ constraint = constr == null ? null : (RuleConditionElement) constr;
+ Object wgt = in.readObject();
+ weight = wgt == null ? null : (RuleConditionElement) wgt;
+
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(integrand);
+ out.writeObject(constraint);
+ out.writeObject(weight);
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /**
+ * @param integrand the integrand to set
+ */
+ public void setIntegrand(RuleConditionElement integrand) {
+ this.integrand = integrand;
+ }
+
+ /**
+ * @return the integrand
+ */
+ public RuleConditionElement getIntegrand() {
+ return integrand;
+ }
+
+ /**
+ * @param constraint the constraint to set
+ */
+ public void setConstraint(RuleConditionElement constraint) {
+ this.constraint = constraint;
+ }
+
+ /**
+ * @return the constraint
+ */
+ public RuleConditionElement getConstraint() {
+ return constraint;
+ }
+
+ /**
+ * @param weight the weight to set
+ */
+ public void setWeight(RuleConditionElement weight) {
+ this.weight = weight;
+ }
+
+ /**
+ * @return the weight
+ */
+ public RuleConditionElement getWeight() {
+ return weight;
+ }
+
+
+
+ public boolean isCutter() {
+ return false;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/From.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/From.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/From.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -71,5 +71,9 @@
public boolean isPatternScopeDelimiter() {
return true;
}
+
+ public boolean isCutter() {
+ return false;
+ }
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/GroupElement.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/GroupElement.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/GroupElement.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -38,10 +38,23 @@
public static final Type AND = Type.AND;
public static final Type OR = Type.OR;
public static final Type NOT = Type.NOT;
+ public static final Type XOR = Type.XOR;
+ public static final Type EQV = Type.EQV;
public static final Type EXISTS = Type.EXISTS;
+// public static final Type FORANY = Type.FORANY;
+ public static final Type DISC = Type.DISC;
+ public static final Type AVG = Type.AVG;
+ public static final Type DMP = Type.DMP;
+
+ public static final Type HEDGE = Type.HEDGE;
+
+
+
private Type type = null;
private List children = new ArrayList();
+ private String param = null;
+ private String label = null;
public GroupElement() {
this( Type.AND );
@@ -50,6 +63,11 @@
public GroupElement(final Type type) {
this.type = type;
}
+
+ public GroupElement(final Type type, String spec) {
+ this.type = type;
+ this.setParam(spec);
+ }
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
@@ -62,6 +80,11 @@
out.writeObject( children );
}
+ public boolean isCutter() {
+ return false;
+ }
+
+
/**
* Adds a child to the current GroupElement.
*
@@ -295,6 +318,14 @@
public boolean isAnd() {
return AND.equals( this.type );
}
+
+ public boolean isXor() {
+ return XOR.equals( this.type );
+ }
+
+ public boolean isEqv() {
+ return EQV.equals( this.type );
+ }
public boolean isOr() {
return OR.equals( this.type );
@@ -307,6 +338,26 @@
public boolean isExists() {
return EXISTS.equals( this.type );
}
+
+ public boolean isDiscount() {
+ return DISC.equals( this.type );
+ }
+
+ public boolean isAverage() {
+ return AVG.equals( this.type );
+ }
+
+ public boolean isDoubleMP() {
+ return DMP.equals( this.type );
+ }
+
+ public boolean isHedge() {
+ return HEDGE.equals( this.type );
+ }
+
+// public boolean isForAny() {
+// return FORANY.equals( this.type );
+// }
public String toString() {
return this.type.toString() + this.children.toString();
@@ -321,14 +372,49 @@
}
/**
+ * @param param the param to set
+ */
+ public void setParam(String param) {
+ this.param = param;
+ }
+
+ /**
+ * @return the param
+ */
+ public String getParam() {
+ return param;
+ }
+
+ /**
+ * @param label the label to set
+ */
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ /**
+ * @return the label
+ */
+ public String getLabel() {
+ return label;
+ }
+
+ /**
* A public enum for CE types
*/
public static enum Type {
AND(false),
OR(false),
- NOT(true),
- EXISTS(true);
+ NOT(true),
+ XOR(false),
+ EQV(false),
+ EXISTS(true),
+ AVG(false),
+ DISC(false),
+ DMP(false),
+ HEDGE(false);
+// FORANY(true);
private final boolean scopeDelimiter;
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/GroupElementFactory.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/GroupElementFactory.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/GroupElementFactory.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -42,4 +42,84 @@
return new GroupElement( GroupElement.EXISTS );
}
+// public static GroupElement newForAnyInstance() {
+// return new GroupElement( GroupElement.FORANY );
+// }
+
+ public static GroupElement newXorInstance() {
+ return new GroupElement( GroupElement.XOR );
+ }
+
+ public static GroupElement newEqvInstance() {
+ return new GroupElement( GroupElement.EQV );
+ }
+
+ public static GroupElement newDiscountInstance() {
+ return new GroupElement( GroupElement.DISC );
+ }
+
+ public static GroupElement newAvgInstance() {
+ return new GroupElement( GroupElement.AVG );
+ }
+
+ public static GroupElement newDblMPInstance() {
+ return new GroupElement( GroupElement.DMP );
+ }
+
+
+ public static GroupElement newHedgeInstance() {
+ return new GroupElement( GroupElement.HEDGE );
+ }
+
+
+
+
+
+ public static GroupElement newAndInstance(String params) {
+ return new GroupElement( GroupElement.AND, params );
+ }
+
+ public static GroupElement newOrInstance(String params) {
+ return new GroupElement( GroupElement.OR, params );
+ }
+
+ public static GroupElement newNotInstance(String params) {
+ return new GroupElement( GroupElement.NOT, params );
+ }
+
+ public static GroupElement newExistsInstance(String params) {
+ return new GroupElement( GroupElement.EXISTS, params );
+ }
+
+// public static GroupElement newForAnyInstance() {
+// return new GroupElement( GroupElement.FORANY );
+// }
+
+ public static GroupElement newXorInstance(String params) {
+ return new GroupElement( GroupElement.XOR, params );
+ }
+
+ public static GroupElement newEqvInstance(String params) {
+ return new GroupElement( GroupElement.EQV, params );
+ }
+
+ public static GroupElement newDiscountInstance(String params) {
+ return new GroupElement( GroupElement.DISC, params );
+ }
+
+ public static GroupElement newAvgInstance(String params) {
+ return new GroupElement( GroupElement.AVG, params );
+ }
+
+ public static GroupElement newDblMPInstance(String params) {
+ return new GroupElement( GroupElement.DMP , params);
+ }
+
+ public static GroupElement newHedgeInstance(String params) {
+ return new GroupElement( GroupElement.HEDGE , params);
+ }
+
+
+
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -52,9 +52,14 @@
private InternalReadAccessor readAccesor;
private LiteralRestriction restriction;
+
- private EvaluationTemplate template;
-
+
+ private EvaluationTemplate template;
+
+ private String label;
+
+
public LiteralConstraint() {
this( null,
null );
@@ -158,7 +163,7 @@
}
final LiteralConstraint other = (LiteralConstraint) object;
- return this.readAccesor.equals( other.readAccesor ) && this.restriction.equals( other.restriction );
+ return this.readAccesor.equals( other.readAccesor ) && this.restriction.equals( other.restriction ) && (this.isCutter() == other.isCutter());
}
public Object clone() {
@@ -196,11 +201,35 @@
public EvaluationTemplate buildEvaluationTemplate(int id, Map<ConstraintKey, Set<String>> dependencies, IDegreeFactory factory) {
Set<String> deps;
+
+ String label = this.restriction.getLabel();
+ Set<String> aliasedDeps = null;
+ if (dependencies != null && label != null) {
+ ConstraintKey tester = new ConstraintKey();
+ tester.setAlias(label);
+ aliasedDeps = dependencies.remove(tester);
+
+ if (aliasedDeps != null) {
+ ConstraintKey properKey = this.getConstraintKey();
+ Set<String> previousDeps = dependencies.remove(properKey);
+
+ if (previousDeps != null)
+ aliasedDeps.addAll(previousDeps);
+
+ properKey.setAlias(label);
+
+ dependencies.put(properKey, aliasedDeps);
+ }
+ }
+
+
if (dependencies == null)
deps = Collections.emptySet();
else
deps = dependencies.get(this.getConstraintKey());
+
+
this.template = new SingleEvaluationTemplate(id,this.getConstraintKey(),deps,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
return template;
}
@@ -211,6 +240,28 @@
else return null;
}
+
+ public boolean isCutter() {
+ return restriction.isCutter();
+ }
+
+ public void setCutter(boolean cut) {
+ restriction.setCutter(cut);
+ }
+ /**
+ * @param label the label to set
+ */
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ /**
+ * @return the label
+ */
+ public String getLabel() {
+ return label;
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -51,6 +51,10 @@
private InternalReadAccessor readAccessor;
private static final Declaration[] requiredDeclarations = new Declaration[0];
+
+ private boolean isCutter;
+
+ private String label;
public LiteralRestriction() {
this( null,
@@ -104,7 +108,7 @@
public IDegree isSatisfied(InternalReadAccessor extractor,
InternalFactHandle handle, InternalWorkingMemory workingMemory,
ContextEntry context, IDegreeFactory factory) {
- return this.evaluator.evaluate( null,
+ return this.evaluator.evaluate( workingMemory,
factory,
this.readAccessor,
handle.getObject(),
@@ -277,7 +281,29 @@
ans.add(this.getConstraintKey());
return ans;
}
+
+ /**
+ * @param isCutter the isCutter to set
+ */
+ public void setCutter(boolean isCutter) {
+ this.isCutter = isCutter;
+ }
+
+ /**
+ * @return the isCutter
+ */
+ public boolean isCutter() {
+ return isCutter;
+ }
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -102,7 +102,7 @@
}
final MultiRestrictionFieldConstraint other = (MultiRestrictionFieldConstraint) object;
- return this.readAccessor.equals( other.readAccessor ) && this.restrictions.equals( other.restrictions );
+ return this.readAccessor.equals( other.readAccessor ) && this.restrictions.equals( other.restrictions ) && (this.isCutter() == other.isCutter());
}
public boolean isAllowed(final InternalFactHandle handle,
@@ -192,10 +192,27 @@
return this.getTemplate();
else return null;
}
+
+ public boolean isCutter() {
+ return restrictions.isCutter();
+ }
+
+ public void setCutter(boolean cutter) {
+ this.restrictions.setCutter(cutter);
+
+
+ }
+ public String getLabel() {
+ return this.restrictions.getLabel();
+ }
+
+ public void setLabel(String label) {
+ this.restrictions.setLabel(label);
+ }
+
-
/*
private EvaluationTemplate buildTemplateForRestriction(Restriction restr, CompositeEvaluationTemplate master, int id, Map<ConstraintKey, Set<String>> dependencies, IDegreeFactory factory) {
EvaluationTemplate temp = null;
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/MutableTypeConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/MutableTypeConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/MutableTypeConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.util.Collections;
import java.util.Map;
import java.util.Set;
@@ -47,7 +48,11 @@
private Constraint.ConstraintType type = Constraint.ConstraintType.UNKNOWN;
private EvaluationTemplate template;
+
+ private String params;
+
+
public void setType( ConstraintType type ) {
this.type = type;
}
@@ -66,11 +71,8 @@
public abstract Object clone();
- public EvaluationTemplate buildEvaluationTemplate(int id, Map<ConstraintKey, Set<String>> dependencies, IDegreeFactory factory) {
- setTemplate(new SingleEvaluationTemplate(id,this.getConstraintKey(),dependencies.get(this.getConstraintKey()),factory.getMergeStrategy(),factory.getNullHandlingStrategy()));
- return getTemplate();
- }
+
public EvaluationTemplate getTemplate() {
return this.template;
}
@@ -87,7 +89,67 @@
return null;
}
}
+
+ /**
+ * @param params the params to set
+ */
+ public void setParams(String params) {
+ this.params = params;
+ }
+
+ /**
+ * @return the params
+ */
+ public String getParams() {
+ return params;
+ }
+
+ /**
+ * @param label the label to set
+ */
+ public abstract void setLabel(String label);
+ /**
+ * @return the label
+ */
+ public abstract String getLabel();
+
+ public EvaluationTemplate buildEvaluationTemplate(int id, Map<ConstraintKey, Set<String>> dependencies, IDegreeFactory factory) {
+ Set<String> deps;
+
+ String label = this.getLabel();
+ Set<String> aliasedDeps = null;
+ if (dependencies != null && label != null) {
+ ConstraintKey tester = new ConstraintKey();
+ tester.setAlias(label);
+ aliasedDeps = dependencies.remove(tester);
+
+ if (aliasedDeps != null) {
+ ConstraintKey properKey = this.getConstraintKey();
+ Set<String> previousDeps = dependencies.remove(properKey);
+
+ if (previousDeps != null)
+ aliasedDeps.addAll(previousDeps);
+
+ properKey.setAlias(label);
+
+ dependencies.put(properKey, aliasedDeps);
+ }
+ }
+
+
+ if (dependencies == null)
+ deps = Collections.emptySet();
+ else
+ deps = dependencies.get(this.getConstraintKey());
+
+
+
+ this.template = new SingleEvaluationTemplate(id,this.getConstraintKey(),deps,factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+ return template;
+ }
+
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/OrConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/OrConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/OrConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -55,9 +55,17 @@
public EvaluationTemplate buildEvaluationTemplate(int id, Map<ConstraintKey, Set<String>> dependencies, IDegreeFactory factory) {
- //BUILD A COMPOSITE TEMPLATE
+ //BUILD A COMPOSITE TEMPLATE
int N = this.getAlphaConstraints().length + this.getBetaConstraints().length;
- CompositeEvaluationTemplate temp = new CompositeEvaluationTemplate(id,this.getConstraintKey(),dependencies.get(this.getConstraintKey()),N,factory.getOrOperator(),factory.getMergeStrategy(),factory.getNullHandlingStrategy());
+
+ setOperator(factory.getOrOperator(this.getParams()));
+ CompositeEvaluationTemplate temp = new CompositeEvaluationTemplate(id,
+ this.getConstraintKey(),
+ dependencies.get(this.getConstraintKey()),
+ N,
+ getOperator(),
+ factory.getMergeStrategy(),
+ factory.getNullHandlingStrategy());
int Na = this.alphaConstraints.length;
int Nb = this.betaConstraints.length;
@@ -264,6 +272,7 @@
private ConstraintKey singletonKey = null;
+ private String label;
public ConstraintKey getConstraintKey() {
if (singletonKey == null) {
@@ -274,7 +283,8 @@
cks[j] = this.alphaConstraints[j].getConstraintKey();
for (int j = 0; j < Nb; j++)
cks[Na+j] = this.betaConstraints[j].getConstraintKey();
- singletonKey = new ConstraintKey("or",cks);
+ String opStr = this.getOperator().getName();
+ singletonKey = new ConstraintKey( opStr , cks);
}
return singletonKey;
}
@@ -294,4 +304,12 @@
return ans;
}
+ public String getLabel() {
+ return this.label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Pattern.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Pattern.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Pattern.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -50,6 +50,9 @@
private int index;
private PatternSource source;
private List<Behavior> behaviors;
+
+ private boolean isCutter = false;
+ private String label = null;
// this is the offset of the related fact inside a tuple. i.e:
// the position of the related fact inside the tuple;
@@ -377,4 +380,32 @@
}
this.behaviors.add( behavior );
}
+
+ /**
+ * @param isCutter the isCutter to set
+ */
+ public void setCutter(boolean isCutter) {
+ this.isCutter = isCutter;
+ }
+
+ /**
+ * @return the isCutter
+ */
+ public boolean isCutter() {
+ return isCutter;
+ }
+
+ /**
+ * @param label the label to set
+ */
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ /**
+ * @return the label
+ */
+ public String getLabel() {
+ return label;
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -226,6 +226,9 @@
final PredicateConstraint other = (PredicateConstraint) object;
+ if (this.isCutter() != other.isCutter())
+ return false;
+
if ( this.previousDeclarations.length != other.previousDeclarations.length ) {
return false;
}
@@ -447,6 +450,8 @@
private ConstraintKey singletonKey = null;
+
+ private String label;
public ConstraintKey getConstraintKey() {
if (singletonKey == null)
@@ -459,9 +464,23 @@
ans.add(getConstraintKey());
return ans;
}
+
+ public boolean isCutter() {
+ throw new UnsupportedOperationException("NOT DONE YET...");
+ }
+
+ public void setCutter(boolean cutter) {
+ throw new UnsupportedOperationException("NOT DONE YET...");
+ }
+ public String getLabel() {
+ return this.label;
+ }
+ public void setLabel(String label) {
+ this.label = label;
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -126,7 +126,7 @@
final ReturnValueConstraint other = (ReturnValueConstraint) object;
- return this.readAccessor.equals( other.readAccessor ) && this.restriction.equals( other.restriction );
+ return this.readAccessor.equals( other.readAccessor ) && this.restriction.equals( other.restriction ) && (this.isCutter() == other.isCutter());
}
public ContextEntry createContextEntry() {
@@ -250,10 +250,24 @@
ans.add(getConstraintKey());
return ans;
}
+
+ public boolean isCutter() {
+ return this.restriction.isCutter();
+ }
+
+ public void setCutter(boolean cutter) {
+ this.restriction.setCutter(cutter);
+ }
-
+ public String getLabel() {
+ return this.restriction.getLabel();
+ }
+ public void setLabel(String label) {
+ this.restriction.setLabel(label);
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -516,6 +516,10 @@
private ConstraintKey singletonKey = null;
+
+ private boolean cutter;
+
+ private String label;
public ConstraintKey getConstraintKey() {
if (singletonKey == null)
@@ -528,4 +532,21 @@
ans.add(getConstraintKey());
return ans;
}
+
+ public boolean isCutter() {
+ return cutter;
+ }
+
+ public void setCutter(boolean cut) {
+ this.cutter = cut;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Rule.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Rule.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/Rule.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -125,6 +125,13 @@
private Enabled enabled;
private Resource resource;
+
+ private String entailMode;
+
+ private String priorDescription;
+
+ private String filterStrategy;
+
private Map<ConstraintKey, Set<String>> dependencies;
@@ -716,4 +723,46 @@
public void setDependencies(Map<ConstraintKey, Set<String>> dependencies) {
this.dependencies = dependencies;
}
+
+ /**
+ * @param entailMode the entailMode to set
+ */
+ public void setEntailMode(String entailMode) {
+ this.entailMode = entailMode;
+ }
+
+ /**
+ * @return the entailMode
+ */
+ public String getEntailMode() {
+ return entailMode;
+ }
+
+ /**
+ * @param priorDescription the priorDescription to set
+ */
+ public void setPriorDescription(String priorDescription) {
+ this.priorDescription = priorDescription;
+ }
+
+ /**
+ * @return the priorDescription
+ */
+ public String getPriorDescription() {
+ return priorDescription;
+ }
+
+ /**
+ * @param filterStrategy the filterStrategy to set
+ */
+ public void setFilterStrategy(String filterStrategy) {
+ this.filterStrategy = filterStrategy;
+ }
+
+ /**
+ * @return the filterStrategy
+ */
+ public String getFilterStrategy() {
+ return filterStrategy;
+ }
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/RuleConditionElement.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/RuleConditionElement.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/RuleConditionElement.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -80,5 +80,8 @@
* @return
*/
public boolean isPatternScopeDelimiter();
+
+
+ public boolean isCutter();
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/VariableConstraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/VariableConstraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/VariableConstraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -203,7 +203,7 @@
final VariableConstraint other = (VariableConstraint) object;
- return this.fieldExtractor.equals( other.fieldExtractor ) && this.restriction.equals( other.restriction );
+ return this.fieldExtractor.equals( other.fieldExtractor ) && this.restriction.equals( other.restriction ) && (this.isCutter() == other.isCutter());
}
public Object clone() {
@@ -225,6 +225,21 @@
return ans;
}
+ public boolean isCutter() {
+ return this.restriction.isCutter();
+ }
+
+ public void setCutter(boolean cutter) {
+ this.restriction.setCutter(cutter);
+ }
+ public String getLabel() {
+ return this.restriction.getLabel();
+ }
+ public void setLabel(String label) {
+ this.restriction.setLabel(label);
+ }
+
+
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/VariableRestriction.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/VariableRestriction.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/rule/VariableRestriction.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -53,6 +53,8 @@
private Evaluator evaluator;
private InternalReadAccessor readAccessor;
+
+ private boolean cutter;
public VariableRestriction() {
}
@@ -153,6 +155,7 @@
public IDegree isSatisfiedCachedRight(LeftTuple tuple, ContextEntry context,
IDegreeFactory factory) {
+ Object o = tuple.get( this.declaration ) ;
return this.evaluator.evaluateCachedRight(
((VariableContextEntry) context).workingMemory,
(VariableContextEntry) context,
@@ -635,6 +638,8 @@
private ConstraintKey singletonKey = null;
+
+ private String label;
public ConstraintKey getConstraintKey() {
if (singletonKey == null) {
@@ -649,5 +654,28 @@
ans.add(getConstraintKey());
return ans;
}
+
+ /**
+ * @param isCutter the isCutter to set
+ */
+ public void setCutter(boolean isCutter) {
+ this.cutter = isCutter;
+ }
+ /**
+ * @return the isCutter
+ */
+ public boolean isCutter() {
+ return cutter;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+
}
\ No newline at end of file
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/runtime/rule/impl/AgendaImpl.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/runtime/rule/impl/AgendaImpl.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/runtime/rule/impl/AgendaImpl.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -46,4 +46,9 @@
return null;
}
}
+
+
+ public InternalAgenda getInnerAgenda() {
+ return agenda;
+ }
}
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/Constraint.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/Constraint.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/Constraint.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -84,6 +84,14 @@
public EvaluationTemplate getEvalTemplate(ConstraintKey key);
+
+
+ public boolean isCutter();
+
+ public void setCutter(boolean cutter);
+
+
+
/**
* An enum for Constraint Types
*/
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/KnowledgeHelper.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -133,6 +133,10 @@
public IDegree getConsequenceDegree();
+ public void setConsequenceDegree(IDegree deg);
+
+
+
public void inject(Object arg, String field, String op, String value);
public void inject(Object[] args, String field, String op, String value);
@@ -140,11 +144,25 @@
public void inject(Object arg, String key);
public void inject(Object[] args, String key);
+
+
+ public void injectKey(Object arg, String field, String op, String value);
+
+ public void injectKey(Object[] args, String field, String op, String value);
+
+ public void injectKey(Object arg, String key);
+
+ public void injectKey(Object[] args, String key);
+
+
+ public void injectId(Object arg, String key);
+
+ public void injectId(Object[] args, String key);
- public void setConsequenceDegree(IDegree deg);
+
public Evaluation getEvaluation();
public void setEvaluation(Evaluation eval);
Modified: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/Restriction.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/Restriction.java 2009-05-15 03:42:44 UTC (rev 26542)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/spi/Restriction.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -69,5 +69,13 @@
public ConstraintKey getConstraintKey();
public Collection<ConstraintKey> getAllConstraintKeys();
+
+ public boolean isCutter();
+
+ public void setCutter(boolean cut);
+
+ public void setLabel(String label);
+
+ public String getLabel();
}
Added: labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/util/DependencyExaminer.java
===================================================================
--- labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/util/DependencyExaminer.java (rev 0)
+++ labs/jbossrules/branches/DroolsChance/drools-core/src/main/java/org/drools/util/DependencyExaminer.java 2009-05-15 03:45:05 UTC (rev 26543)
@@ -0,0 +1,117 @@
+package org.drools.util;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.drools.common.AbstractWorkingMemory;
+import org.drools.common.DefaultFactHandle;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.LogicalDependency;
+import org.drools.common.TruthMaintenanceSystem;
+import org.drools.reteoo.ImperfectAgendaItem;
+import org.drools.rule.Rule;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.rule.FactHandle;
+import org.drools.runtime.rule.impl.AgendaImpl;
+import org.drools.spi.Activation;
+
+public class DependencyExaminer {
+
+
+ public static DepTreeNode getDependencies(StatefulKnowledgeSession session, FactHandle factHandle) {
+
+ TruthMaintenanceSystem tms = ((AbstractWorkingMemory) ((AgendaImpl) session.getAgenda()).getInnerAgenda().getWorkingMemory()).getTruthMaintenanceSystem();
+
+ return new DepTreeNode(factHandle,tms);
+
+ }
+
+
+ static class ActTreeNode {
+
+ private Activation activ;
+
+ private DepTreeNode[] args;
+
+ public ActTreeNode(Activation activation, TruthMaintenanceSystem tms) {
+
+ this.activ = activation;
+
+ Collection<? extends FactHandle> args = activation.getFactHandles();
+
+ int j = 0;
+ this.args = new DepTreeNode[args.size()];
+ for (FactHandle f : args)
+ this.args[j++] = new DepTreeNode(f,tms);
+
+ }
+
+ public String toString(int depth) {
+ StringBuilder tab = new StringBuilder();
+ for (int j = 0; j < depth; j++)
+ tab.append("\t");
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(tab).append("# ").append(activ.getRule().getName()).append(" ("+activ.hashCode()+")").append(" / "+ ((ImperfectAgendaItem) activ).getDegree()).append("\n");
+ for (int j = 0; j < args.length; j++) {
+ sb.append("\n").append(args[j].toString(depth+1));
+ }
+
+
+ return sb.toString();
+ }
+
+ }
+
+
+ public static class DepTreeNode {
+
+ private FactHandle object;
+ private ActTreeNode[] rules;
+
+ public DepTreeNode(FactHandle object, TruthMaintenanceSystem tms) {
+
+ this.object = object;
+
+ HashSet<LogicalDependency> deps = (HashSet<LogicalDependency>) tms.getJustifiedMap().get(((InternalFactHandle) object).getId());
+
+ int j = 0;
+ if (deps != null) {
+ rules = new ActTreeNode[deps.size()];
+ for (LogicalDependency dep : deps) {
+
+ rules[j++] = new ActTreeNode(dep.getJustifier(),tms);
+
+ }
+ } else {
+ rules = new ActTreeNode[0];
+ }
+
+ }
+
+
+
+ public String toString() {
+ return toString(0);
+ }
+
+ public String toString(int depth) {
+ StringBuilder tab = new StringBuilder();
+ for (int j = 0; j < depth; j++)
+ tab.append("\t");
+
+ StringBuilder sb = new StringBuilder();
+ DefaultFactHandle dfh = (DefaultFactHandle) object;
+ String objS = dfh.getObject() == null ? "null" : dfh.getObject().toString();
+ sb.append(tab).append("* ").append(objS).append("\n");
+ for (int j = 0; j < rules.length; j++) {
+ sb.append("\n").append(rules[j].toString(depth+1));
+ }
+
+
+ return sb.toString();
+ }
+
+ }
+
+}
More information about the jboss-svn-commits
mailing list