Index: /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java
===================================================================
--- /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java	(revision 1954)
+++ /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java	(revision 1955)
@@ -575,4 +575,336 @@
      * the same replacement order needs to be taken.
      */
+//    private void removeInterleavingTasksOld(RuleApplicationData appData) {
+//        // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+//        // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TEST IMPLEMENTATION >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+//        // dumpSortedCollectionOfSubsequences
+//        //     ("found task", appData.getLastFoundSubsequences().subsequences);
+//        // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+//        // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST IMPLEMENTATION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+//
+//        List<InterleavingSubsequence> interleavings;
+//        
+//        do {
+//            interleavings = getInterleavings(appData.getLastFoundSubsequences(), appData);
+//            
+//            if (interleavings.size() > 0) {
+//                // dumpSorted(interleavings);
+//
+//                // Console.traceln(Level.FINEST, "found " + interleavings.size() + " subsequences " +
+//                //                 "--> checking for most real interleavings");
+//                
+//                // we found interleaving subsequences. We need to decide for them, which to replace
+//                // first. For this, we need to remove some of them from the list of detected
+//                // subsequences in an ordered way to always have the same prioritization for
+//                // replacements. The ones to be removed are those with most interleavings.
+//                interleavings = getMostIntensiveInterleavings(interleavings);
+//                
+//                //dumpSorted(interleavings);
+//                
+//                if (interleavings.size() == 1) {
+//                    // Console.traceln(Level.FINEST, "found one most interleaving subsequence " +
+//                    //                 "--> removing it and checking for further interleavings");
+//
+//                    // we have exactly one most interleaving detected subsequence. In this case,
+//                    // we remove it from the list of found subsequences and check again, if their
+//                    // are remaining interleavings. If not, we have the final list of non
+//                    // interleaving subsequences to be replaced. The order or their replacement
+//                    // doesn't matter as they are not interleaving.
+//                    appData.getLastFoundSubsequences().remove
+//                        (interleavings.get(0).getSubsequence());
+//                    
+//                    continue;
+//                }
+//                else if (interleavings.size() == 0) {
+//                    // this should never happen
+//                    throw new RuntimeException("Implementation error: don't know how I got here");
+//                }
+//                
+//                // Console.traceln(Level.FINEST, "found " + interleavings.size() + " most " +
+//                //                 "interleaving subsequences --> checking which are most often a " +
+//                //                 "successor");
+//
+//                // there are several subsequences with the same amount of interleavings.
+//                // Check which of them is the most often a successor. This should be removed.
+//                interleavings = getMostInterleavingsAsSuccessor(interleavings);
+//                
+//                // dumpSorted(interleavings);
+//
+//                if (interleavings.size() == 1) {
+//                    //  Console.traceln(Level.FINEST, "found one interleaving subsequence being most " +
+//                    //                  "often a successor --> removing it and checking for further " +
+//                    //                  "interleavings");
+//
+//                    // we have exactly one interleaving subsequence that is most often a successor
+//                    // of the others. Remove it and try again to see if sufficient interleavings
+//                    // were cleared.
+//                    appData.getLastFoundSubsequences().remove
+//                        (interleavings.get(0).getSubsequence());
+//                    
+//                    continue;
+//                }
+//                else if (interleavings.size() == 0) {
+//                    // this should never happen
+//                    throw new RuntimeException("Implementation error: don't know how I got here");
+//                }
+//                
+//                // Console.traceln(Level.FINEST, "found " + interleavings.size() +
+//                //                 " most interleaving subsequences being most often a successor " +
+//                //                 "--> checking which is most seldom a predecessor");
+//
+//                // there are several subsequences with the same amount of interleavings being also
+//                // the same times a successor of another subsequence. Hence, check which of them is
+//                // the least often a predecessor. This should be removed.
+//                interleavings = getLeastInterleavingsAsPredecessor(interleavings);
+//                
+//                //dumpSorted(interleavings);
+//
+//                if (interleavings.size() == 1) {
+//                    // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " +
+//                    //                 "often a successor and most seldom a predecessor --> " +
+//                    //                 "removing it and checking for further interleavings");
+//
+//                    // we have exactly one interleaving subsequence that is most often a successor
+//                    // and most seldom a predecessor of the others. Remove it and try again to see
+//                    // if sufficient interleavings were cleared.
+//                    appData.getLastFoundSubsequences().remove
+//                        (interleavings.get(0).getSubsequence());
+//                    
+//                    continue;
+//                }
+//                else if (interleavings.size() == 0) {
+//                    // this should never happen
+//                    throw new RuntimeException("Implementation error: don't know how I got here");
+//                }
+//                
+//                // the remaining subsequences are interleaving the same amount of times and are
+//                // used the same amount of times as successors and as predecessors by all other
+//                // detected interleaving subsequences. Now lets check, which of them is mostly used
+//                // as successor and most seldom used as predecessor only considering the remaining
+//                // subsequences. If some of them do not interfere with the others, remove them and
+//                // try again to see if sufficient interleavings were cleared.
+//                
+//                // Console.traceln(Level.FINEST, "found " + interleavings.size() +
+//                //                 " most interleaving subsequences being most often a successor " +
+//                //                 "and most seldom a predecessor --> removing collision being not " +
+//                //                 "between themselves");
+//
+//                interleavings = removeCollisionsOfOtherSubsequences(interleavings);
+//                
+//                // dumpSorted(interleavings);
+//                
+//                // Console.traceln(Level.FINEST, "removed collisions of other subsequences not " +
+//                //                 "belonging to the remaining interleaving subsequences --> " +
+//                //                 "checking of the remaining interleaving are most often a " +
+//                //                 "successor of another one");
+//                
+//                interleavings = getMostInterleavingsAsSuccessor(interleavings);
+//                interleavings = removeCollisionsOfOtherSubsequences(interleavings);
+//                
+//                // dumpSorted(interleavings);
+//
+//                if (interleavings.size() == 1) {
+//                    // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " +
+//                    //                 "often a successor in comparison to the other remaining " +
+//                    //                 "interleavings --> removing it and checking for further " +
+//                    //                 "interleavings");
+//
+//                    appData.getLastFoundSubsequences().remove
+//                        (interleavings.get(0).getSubsequence());
+//                    
+//                    continue;
+//                }
+//                else if (interleavings.size() == 0) {
+//                    // this should never happen
+//                    throw new RuntimeException("Implementation error: don't know how I got here");
+//                }
+//                
+//                // Console.traceln(Level.FINEST, "found " + interleavings.size() +
+//                //                 " most interleaving subsequences being most often a successor in " +
+//                //                 "comparison to the other remaining interleavings --> checking " +
+//                //                 "which is most seldom a predecessor");
+//
+//                interleavings = getLeastInterleavingsAsPredecessor(interleavings);
+//                interleavings = removeCollisionsOfOtherSubsequences(interleavings);
+//                
+//                // dumpSorted(interleavings);
+//
+//                if (interleavings.size() == 1) {
+//                    // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " +
+//                    //                 "often a successor and most seldom a predecessor in " +
+//                    //                 "comparison to the other remaining interleavings --> " +
+//                    //                 "removing it and checking for further interleavings");
+//
+//                    appData.getLastFoundSubsequences().remove
+//                        (interleavings.get(0).getSubsequence());
+//                    
+//                    continue;
+//                }
+//                else if (interleavings.size() == 0) {
+//                    // this should never happen
+//                    throw new RuntimeException("Implementation error: don't know how I got here");
+//                }
+//                
+//                // Console.traceln(Level.FINEST, "found " + interleavings.size() +
+//                //                 " most interleaving subsequences being most often a successor " +
+//                //                 "and most seldom a predecessor in comparison to the other " +
+//                //                 "remaining interleavings --> this may happen if there are no " +
+//                //                 "collisions between them anymore. If so, remove all of them at " +
+//                //                 "once.");
+//
+//                int collisionCount = 0;
+//                
+//                for (InterleavingSubsequence subsequence : interleavings) {
+//                    collisionCount += subsequence.getCollisionCounter();
+//                }
+//                
+//                if (collisionCount == 0) {
+//                    // Console.traceln(Level.FINEST, "remaining interleaving subsequences have no " +
+//                    //                 "further collisions with each other --> removing all of them " +
+//                    //                 "and checking for further interleavings");
+//                    
+//                    for (InterleavingSubsequence subsequence : interleavings) {
+//                        appData.getLastFoundSubsequences().remove(subsequence.getSubsequence());
+//                    }
+//                    
+//                    continue;
+//                }
+//
+//                // Console.traceln(Level.FINEST, "remaining interleaving subsequences still have " +
+//                //                 "collisions with each other --> decide based on their occurrences" +
+//                //                 " in the sessions (remove those, coming later in comparison to " +
+//                //                 "the others)");
+//                
+//                // determine the predecessor collisions being the last in all sessions. Those
+//                // collisions show the interleaving subsequence occurring last 
+//                Map<IUserSession, Collision> sessions =
+//                    new IdentityHashMap<IUserSession, Collision>();
+//                
+//                for (InterleavingSubsequence interleaving : interleavings) {
+//                    for (Collision coll : interleaving.getPredecessorCollisions()) {
+//                        Collision maxPosColl = sessions.get(coll.getLocation().getSession());
+//                        
+//                        if ((maxPosColl == null) ||
+//                            (maxPosColl.getLocation().getIndex() < coll.getLocation().getIndex()))
+//                        {
+//                            sessions.put(coll.getLocation().getSession(), coll);
+//                        }
+//                    }
+//                }
+//                
+//                // determine, which of the subsequences occurs most often as the last one
+//                // interleaving with another
+//                Map<Subsequence, Integer> lastOccurrenceCounters =
+//                    new IdentityHashMap<Subsequence, Integer>();
+//                
+//                for (Collision coll : sessions.values()) {
+//                    Integer counter = lastOccurrenceCounters.get(coll.getSubsequence());
+//                    
+//                    if (counter == null) {
+//                        lastOccurrenceCounters.put(coll.getSubsequence(), 1);
+//                    }
+//                    else {
+//                        lastOccurrenceCounters.put(coll.getSubsequence(), counter + 1);
+//                    }
+//                }
+//                
+//                int maxCounter = 0;
+//                Subsequence toRemove = null;
+//                
+//                for (Map.Entry<Subsequence, Integer> entry : lastOccurrenceCounters.entrySet()) {
+//                    if (entry.getValue() > maxCounter) {
+//                        maxCounter = entry.getValue();
+//                        toRemove = entry.getKey();
+//                    }
+//                    else if (entry.getValue() == maxCounter) {
+//                        // we can not decide again
+//                        toRemove = null;
+//                        break;
+//                    }
+//                }
+//                
+//                if (toRemove != null) {
+//                    // Console.traceln(Level.FINEST, "one of the remaining interleaving subsequences" +
+//                    //                 " is most often the last to occur --> removing it and " +
+//                    //                 "checking for further interleavings");
+//            
+//                    appData.getLastFoundSubsequences().remove(toRemove);
+//                    continue;
+//                }
+//                
+//                // checking now, if there is one sequence, having the lowest index for any of
+//                // its collisions and preserve it. If there are several ones with the same minimum
+//                // index, check if they are independent. If not, throw an exception
+//                int minPosInAnySequence = Integer.MAX_VALUE;
+//                List<InterleavingSubsequence> subsequencesWithMinPos = new LinkedList<>();
+//                
+//                for (InterleavingSubsequence interleaving : interleavings) {
+//                    for (Collision collision : interleaving.getSuccessorCollisions()) {
+//                        if (minPosInAnySequence > collision.getLocation().getIndex()) {
+//                            minPosInAnySequence = collision.getLocation().getIndex();
+//                            subsequencesWithMinPos.clear();
+//                        }
+//                        
+//                        if (minPosInAnySequence == collision.getLocation().getIndex()) {
+//                            // several have the same min pos --> undecidable which to prefer
+//                            subsequencesWithMinPos.add(interleaving);
+//                        }
+//                    }
+//                }
+//                
+//                if (subsequencesWithMinPos.size() > 0) {
+//                    List<Subsequence> subsequencesToRemove = new LinkedList<Subsequence>();
+//                    
+//                    for (Subsequence candidate : appData.getLastFoundSubsequences()) {
+//                        boolean found = false;
+//                        
+//                        for (InterleavingSubsequence subsequenceWithMinPos : subsequencesWithMinPos)
+//                        {
+//                            if (candidate == subsequenceWithMinPos.getSubsequence()) {
+//                                found = true;
+//                            }
+//                        }
+//                        
+//                        if (!found) {
+//                            subsequencesToRemove.add(candidate);
+//                        }
+//                    }
+//                    
+//                    if (subsequencesToRemove.size() > 0) {
+//                        for (Subsequence candidate : subsequencesToRemove) {
+//                            appData.getLastFoundSubsequences().remove(candidate);
+//                        }
+//                    
+//                        continue;
+//                    }
+//                }
+//                
+//                // At this point, we can not decide anymore. But it should also not
+//                // happen. Even if two subsequences ab and ba one of them should be
+//                // more often a successor or predecessor than the other if they
+//                // directly follow each other. If not, it can not be decided, which of
+//                // them to replace first. Perhaps the one occurring more often as
+//                // the first in a session that the other. But this can be implemented
+//                // later.
+//                dumpSorted(interleavings, Level.SEVERE);
+//                
+//                throw new RuntimeException
+//                    ("can not decide which detected subsequence to replace first.");
+//            }
+//        }
+//        while (interleavings.size() > 0);
+//
+//        // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+//        // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TEST IMPLEMENTATION >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+//        // dumpSortedCollectionOfSubsequences
+//        //    ("to replace", appData.getLastFoundSubsequences().subsequences);
+//        // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+//        // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST IMPLEMENTATION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+//    }
+
+    /**
+     * from the last found tasks, sort out those that interleave with each other as for them always
+     * the same replacement order needs to be taken.
+     */
     private void removeInterleavingTasks(RuleApplicationData appData) {
         // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -602,15 +934,13 @@
                 //dumpSorted(interleavings);
                 
-                if (interleavings.size() == 1) {
-                    // Console.traceln(Level.FINEST, "found one most interleaving subsequence " +
-                    //                 "--> removing it and checking for further interleavings");
-
-                    // we have exactly one most interleaving detected subsequence. In this case,
-                    // we remove it from the list of found subsequences and check again, if their
-                    // are remaining interleavings. If not, we have the final list of non
-                    // interleaving subsequences to be replaced. The order or their replacement
-                    // doesn't matter as they are not interleaving.
-                    appData.getLastFoundSubsequences().remove
-                        (interleavings.get(0).getSubsequence());
+                if (interleavings.size() < appData.getLastFoundSubsequences().size()) {
+                    // Console.traceln(Level.FINEST, "found most interleaving subsequences " +
+                    //                 "--> removing them and checking for further interleavings");
+
+                    // we have most interleaving subsequences. As these are less than all detected
+                    // subsequences, we remove them and check if there are remaining interleavings.
+                    for (InterleavingSubsequence interleaving : interleavings) {
+                        appData.getLastFoundSubsequences().remove(interleaving.getSubsequence());
+                    }
                     
                     continue;
@@ -625,20 +955,22 @@
                 //                 "successor");
 
-                // there are several subsequences with the same amount of interleavings.
-                // Check which of them is the most often a successor. This should be removed.
+                // all detected subsequences are also interleaving with the same amount of time
+                // check, which of them is most often the successor in a collision
+                interleavings = removeCollisionsOfOtherSubsequences(interleavings);
                 interleavings = getMostInterleavingsAsSuccessor(interleavings);
                 
                 // dumpSorted(interleavings);
 
-                if (interleavings.size() == 1) {
-                    //  Console.traceln(Level.FINEST, "found one interleaving subsequence being most " +
-                    //                  "often a successor --> removing it and checking for further " +
+                if (interleavings.size() < appData.getLastFoundSubsequences().size()) {
+                    //  Console.traceln(Level.FINEST, "found interleaving subsequences being most " +
+                    //                  "often a successor --> removing them and checking for further " +
                     //                  "interleavings");
 
-                    // we have exactly one interleaving subsequence that is most often a successor
-                    // of the others. Remove it and try again to see if sufficient interleavings
-                    // were cleared.
-                    appData.getLastFoundSubsequences().remove
-                        (interleavings.get(0).getSubsequence());
+                    // we have interleaving subsequences that are most often a successor
+                    // of the others. As they are less than all detected subsequences, remove them
+                    // and try again to see if sufficient interleavings were cleared.
+                    for (InterleavingSubsequence interleaving : interleavings) {
+                        appData.getLastFoundSubsequences().remove(interleaving.getSubsequence());
+                    }
                     
                     continue;
@@ -653,21 +985,24 @@
                 //                 "--> checking which is most seldom a predecessor");
 
-                // there are several subsequences with the same amount of interleavings being also
+                // all detected subsequences have the same amount of interleavings being also
                 // the same times a successor of another subsequence. Hence, check which of them is
                 // the least often a predecessor. This should be removed.
+                interleavings = removeCollisionsOfOtherSubsequences(interleavings);
                 interleavings = getLeastInterleavingsAsPredecessor(interleavings);
                 
                 //dumpSorted(interleavings);
 
-                if (interleavings.size() == 1) {
-                    // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " +
+                if (interleavings.size() < appData.getLastFoundSubsequences().size()) {
+                    // Console.traceln(Level.FINEST, "found interleaving subsequences being most " +
                     //                 "often a successor and most seldom a predecessor --> " +
-                    //                 "removing it and checking for further interleavings");
-
-                    // we have exactly one interleaving subsequence that is most often a successor
-                    // and most seldom a predecessor of the others. Remove it and try again to see
+                    //                 "removing them and checking for further interleavings");
+
+                    // we have interleaving subsequences that are most often a successor
+                    // and most seldom a predecessor of the others. As they are less than all
+                    // detected subsequences, remove them and try again to see
                     // if sufficient interleavings were cleared.
-                    appData.getLastFoundSubsequences().remove
-                        (interleavings.get(0).getSubsequence());
+                    for (InterleavingSubsequence interleaving : interleavings) {
+                        appData.getLastFoundSubsequences().remove(interleaving.getSubsequence());
+                    }
                     
                     continue;
@@ -680,202 +1015,73 @@
                 // the remaining subsequences are interleaving the same amount of times and are
                 // used the same amount of times as successors and as predecessors by all other
-                // detected interleaving subsequences. Now lets check, which of them is mostly used
-                // as successor and most seldom used as predecessor only considering the remaining
-                // subsequences. If some of them do not interfere with the others, remove them and
-                // try again to see if sufficient interleavings were cleared.
-                
-                // Console.traceln(Level.FINEST, "found " + interleavings.size() +
-                //                 " most interleaving subsequences being most often a successor " +
-                //                 "and most seldom a predecessor --> removing collision being not " +
-                //                 "between themselves");
-
-                interleavings = removeCollisionsOfOtherSubsequences(interleavings);
-                
-                // dumpSorted(interleavings);
-                
-                // Console.traceln(Level.FINEST, "removed collisions of other subsequences not " +
-                //                 "belonging to the remaining interleaving subsequences --> " +
-                //                 "checking of the remaining interleaving are most often a " +
-                //                 "successor of another one");
-                
-                interleavings = getMostInterleavingsAsSuccessor(interleavings);
-                interleavings = removeCollisionsOfOtherSubsequences(interleavings);
-                
-                // dumpSorted(interleavings);
-
-                if (interleavings.size() == 1) {
-                    // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " +
-                    //                 "often a successor in comparison to the other remaining " +
-                    //                 "interleavings --> removing it and checking for further " +
-                    //                 "interleavings");
-
-                    appData.getLastFoundSubsequences().remove
-                        (interleavings.get(0).getSubsequence());
-                    
-                    continue;
-                }
-                else if (interleavings.size() == 0) {
-                    // this should never happen
-                    throw new RuntimeException("Implementation error: don't know how I got here");
-                }
-                
-                // Console.traceln(Level.FINEST, "found " + interleavings.size() +
-                //                 " most interleaving subsequences being most often a successor in " +
-                //                 "comparison to the other remaining interleavings --> checking " +
-                //                 "which is most seldom a predecessor");
-
-                interleavings = getLeastInterleavingsAsPredecessor(interleavings);
-                interleavings = removeCollisionsOfOtherSubsequences(interleavings);
-                
-                // dumpSorted(interleavings);
-
-                if (interleavings.size() == 1) {
-                    // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " +
-                    //                 "often a successor and most seldom a predecessor in " +
-                    //                 "comparison to the other remaining interleavings --> " +
-                    //                 "removing it and checking for further interleavings");
-
-                    appData.getLastFoundSubsequences().remove
-                        (interleavings.get(0).getSubsequence());
-                    
-                    continue;
-                }
-                else if (interleavings.size() == 0) {
-                    // this should never happen
-                    throw new RuntimeException("Implementation error: don't know how I got here");
-                }
+                // detected interleaving subsequences. 
                 
                 // Console.traceln(Level.FINEST, "found " + interleavings.size() +
                 //                 " most interleaving subsequences being most often a successor " +
                 //                 "and most seldom a predecessor in comparison to the other " +
-                //                 "remaining interleavings --> this may happen if there are no " +
-                //                 "collisions between them anymore. If so, remove all of them at " +
-                //                 "once.");
-
-                int collisionCount = 0;
-                
-                for (InterleavingSubsequence subsequence : interleavings) {
-                    collisionCount += subsequence.getCollisionCounter();
-                }
-                
-                if (collisionCount == 0) {
-                    // Console.traceln(Level.FINEST, "remaining interleaving subsequences have no " +
-                    //                 "further collisions with each other --> removing all of them " +
-                    //                 "and checking for further interleavings");
+                //                 "remaining interleavings --> decide based on their occurrences" +
+                //                 " in the sessions (remove those, coming later in comparison to " +
+                //                 "the others)");
+                
+                // determine the subsequences whose sum of the indexes of collisions is smallest or
+                // who has the smallest collision index in all sessions and remove all others
+                int overallMinSumOfCollisionIndexes = Integer.MAX_VALUE;
+                int overallMinimalCollisionIndex = Integer.MAX_VALUE;
+                InterleavingSubsequence interleavingWithMinSum = null;
+                InterleavingSubsequence interleavingWithMinIndex = null;
+                
+                for (InterleavingSubsequence interleaving : interleavings) {
+                    int sumOfCollisionIndexes = 0;
+                    int minimalCollisionIndex = Integer.MAX_VALUE;
                     
-                    for (InterleavingSubsequence subsequence : interleavings) {
-                        appData.getLastFoundSubsequences().remove(subsequence.getSubsequence());
+                    for (Collision coll : interleaving.getPredecessorCollisions()) {
+                        sumOfCollisionIndexes += coll.getLocation().getIndex();
+                        minimalCollisionIndex =
+                            Math.min(minimalCollisionIndex, coll.getLocation().getIndex());
+                    }
+                    
+                    for (Collision coll : interleaving.getSuccessorCollisions()) {
+                        sumOfCollisionIndexes += coll.getLocation().getIndex();
+                        minimalCollisionIndex =
+                            Math.min(minimalCollisionIndex, coll.getLocation().getIndex());
+                    }
+                    
+                    if (overallMinSumOfCollisionIndexes > sumOfCollisionIndexes) {
+                        interleavingWithMinSum = interleaving;
+                        overallMinSumOfCollisionIndexes = sumOfCollisionIndexes;
+                    }
+                    else if (overallMinSumOfCollisionIndexes == sumOfCollisionIndexes) {
+                        // cannot decide between already found and new one
+                        interleavingWithMinSum = null;
+                    }
+                    
+                    if (overallMinimalCollisionIndex > minimalCollisionIndex) {
+                        interleavingWithMinIndex = interleaving;
+                        overallMinimalCollisionIndex = minimalCollisionIndex;
+                    }
+                    else if (overallMinimalCollisionIndex == minimalCollisionIndex) {
+                        // cannot decide between already found and new one
+                        interleavingWithMinIndex = null;
+                    }
+                }
+                
+                if (interleavingWithMinSum != null) {
+                    for (InterleavingSubsequence interleaving : interleavings) {
+                        if (interleaving != interleavingWithMinSum) {
+                            appData.getLastFoundSubsequences().remove(interleaving.getSubsequence());
+                        }
                     }
                     
                     continue;
                 }
-
-                // Console.traceln(Level.FINEST, "remaining interleaving subsequences still have " +
-                //                 "collisions with each other --> decide based on their occurrences" +
-                //                 " in the sessions (remove those, coming later in comparison to " +
-                //                 "the others)");
-                
-                // determine the predecessor collisions being the last in all sessions. Those
-                // collisions show the interleaving subsequence occurring last 
-                Map<IUserSession, Collision> sessions =
-                    new IdentityHashMap<IUserSession, Collision>();
-                
-                for (InterleavingSubsequence interleaving : interleavings) {
-                    for (Collision coll : interleaving.getPredecessorCollisions()) {
-                        Collision maxPosColl = sessions.get(coll.getLocation().getSession());
-                        
-                        if ((maxPosColl == null) ||
-                            (maxPosColl.getLocation().getIndex() < coll.getLocation().getIndex()))
-                        {
-                            sessions.put(coll.getLocation().getSession(), coll);
+                
+                if (interleavingWithMinIndex != null) {
+                    for (InterleavingSubsequence interleaving : interleavings) {
+                        if (interleaving != interleavingWithMinIndex) {
+                            appData.getLastFoundSubsequences().remove(interleaving.getSubsequence());
                         }
                     }
-                }
-                
-                // determine, which of the subsequences occurs most often as the last one
-                // interleaving with another
-                Map<Subsequence, Integer> lastOccurrenceCounters =
-                    new IdentityHashMap<Subsequence, Integer>();
-                
-                for (Collision coll : sessions.values()) {
-                    Integer counter = lastOccurrenceCounters.get(coll.getSubsequence());
                     
-                    if (counter == null) {
-                        lastOccurrenceCounters.put(coll.getSubsequence(), 1);
-                    }
-                    else {
-                        lastOccurrenceCounters.put(coll.getSubsequence(), counter + 1);
-                    }
-                }
-                
-                int maxCounter = 0;
-                Subsequence toRemove = null;
-                
-                for (Map.Entry<Subsequence, Integer> entry : lastOccurrenceCounters.entrySet()) {
-                    if (entry.getValue() > maxCounter) {
-                        maxCounter = entry.getValue();
-                        toRemove = entry.getKey();
-                    }
-                    else if (entry.getValue() == maxCounter) {
-                        // we can not decide again
-                        toRemove = null;
-                        break;
-                    }
-                }
-                
-                if (toRemove != null) {
-                    // Console.traceln(Level.FINEST, "one of the remaining interleaving subsequences" +
-                    //                 " is most often the last to occur --> removing it and " +
-                    //                 "checking for further interleavings");
-            
-                    appData.getLastFoundSubsequences().remove(toRemove);
                     continue;
-                }
-                
-                // checking now, if there is one sequence, having the lowest index for any of
-                // its collisions and preserve it. If there are several ones with the same minimum
-                // index, check if they are independent. If not, throw an exception
-                int minPosInAnySequence = Integer.MAX_VALUE;
-                List<InterleavingSubsequence> subsequencesWithMinPos = new LinkedList<>();
-                
-                for (InterleavingSubsequence interleaving : interleavings) {
-                    for (Collision collision : interleaving.getSuccessorCollisions()) {
-                        if (minPosInAnySequence > collision.getLocation().getIndex()) {
-                            minPosInAnySequence = collision.getLocation().getIndex();
-                            subsequencesWithMinPos.clear();
-                        }
-                        
-                        if (minPosInAnySequence == collision.getLocation().getIndex()) {
-                            // several have the same min pos --> undecidable which to prefer
-                            subsequencesWithMinPos.add(interleaving);
-                        }
-                    }
-                }
-                
-                if (subsequencesWithMinPos.size() > 0) {
-                    List<Subsequence> subsequencesToRemove = new LinkedList<Subsequence>();
-                    
-                    for (Subsequence candidate : appData.getLastFoundSubsequences()) {
-                        boolean found = false;
-                        
-                        for (InterleavingSubsequence subsequenceWithMinPos : subsequencesWithMinPos)
-                        {
-                            if (candidate == subsequenceWithMinPos.getSubsequence()) {
-                                found = true;
-                            }
-                        }
-                        
-                        if (!found) {
-                            subsequencesToRemove.add(candidate);
-                        }
-                    }
-                    
-                    if (subsequencesToRemove.size() > 0) {
-                        for (Subsequence candidate : subsequencesToRemove) {
-                            appData.getLastFoundSubsequences().remove(candidate);
-                        }
-                    
-                        continue;
-                    }
                 }
                 
@@ -885,5 +1091,5 @@
                 // directly follow each other. If not, it can not be decided, which of
                 // them to replace first. Perhaps the one occurring more often as
-                // the first in a session that the other. But this can be implemented
+                // the first in a session than the other. But this can be implemented
                 // later.
                 dumpSorted(interleavings, Level.SEVERE);
@@ -2152,7 +2358,7 @@
          * @return the subsequence
          */
-        private Subsequence getSubsequence() {
-            return subsequence;
-        }
+//        private Subsequence getSubsequence() {
+//            return subsequence;
+//        }
 
         /* (non-Javadoc)
