ReferenceEdge edge = edgeItr.next();
D_i = D_i.union( edge.getBeta() );
}
+ D_i = D_i.exhaustiveArityCombinations();
paramIndex2rewriteD.put( paramIndex, D_i );
}
Iterator<TokenTupleSet> ttsItr = rules.iterator();
while( ttsItr.hasNext() ) {
TokenTupleSet tts = ttsItr.next();
- r0 = r0.union( tts.simpleRewriteToken( tokenToRewrite, hrn.getAlpha() ) );
+ r0 = r0.union( tts.rewriteToken( tokenToRewrite, hrn.getAlpha() ) );
}
ReachabilitySet r1 = new ReachabilitySet().makeCanonical();
TokenTuple tokenToRewriteJ = paramIndex2paramToken.get( paramIndexJ );
assert tokenToRewriteJ != null;
if( ttsIn.containsTuple( tokenToRewriteJ ) ) {
- ReachabilitySet r = ttsIn.exhaustiveRewriteToken( tokenToRewriteJ, D_j );
+ ReachabilitySet r = ttsIn.rewriteToken( tokenToRewriteJ, D_j );
Iterator<TokenTupleSet> ttsItr = r.iterator();
while( ttsItr.hasNext() ) {
TokenTupleSet tts = ttsItr.next();
TokenTuple tokenStarToRewriteJ = paramIndex2paramTokenStar.get( paramIndexJ );
assert tokenStarToRewriteJ != null;
if( ttsIn.containsTuple( tokenStarToRewriteJ ) ) {
- ReachabilitySet r = ttsIn.exhaustiveRewriteToken( tokenStarToRewriteJ, D_j );
+ ReachabilitySet r = ttsIn.rewriteToken( tokenStarToRewriteJ, D_j );
Iterator<TokenTupleSet> ttsItr = r.iterator();
while( ttsItr.hasNext() ) {
TokenTupleSet tts = ttsItr.next();
}
+ public ReachabilitySet exhaustiveArityCombinations() {
+ ReachabilitySet rsOut = new ReachabilitySet();
+
+ int numDimensions = this.possibleReachabilities.size();
+
+ // add an extra digit to detect termination
+ int[] digits = new int[numDimensions+1];
+
+ int minArity = 0;
+ int maxArity = 2;
+
+ // start with the minimum possible coordinate
+ for( int i = 0; i < numDimensions+1; ++i ) {
+ digits[i] = minArity;
+ }
+
+ // and stop when the highest-ordered axis rolls above the minimum
+ while( digits[numDimensions] == minArity ) {
+
+ // spit out a "coordinate" made from these digits
+ TokenTupleSet ttsCoordinate = new TokenTupleSet();
+ Iterator<TokenTupleSet> ttsItr = this.iterator();
+ for( int i = 0; i < numDimensions; ++i ) {
+ assert ttsItr.hasNext();
+ TokenTupleSet ttsUnit = ttsItr.next();
+ for( int j = 0; j < digits[i]; ++j ) {
+ ttsCoordinate = ttsCoordinate.unionUpArity( ttsUnit );
+ }
+ }
+ rsOut = rsOut.add( ttsCoordinate.makeCanonical() );
+
+ // increment
+ for( int i = 0; i < numDimensions+1; ++i ) {
+ digits[i]++;
+ if( digits[i] > maxArity ) {
+ // this axis reached its max, so roll it back to min and increment next higher digit
+ digits[i] = minArity;
+
+ } else {
+ // this axis did not reach its max so we just enumerated a new unique coordinate, stop
+ break;
+ }
+ }
+ }
+
+ return rsOut.makeCanonical();
+ }
+
+
public boolean equals(Object o) {
if( o == null ) {
return false;
return ttsOut.makeCanonical();
}
+ public TokenTupleSet unionUpArity( TokenTupleSet ttsIn ) {
+ assert ttsIn != null;
+ TokenTupleSet ttsOut = new TokenTupleSet();
+
+ Iterator<TokenTuple> ttItr = this.iterator();
+ while( ttItr.hasNext() ) {
+ TokenTuple tt = ttItr.next();
+
+ if( ttsIn.containsToken( tt.getToken() ) ) {
+ ttsOut.tokenTuples.add(tt.increaseArity());
+ } else {
+ ttsOut.tokenTuples.add(tt);
+ }
+ }
+
+ ttItr = ttsIn.iterator();
+ while( ttItr.hasNext() ) {
+ TokenTuple tt = ttItr.next();
+
+ if( !ttsOut.containsToken(tt.getToken()) ) {
+ ttsOut.tokenTuples.add(tt);
+ }
+ }
+
+ return ttsOut.makeCanonical();
+ }
+
public TokenTupleSet add(TokenTuple tt) {
assert tt != null;
TokenTupleSet ttsOut = new TokenTupleSet(tt);
}
- public ReachabilitySet simpleRewriteToken( TokenTuple tokenToRewrite,
- ReachabilitySet replacements ) {
+ public ReachabilitySet rewriteToken( TokenTuple tokenToRewrite,
+ ReachabilitySet replacements ) {
ReachabilitySet rsOut = new ReachabilitySet().makeCanonical();
-
- if( !tokenTuples.contains( tokenToRewrite ) ) {
- rsOut = rsOut.add( this );
-
- } else {
- TokenTupleSet ttsMinusToken = new TokenTupleSet( this );
- ttsMinusToken.tokenTuples.remove( tokenToRewrite );
-
- Iterator<TokenTupleSet> replaceItr = replacements.iterator();
- while( replaceItr.hasNext() ) {
- TokenTupleSet replacement = replaceItr.next();
- TokenTupleSet replaced = new TokenTupleSet();
- replaced.tokenTuples.addAll( ttsMinusToken.tokenTuples );
- replaced.tokenTuples.addAll( replacement.tokenTuples );
- replaced = replaced.makeCanonical();
- rsOut = rsOut.add( replaced );
- }
- }
-
- return rsOut;
- }
-
-
- public ReachabilitySet exhaustiveRewriteToken( TokenTuple tokenToRewrite,
- ReachabilitySet replacements ) {
- ReachabilitySet rsOut = new ReachabilitySet().makeCanonical();
-
- /*
if( !tokenTuples.contains( tokenToRewrite ) ) {
rsOut = rsOut.add( this );
-
+
} else {
TokenTupleSet ttsMinusToken = new TokenTupleSet( this );
ttsMinusToken.tokenTuples.remove( tokenToRewrite );
-
+
Iterator<TokenTupleSet> replaceItr = replacements.iterator();
while( replaceItr.hasNext() ) {
TokenTupleSet replacement = replaceItr.next();
rsOut = rsOut.add( replaced );
}
}
- */
-
+
return rsOut;
}
-
+
public String toString() {
return tokenTuples.toString();
test( "cts1 == cts0?", true, cts1 == cts0 );
test( "cts1.hashCode() == cts0.hashCode()?", true, cts1.hashCode() == cts0.hashCode() );
+
+ TokenTuple tt173 = new TokenTuple( new Integer( 173 ), false, TokenTuple.ARITY_ONE ).makeCanonical();
+ TokenTuple tt174 = new TokenTuple( new Integer( 174 ), true, TokenTuple.ARITY_ONE ).makeCanonical();
+ TokenTuple tt174b = new TokenTuple( new Integer( 174 ), true, TokenTuple.ARITY_MANY ).makeCanonical();
+ TokenTuple tt177 = new TokenTuple( new Integer( 177 ), true, TokenTuple.ARITY_ONE ).makeCanonical();
+
+ TokenTupleSet tts3 = new TokenTupleSet().add( tt173 );
+ TokenTupleSet tts4 = new TokenTupleSet().add( tt174 );
+ TokenTupleSet tts7 = new TokenTupleSet().add( tt177 );
+ TokenTupleSet tts4b7 = new TokenTupleSet().add( tt174b ).add( tt177 );
+ TokenTupleSet tts43 = new TokenTupleSet().add( tt174 ).add( tt173 );
+
+ ReachabilitySet rs100 = new ReachabilitySet().add( tts3 ).add( tts4 ).add( tts7 ).add( tts4b7 ).add( tts43 );
+ ReachabilitySet rs101 = rs100.exhaustiveArityCombinations();
+
+ System.out.println( "#####################\nrs100 = \n"+rs100 );
+ System.out.println( "#####################\nrs101 = \n"+rs101 );
}
}