Index: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
===================================================================
--- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java	(revision 1559)
+++ branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java	(revision 1568)
@@ -30,4 +30,5 @@
 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.SmithWatermanRepeated;
 import de.ugoe.cs.autoquest.tasktrees.alignment.substitution.ObjectDistanceSubstitionMatrix;
+import de.ugoe.cs.autoquest.tasktrees.alignment.substitution.TriangleMatrix;
 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
@@ -156,39 +157,76 @@
 		// this is the real rule application. Loop while something is replaced.
 		SymbolMap<ITaskInstance, ITask> uniqueTasks = harmonizeEventTaskInstancesModel(appData);
+
 		ObjectDistanceSubstitionMatrix submat = new ObjectDistanceSubstitionMatrix(
 				uniqueTasks, 5);
 		submat.generate();
 
-		// good tests: 7/8 20/24
+		TriangleMatrix sequenceDistances = new TriangleMatrix(numberseqs.size());
+
 		for (int i = 0; i < numberseqs.size(); i++) {
+			NumberSequence ns1 = numberseqs.get(i);
+			//System.out.print("Sequence " + i + ": ");
+			//ns1.printSequence();
 			for (int j = 0; j < numberseqs.size(); j++) {
+				NumberSequence ns2 = numberseqs.get(j);
+
+				if (i != j) {
+					int smithWatermanThreshold = 10;
+
+					SmithWatermanRepeated twoSequences = new SmithWatermanRepeated(
+							ns1.getSequence(), ns2.getSequence(), submat,
+							smithWatermanThreshold);
+					SmithWatermanRepeated sameSequence1 = new SmithWatermanRepeated(
+							ns1.getSequence(), ns1.getSequence(), submat,
+							smithWatermanThreshold);
+					SmithWatermanRepeated sameSequence2 = new SmithWatermanRepeated(
+							ns2.getSequence(), ns2.getSequence(), submat,
+							smithWatermanThreshold);
+					
+					SmithWatermanRepeated randomSequence = new SmithWatermanRepeated(
+							ns1.shuffle().getSequence(),ns2.shuffle().getSequence(),submat,smithWatermanThreshold);
+					//randomSequence.printDPMatrix();
+					//randomSequence.traceback();
+					
+					double score = twoSequences.getAlignmentScore();
+					// Scores of the sequence beeing aligned to itself
+					double sSelf1 = sameSequence1.getAlignmentScore();
+					double sSelf2 = sameSequence2.getAlignmentScore();
+
+					double sRand = randomSequence.getAlignmentScore();
+
+					double sMax = (sSelf1 + sSelf2) / 2;
+					double sEff = (score - sRand)/ (sMax - sRand);
+					double distance = -Math.log(sEff);
 				
-				NumberSequence ns1 = numberseqs.get(i);
-				NumberSequence ns2 = numberseqs.get(j);
-				
-				
-				
-				SmithWatermanRepeated sw = new SmithWatermanRepeated(
-						ns1.getSequence(), ns2.getSequence(), submat, 10);
-				
-				if(sw.getAlignmentScore() > 0)
-				{   
-					System.out.println("=================================================");
-					System.out.println("| Sequence " + String.format("%3d", i) +" Sequence " + String.format("%3d", j)  + "                     |");
-					System.out.println("=================================================");
-					//System.out.print("Sequence " + i + ": ");
-					//ns1.printSequence();
-					//System.out.print("Sequence " + j + ": ");
-					//ns2.printSequence();
-					//System.out.println("Max Scrore: " + sw.getMaxScore());
-					System.out.println("Alignment Score: " + sw.getAlignmentScore());
-					//sw.printDPMatrix();
-					sw.traceback();
-					System.out.println();
-					System.out.println();
-				}
-			}
-		}
-
+					System.out.println("Score: " + score + " sRand: " + sRand + " sMax: " + sMax + " sEff: " + sEff + " distance: " + distance);
+					
+					sequenceDistances.set(i,j,distance );
+
+					if (score > 0) {
+						/*
+						 * System.out.println(
+						 * "=================================================");
+						 * System.out.println("| Sequence " +
+						 * String.format("%3d", i) +" Sequence " +
+						 * String.format("%3d", j) + "                     |");
+						 * System.out.println(
+						 * "=================================================");
+						 * System.out.print("Sequence " + i + ": ");
+						 * ns1.printSequence(); System.out.print("Sequence " + j
+						 * + ": "); ns2.printSequence(); System.out.println();
+						 * //System.out.println("Max Scrore: " +
+						 * sw.getMaxScore());
+						 * System.out.println("Alignment Score: " +
+						 * sw.getAlignmentScore()); //sw.printDPMatrix();
+						 * sw.traceback(); System.out.println();
+						 * System.out.println();
+						 */
+					}
+				}
+			}
+		}
+		//System.out.println(sequenceDistances.toString());
+		
 		do {
 			System.out.println();
