Ignore:
Timestamp:
05/31/15 19:23:33 (9 years ago)
Author:
pharms
Message:
  • eased the selection process of which sublist to handle first
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java

    r1947 r1955  
    575575     * the same replacement order needs to be taken. 
    576576     */ 
     577//    private void removeInterleavingTasksOld(RuleApplicationData appData) { 
     578//        // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
     579//        // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TEST IMPLEMENTATION >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
     580//        // dumpSortedCollectionOfSubsequences 
     581//        //     ("found task", appData.getLastFoundSubsequences().subsequences); 
     582//        // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
     583//        // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST IMPLEMENTATION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
     584// 
     585//        List<InterleavingSubsequence> interleavings; 
     586//         
     587//        do { 
     588//            interleavings = getInterleavings(appData.getLastFoundSubsequences(), appData); 
     589//             
     590//            if (interleavings.size() > 0) { 
     591//                // dumpSorted(interleavings); 
     592// 
     593//                // Console.traceln(Level.FINEST, "found " + interleavings.size() + " subsequences " + 
     594//                //                 "--> checking for most real interleavings"); 
     595//                 
     596//                // we found interleaving subsequences. We need to decide for them, which to replace 
     597//                // first. For this, we need to remove some of them from the list of detected 
     598//                // subsequences in an ordered way to always have the same prioritization for 
     599//                // replacements. The ones to be removed are those with most interleavings. 
     600//                interleavings = getMostIntensiveInterleavings(interleavings); 
     601//                 
     602//                //dumpSorted(interleavings); 
     603//                 
     604//                if (interleavings.size() == 1) { 
     605//                    // Console.traceln(Level.FINEST, "found one most interleaving subsequence " + 
     606//                    //                 "--> removing it and checking for further interleavings"); 
     607// 
     608//                    // we have exactly one most interleaving detected subsequence. In this case, 
     609//                    // we remove it from the list of found subsequences and check again, if their 
     610//                    // are remaining interleavings. If not, we have the final list of non 
     611//                    // interleaving subsequences to be replaced. The order or their replacement 
     612//                    // doesn't matter as they are not interleaving. 
     613//                    appData.getLastFoundSubsequences().remove 
     614//                        (interleavings.get(0).getSubsequence()); 
     615//                     
     616//                    continue; 
     617//                } 
     618//                else if (interleavings.size() == 0) { 
     619//                    // this should never happen 
     620//                    throw new RuntimeException("Implementation error: don't know how I got here"); 
     621//                } 
     622//                 
     623//                // Console.traceln(Level.FINEST, "found " + interleavings.size() + " most " + 
     624//                //                 "interleaving subsequences --> checking which are most often a " + 
     625//                //                 "successor"); 
     626// 
     627//                // there are several subsequences with the same amount of interleavings. 
     628//                // Check which of them is the most often a successor. This should be removed. 
     629//                interleavings = getMostInterleavingsAsSuccessor(interleavings); 
     630//                 
     631//                // dumpSorted(interleavings); 
     632// 
     633//                if (interleavings.size() == 1) { 
     634//                    //  Console.traceln(Level.FINEST, "found one interleaving subsequence being most " + 
     635//                    //                  "often a successor --> removing it and checking for further " + 
     636//                    //                  "interleavings"); 
     637// 
     638//                    // we have exactly one interleaving subsequence that is most often a successor 
     639//                    // of the others. Remove it and try again to see if sufficient interleavings 
     640//                    // were cleared. 
     641//                    appData.getLastFoundSubsequences().remove 
     642//                        (interleavings.get(0).getSubsequence()); 
     643//                     
     644//                    continue; 
     645//                } 
     646//                else if (interleavings.size() == 0) { 
     647//                    // this should never happen 
     648//                    throw new RuntimeException("Implementation error: don't know how I got here"); 
     649//                } 
     650//                 
     651//                // Console.traceln(Level.FINEST, "found " + interleavings.size() + 
     652//                //                 " most interleaving subsequences being most often a successor " + 
     653//                //                 "--> checking which is most seldom a predecessor"); 
     654// 
     655//                // there are several subsequences with the same amount of interleavings being also 
     656//                // the same times a successor of another subsequence. Hence, check which of them is 
     657//                // the least often a predecessor. This should be removed. 
     658//                interleavings = getLeastInterleavingsAsPredecessor(interleavings); 
     659//                 
     660//                //dumpSorted(interleavings); 
     661// 
     662//                if (interleavings.size() == 1) { 
     663//                    // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " + 
     664//                    //                 "often a successor and most seldom a predecessor --> " + 
     665//                    //                 "removing it and checking for further interleavings"); 
     666// 
     667//                    // we have exactly one interleaving subsequence that is most often a successor 
     668//                    // and most seldom a predecessor of the others. Remove it and try again to see 
     669//                    // if sufficient interleavings were cleared. 
     670//                    appData.getLastFoundSubsequences().remove 
     671//                        (interleavings.get(0).getSubsequence()); 
     672//                     
     673//                    continue; 
     674//                } 
     675//                else if (interleavings.size() == 0) { 
     676//                    // this should never happen 
     677//                    throw new RuntimeException("Implementation error: don't know how I got here"); 
     678//                } 
     679//                 
     680//                // the remaining subsequences are interleaving the same amount of times and are 
     681//                // used the same amount of times as successors and as predecessors by all other 
     682//                // detected interleaving subsequences. Now lets check, which of them is mostly used 
     683//                // as successor and most seldom used as predecessor only considering the remaining 
     684//                // subsequences. If some of them do not interfere with the others, remove them and 
     685//                // try again to see if sufficient interleavings were cleared. 
     686//                 
     687//                // Console.traceln(Level.FINEST, "found " + interleavings.size() + 
     688//                //                 " most interleaving subsequences being most often a successor " + 
     689//                //                 "and most seldom a predecessor --> removing collision being not " + 
     690//                //                 "between themselves"); 
     691// 
     692//                interleavings = removeCollisionsOfOtherSubsequences(interleavings); 
     693//                 
     694//                // dumpSorted(interleavings); 
     695//                 
     696//                // Console.traceln(Level.FINEST, "removed collisions of other subsequences not " + 
     697//                //                 "belonging to the remaining interleaving subsequences --> " + 
     698//                //                 "checking of the remaining interleaving are most often a " + 
     699//                //                 "successor of another one"); 
     700//                 
     701//                interleavings = getMostInterleavingsAsSuccessor(interleavings); 
     702//                interleavings = removeCollisionsOfOtherSubsequences(interleavings); 
     703//                 
     704//                // dumpSorted(interleavings); 
     705// 
     706//                if (interleavings.size() == 1) { 
     707//                    // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " + 
     708//                    //                 "often a successor in comparison to the other remaining " + 
     709//                    //                 "interleavings --> removing it and checking for further " + 
     710//                    //                 "interleavings"); 
     711// 
     712//                    appData.getLastFoundSubsequences().remove 
     713//                        (interleavings.get(0).getSubsequence()); 
     714//                     
     715//                    continue; 
     716//                } 
     717//                else if (interleavings.size() == 0) { 
     718//                    // this should never happen 
     719//                    throw new RuntimeException("Implementation error: don't know how I got here"); 
     720//                } 
     721//                 
     722//                // Console.traceln(Level.FINEST, "found " + interleavings.size() + 
     723//                //                 " most interleaving subsequences being most often a successor in " + 
     724//                //                 "comparison to the other remaining interleavings --> checking " + 
     725//                //                 "which is most seldom a predecessor"); 
     726// 
     727//                interleavings = getLeastInterleavingsAsPredecessor(interleavings); 
     728//                interleavings = removeCollisionsOfOtherSubsequences(interleavings); 
     729//                 
     730//                // dumpSorted(interleavings); 
     731// 
     732//                if (interleavings.size() == 1) { 
     733//                    // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " + 
     734//                    //                 "often a successor and most seldom a predecessor in " + 
     735//                    //                 "comparison to the other remaining interleavings --> " + 
     736//                    //                 "removing it and checking for further interleavings"); 
     737// 
     738//                    appData.getLastFoundSubsequences().remove 
     739//                        (interleavings.get(0).getSubsequence()); 
     740//                     
     741//                    continue; 
     742//                } 
     743//                else if (interleavings.size() == 0) { 
     744//                    // this should never happen 
     745//                    throw new RuntimeException("Implementation error: don't know how I got here"); 
     746//                } 
     747//                 
     748//                // Console.traceln(Level.FINEST, "found " + interleavings.size() + 
     749//                //                 " most interleaving subsequences being most often a successor " + 
     750//                //                 "and most seldom a predecessor in comparison to the other " + 
     751//                //                 "remaining interleavings --> this may happen if there are no " + 
     752//                //                 "collisions between them anymore. If so, remove all of them at " + 
     753//                //                 "once."); 
     754// 
     755//                int collisionCount = 0; 
     756//                 
     757//                for (InterleavingSubsequence subsequence : interleavings) { 
     758//                    collisionCount += subsequence.getCollisionCounter(); 
     759//                } 
     760//                 
     761//                if (collisionCount == 0) { 
     762//                    // Console.traceln(Level.FINEST, "remaining interleaving subsequences have no " + 
     763//                    //                 "further collisions with each other --> removing all of them " + 
     764//                    //                 "and checking for further interleavings"); 
     765//                     
     766//                    for (InterleavingSubsequence subsequence : interleavings) { 
     767//                        appData.getLastFoundSubsequences().remove(subsequence.getSubsequence()); 
     768//                    } 
     769//                     
     770//                    continue; 
     771//                } 
     772// 
     773//                // Console.traceln(Level.FINEST, "remaining interleaving subsequences still have " + 
     774//                //                 "collisions with each other --> decide based on their occurrences" + 
     775//                //                 " in the sessions (remove those, coming later in comparison to " + 
     776//                //                 "the others)"); 
     777//                 
     778//                // determine the predecessor collisions being the last in all sessions. Those 
     779//                // collisions show the interleaving subsequence occurring last  
     780//                Map<IUserSession, Collision> sessions = 
     781//                    new IdentityHashMap<IUserSession, Collision>(); 
     782//                 
     783//                for (InterleavingSubsequence interleaving : interleavings) { 
     784//                    for (Collision coll : interleaving.getPredecessorCollisions()) { 
     785//                        Collision maxPosColl = sessions.get(coll.getLocation().getSession()); 
     786//                         
     787//                        if ((maxPosColl == null) || 
     788//                            (maxPosColl.getLocation().getIndex() < coll.getLocation().getIndex())) 
     789//                        { 
     790//                            sessions.put(coll.getLocation().getSession(), coll); 
     791//                        } 
     792//                    } 
     793//                } 
     794//                 
     795//                // determine, which of the subsequences occurs most often as the last one 
     796//                // interleaving with another 
     797//                Map<Subsequence, Integer> lastOccurrenceCounters = 
     798//                    new IdentityHashMap<Subsequence, Integer>(); 
     799//                 
     800//                for (Collision coll : sessions.values()) { 
     801//                    Integer counter = lastOccurrenceCounters.get(coll.getSubsequence()); 
     802//                     
     803//                    if (counter == null) { 
     804//                        lastOccurrenceCounters.put(coll.getSubsequence(), 1); 
     805//                    } 
     806//                    else { 
     807//                        lastOccurrenceCounters.put(coll.getSubsequence(), counter + 1); 
     808//                    } 
     809//                } 
     810//                 
     811//                int maxCounter = 0; 
     812//                Subsequence toRemove = null; 
     813//                 
     814//                for (Map.Entry<Subsequence, Integer> entry : lastOccurrenceCounters.entrySet()) { 
     815//                    if (entry.getValue() > maxCounter) { 
     816//                        maxCounter = entry.getValue(); 
     817//                        toRemove = entry.getKey(); 
     818//                    } 
     819//                    else if (entry.getValue() == maxCounter) { 
     820//                        // we can not decide again 
     821//                        toRemove = null; 
     822//                        break; 
     823//                    } 
     824//                } 
     825//                 
     826//                if (toRemove != null) { 
     827//                    // Console.traceln(Level.FINEST, "one of the remaining interleaving subsequences" + 
     828//                    //                 " is most often the last to occur --> removing it and " + 
     829//                    //                 "checking for further interleavings"); 
     830//             
     831//                    appData.getLastFoundSubsequences().remove(toRemove); 
     832//                    continue; 
     833//                } 
     834//                 
     835//                // checking now, if there is one sequence, having the lowest index for any of 
     836//                // its collisions and preserve it. If there are several ones with the same minimum 
     837//                // index, check if they are independent. If not, throw an exception 
     838//                int minPosInAnySequence = Integer.MAX_VALUE; 
     839//                List<InterleavingSubsequence> subsequencesWithMinPos = new LinkedList<>(); 
     840//                 
     841//                for (InterleavingSubsequence interleaving : interleavings) { 
     842//                    for (Collision collision : interleaving.getSuccessorCollisions()) { 
     843//                        if (minPosInAnySequence > collision.getLocation().getIndex()) { 
     844//                            minPosInAnySequence = collision.getLocation().getIndex(); 
     845//                            subsequencesWithMinPos.clear(); 
     846//                        } 
     847//                         
     848//                        if (minPosInAnySequence == collision.getLocation().getIndex()) { 
     849//                            // several have the same min pos --> undecidable which to prefer 
     850//                            subsequencesWithMinPos.add(interleaving); 
     851//                        } 
     852//                    } 
     853//                } 
     854//                 
     855//                if (subsequencesWithMinPos.size() > 0) { 
     856//                    List<Subsequence> subsequencesToRemove = new LinkedList<Subsequence>(); 
     857//                     
     858//                    for (Subsequence candidate : appData.getLastFoundSubsequences()) { 
     859//                        boolean found = false; 
     860//                         
     861//                        for (InterleavingSubsequence subsequenceWithMinPos : subsequencesWithMinPos) 
     862//                        { 
     863//                            if (candidate == subsequenceWithMinPos.getSubsequence()) { 
     864//                                found = true; 
     865//                            } 
     866//                        } 
     867//                         
     868//                        if (!found) { 
     869//                            subsequencesToRemove.add(candidate); 
     870//                        } 
     871//                    } 
     872//                     
     873//                    if (subsequencesToRemove.size() > 0) { 
     874//                        for (Subsequence candidate : subsequencesToRemove) { 
     875//                            appData.getLastFoundSubsequences().remove(candidate); 
     876//                        } 
     877//                     
     878//                        continue; 
     879//                    } 
     880//                } 
     881//                 
     882//                // At this point, we can not decide anymore. But it should also not 
     883//                // happen. Even if two subsequences ab and ba one of them should be 
     884//                // more often a successor or predecessor than the other if they 
     885//                // directly follow each other. If not, it can not be decided, which of 
     886//                // them to replace first. Perhaps the one occurring more often as 
     887//                // the first in a session that the other. But this can be implemented 
     888//                // later. 
     889//                dumpSorted(interleavings, Level.SEVERE); 
     890//                 
     891//                throw new RuntimeException 
     892//                    ("can not decide which detected subsequence to replace first."); 
     893//            } 
     894//        } 
     895//        while (interleavings.size() > 0); 
     896// 
     897//        // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
     898//        // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TEST IMPLEMENTATION >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
     899//        // dumpSortedCollectionOfSubsequences 
     900//        //    ("to replace", appData.getLastFoundSubsequences().subsequences); 
     901//        // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
     902//        // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST IMPLEMENTATION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
     903//    } 
     904 
     905    /** 
     906     * from the last found tasks, sort out those that interleave with each other as for them always 
     907     * the same replacement order needs to be taken. 
     908     */ 
    577909    private void removeInterleavingTasks(RuleApplicationData appData) { 
    578910        // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
     
    602934                //dumpSorted(interleavings); 
    603935                 
    604                 if (interleavings.size() == 1) { 
    605                     // Console.traceln(Level.FINEST, "found one most interleaving subsequence " + 
    606                     //                 "--> removing it and checking for further interleavings"); 
    607  
    608                     // we have exactly one most interleaving detected subsequence. In this case, 
    609                     // we remove it from the list of found subsequences and check again, if their 
    610                     // are remaining interleavings. If not, we have the final list of non 
    611                     // interleaving subsequences to be replaced. The order or their replacement 
    612                     // doesn't matter as they are not interleaving. 
    613                     appData.getLastFoundSubsequences().remove 
    614                         (interleavings.get(0).getSubsequence()); 
     936                if (interleavings.size() < appData.getLastFoundSubsequences().size()) { 
     937                    // Console.traceln(Level.FINEST, "found most interleaving subsequences " + 
     938                    //                 "--> removing them and checking for further interleavings"); 
     939 
     940                    // we have most interleaving subsequences. As these are less than all detected 
     941                    // subsequences, we remove them and check if there are remaining interleavings. 
     942                    for (InterleavingSubsequence interleaving : interleavings) { 
     943                        appData.getLastFoundSubsequences().remove(interleaving.getSubsequence()); 
     944                    } 
    615945                     
    616946                    continue; 
     
    625955                //                 "successor"); 
    626956 
    627                 // there are several subsequences with the same amount of interleavings. 
    628                 // Check which of them is the most often a successor. This should be removed. 
     957                // all detected subsequences are also interleaving with the same amount of time 
     958                // check, which of them is most often the successor in a collision 
     959                interleavings = removeCollisionsOfOtherSubsequences(interleavings); 
    629960                interleavings = getMostInterleavingsAsSuccessor(interleavings); 
    630961                 
    631962                // dumpSorted(interleavings); 
    632963 
    633                 if (interleavings.size() == 1) { 
    634                     //  Console.traceln(Level.FINEST, "found one interleaving subsequence being most " + 
    635                     //                  "often a successor --> removing it and checking for further " + 
     964                if (interleavings.size() < appData.getLastFoundSubsequences().size()) { 
     965                    //  Console.traceln(Level.FINEST, "found interleaving subsequences being most " + 
     966                    //                  "often a successor --> removing them and checking for further " + 
    636967                    //                  "interleavings"); 
    637968 
    638                     // we have exactly one interleaving subsequence that is most often a successor 
    639                     // of the others. Remove it and try again to see if sufficient interleavings 
    640                     // were cleared. 
    641                     appData.getLastFoundSubsequences().remove 
    642                         (interleavings.get(0).getSubsequence()); 
     969                    // we have interleaving subsequences that are most often a successor 
     970                    // of the others. As they are less than all detected subsequences, remove them 
     971                    // and try again to see if sufficient interleavings were cleared. 
     972                    for (InterleavingSubsequence interleaving : interleavings) { 
     973                        appData.getLastFoundSubsequences().remove(interleaving.getSubsequence()); 
     974                    } 
    643975                     
    644976                    continue; 
     
    653985                //                 "--> checking which is most seldom a predecessor"); 
    654986 
    655                 // there are several subsequences with the same amount of interleavings being also 
     987                // all detected subsequences have the same amount of interleavings being also 
    656988                // the same times a successor of another subsequence. Hence, check which of them is 
    657989                // the least often a predecessor. This should be removed. 
     990                interleavings = removeCollisionsOfOtherSubsequences(interleavings); 
    658991                interleavings = getLeastInterleavingsAsPredecessor(interleavings); 
    659992                 
    660993                //dumpSorted(interleavings); 
    661994 
    662                 if (interleavings.size() == 1) { 
    663                     // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " + 
     995                if (interleavings.size() < appData.getLastFoundSubsequences().size()) { 
     996                    // Console.traceln(Level.FINEST, "found interleaving subsequences being most " + 
    664997                    //                 "often a successor and most seldom a predecessor --> " + 
    665                     //                 "removing it and checking for further interleavings"); 
    666  
    667                     // we have exactly one interleaving subsequence that is most often a successor 
    668                     // and most seldom a predecessor of the others. Remove it and try again to see 
     998                    //                 "removing them and checking for further interleavings"); 
     999 
     1000                    // we have interleaving subsequences that are most often a successor 
     1001                    // and most seldom a predecessor of the others. As they are less than all 
     1002                    // detected subsequences, remove them and try again to see 
    6691003                    // if sufficient interleavings were cleared. 
    670                     appData.getLastFoundSubsequences().remove 
    671                         (interleavings.get(0).getSubsequence()); 
     1004                    for (InterleavingSubsequence interleaving : interleavings) { 
     1005                        appData.getLastFoundSubsequences().remove(interleaving.getSubsequence()); 
     1006                    } 
    6721007                     
    6731008                    continue; 
     
    6801015                // the remaining subsequences are interleaving the same amount of times and are 
    6811016                // used the same amount of times as successors and as predecessors by all other 
    682                 // detected interleaving subsequences. Now lets check, which of them is mostly used 
    683                 // as successor and most seldom used as predecessor only considering the remaining 
    684                 // subsequences. If some of them do not interfere with the others, remove them and 
    685                 // try again to see if sufficient interleavings were cleared. 
    686                  
    687                 // Console.traceln(Level.FINEST, "found " + interleavings.size() + 
    688                 //                 " most interleaving subsequences being most often a successor " + 
    689                 //                 "and most seldom a predecessor --> removing collision being not " + 
    690                 //                 "between themselves"); 
    691  
    692                 interleavings = removeCollisionsOfOtherSubsequences(interleavings); 
    693                  
    694                 // dumpSorted(interleavings); 
    695                  
    696                 // Console.traceln(Level.FINEST, "removed collisions of other subsequences not " + 
    697                 //                 "belonging to the remaining interleaving subsequences --> " + 
    698                 //                 "checking of the remaining interleaving are most often a " + 
    699                 //                 "successor of another one"); 
    700                  
    701                 interleavings = getMostInterleavingsAsSuccessor(interleavings); 
    702                 interleavings = removeCollisionsOfOtherSubsequences(interleavings); 
    703                  
    704                 // dumpSorted(interleavings); 
    705  
    706                 if (interleavings.size() == 1) { 
    707                     // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " + 
    708                     //                 "often a successor in comparison to the other remaining " + 
    709                     //                 "interleavings --> removing it and checking for further " + 
    710                     //                 "interleavings"); 
    711  
    712                     appData.getLastFoundSubsequences().remove 
    713                         (interleavings.get(0).getSubsequence()); 
    714                      
    715                     continue; 
    716                 } 
    717                 else if (interleavings.size() == 0) { 
    718                     // this should never happen 
    719                     throw new RuntimeException("Implementation error: don't know how I got here"); 
    720                 } 
    721                  
    722                 // Console.traceln(Level.FINEST, "found " + interleavings.size() + 
    723                 //                 " most interleaving subsequences being most often a successor in " + 
    724                 //                 "comparison to the other remaining interleavings --> checking " + 
    725                 //                 "which is most seldom a predecessor"); 
    726  
    727                 interleavings = getLeastInterleavingsAsPredecessor(interleavings); 
    728                 interleavings = removeCollisionsOfOtherSubsequences(interleavings); 
    729                  
    730                 // dumpSorted(interleavings); 
    731  
    732                 if (interleavings.size() == 1) { 
    733                     // Console.traceln(Level.FINEST, "found one interleaving subsequence being most " + 
    734                     //                 "often a successor and most seldom a predecessor in " + 
    735                     //                 "comparison to the other remaining interleavings --> " + 
    736                     //                 "removing it and checking for further interleavings"); 
    737  
    738                     appData.getLastFoundSubsequences().remove 
    739                         (interleavings.get(0).getSubsequence()); 
    740                      
    741                     continue; 
    742                 } 
    743                 else if (interleavings.size() == 0) { 
    744                     // this should never happen 
    745                     throw new RuntimeException("Implementation error: don't know how I got here"); 
    746                 } 
     1017                // detected interleaving subsequences.  
    7471018                 
    7481019                // Console.traceln(Level.FINEST, "found " + interleavings.size() + 
    7491020                //                 " most interleaving subsequences being most often a successor " + 
    7501021                //                 "and most seldom a predecessor in comparison to the other " + 
    751                 //                 "remaining interleavings --> this may happen if there are no " + 
    752                 //                 "collisions between them anymore. If so, remove all of them at " + 
    753                 //                 "once."); 
    754  
    755                 int collisionCount = 0; 
    756                  
    757                 for (InterleavingSubsequence subsequence : interleavings) { 
    758                     collisionCount += subsequence.getCollisionCounter(); 
    759                 } 
    760                  
    761                 if (collisionCount == 0) { 
    762                     // Console.traceln(Level.FINEST, "remaining interleaving subsequences have no " + 
    763                     //                 "further collisions with each other --> removing all of them " + 
    764                     //                 "and checking for further interleavings"); 
     1022                //                 "remaining interleavings --> decide based on their occurrences" + 
     1023                //                 " in the sessions (remove those, coming later in comparison to " + 
     1024                //                 "the others)"); 
     1025                 
     1026                // determine the subsequences whose sum of the indexes of collisions is smallest or 
     1027                // who has the smallest collision index in all sessions and remove all others 
     1028                int overallMinSumOfCollisionIndexes = Integer.MAX_VALUE; 
     1029                int overallMinimalCollisionIndex = Integer.MAX_VALUE; 
     1030                InterleavingSubsequence interleavingWithMinSum = null; 
     1031                InterleavingSubsequence interleavingWithMinIndex = null; 
     1032                 
     1033                for (InterleavingSubsequence interleaving : interleavings) { 
     1034                    int sumOfCollisionIndexes = 0; 
     1035                    int minimalCollisionIndex = Integer.MAX_VALUE; 
    7651036                     
    766                     for (InterleavingSubsequence subsequence : interleavings) { 
    767                         appData.getLastFoundSubsequences().remove(subsequence.getSubsequence()); 
     1037                    for (Collision coll : interleaving.getPredecessorCollisions()) { 
     1038                        sumOfCollisionIndexes += coll.getLocation().getIndex(); 
     1039                        minimalCollisionIndex = 
     1040                            Math.min(minimalCollisionIndex, coll.getLocation().getIndex()); 
     1041                    } 
     1042                     
     1043                    for (Collision coll : interleaving.getSuccessorCollisions()) { 
     1044                        sumOfCollisionIndexes += coll.getLocation().getIndex(); 
     1045                        minimalCollisionIndex = 
     1046                            Math.min(minimalCollisionIndex, coll.getLocation().getIndex()); 
     1047                    } 
     1048                     
     1049                    if (overallMinSumOfCollisionIndexes > sumOfCollisionIndexes) { 
     1050                        interleavingWithMinSum = interleaving; 
     1051                        overallMinSumOfCollisionIndexes = sumOfCollisionIndexes; 
     1052                    } 
     1053                    else if (overallMinSumOfCollisionIndexes == sumOfCollisionIndexes) { 
     1054                        // cannot decide between already found and new one 
     1055                        interleavingWithMinSum = null; 
     1056                    } 
     1057                     
     1058                    if (overallMinimalCollisionIndex > minimalCollisionIndex) { 
     1059                        interleavingWithMinIndex = interleaving; 
     1060                        overallMinimalCollisionIndex = minimalCollisionIndex; 
     1061                    } 
     1062                    else if (overallMinimalCollisionIndex == minimalCollisionIndex) { 
     1063                        // cannot decide between already found and new one 
     1064                        interleavingWithMinIndex = null; 
     1065                    } 
     1066                } 
     1067                 
     1068                if (interleavingWithMinSum != null) { 
     1069                    for (InterleavingSubsequence interleaving : interleavings) { 
     1070                        if (interleaving != interleavingWithMinSum) { 
     1071                            appData.getLastFoundSubsequences().remove(interleaving.getSubsequence()); 
     1072                        } 
    7681073                    } 
    7691074                     
    7701075                    continue; 
    7711076                } 
    772  
    773                 // Console.traceln(Level.FINEST, "remaining interleaving subsequences still have " + 
    774                 //                 "collisions with each other --> decide based on their occurrences" + 
    775                 //                 " in the sessions (remove those, coming later in comparison to " + 
    776                 //                 "the others)"); 
    777                  
    778                 // determine the predecessor collisions being the last in all sessions. Those 
    779                 // collisions show the interleaving subsequence occurring last  
    780                 Map<IUserSession, Collision> sessions = 
    781                     new IdentityHashMap<IUserSession, Collision>(); 
    782                  
    783                 for (InterleavingSubsequence interleaving : interleavings) { 
    784                     for (Collision coll : interleaving.getPredecessorCollisions()) { 
    785                         Collision maxPosColl = sessions.get(coll.getLocation().getSession()); 
    786                          
    787                         if ((maxPosColl == null) || 
    788                             (maxPosColl.getLocation().getIndex() < coll.getLocation().getIndex())) 
    789                         { 
    790                             sessions.put(coll.getLocation().getSession(), coll); 
     1077                 
     1078                if (interleavingWithMinIndex != null) { 
     1079                    for (InterleavingSubsequence interleaving : interleavings) { 
     1080                        if (interleaving != interleavingWithMinIndex) { 
     1081                            appData.getLastFoundSubsequences().remove(interleaving.getSubsequence()); 
    7911082                        } 
    7921083                    } 
    793                 } 
    794                  
    795                 // determine, which of the subsequences occurs most often as the last one 
    796                 // interleaving with another 
    797                 Map<Subsequence, Integer> lastOccurrenceCounters = 
    798                     new IdentityHashMap<Subsequence, Integer>(); 
    799                  
    800                 for (Collision coll : sessions.values()) { 
    801                     Integer counter = lastOccurrenceCounters.get(coll.getSubsequence()); 
    8021084                     
    803                     if (counter == null) { 
    804                         lastOccurrenceCounters.put(coll.getSubsequence(), 1); 
    805                     } 
    806                     else { 
    807                         lastOccurrenceCounters.put(coll.getSubsequence(), counter + 1); 
    808                     } 
    809                 } 
    810                  
    811                 int maxCounter = 0; 
    812                 Subsequence toRemove = null; 
    813                  
    814                 for (Map.Entry<Subsequence, Integer> entry : lastOccurrenceCounters.entrySet()) { 
    815                     if (entry.getValue() > maxCounter) { 
    816                         maxCounter = entry.getValue(); 
    817                         toRemove = entry.getKey(); 
    818                     } 
    819                     else if (entry.getValue() == maxCounter) { 
    820                         // we can not decide again 
    821                         toRemove = null; 
    822                         break; 
    823                     } 
    824                 } 
    825                  
    826                 if (toRemove != null) { 
    827                     // Console.traceln(Level.FINEST, "one of the remaining interleaving subsequences" + 
    828                     //                 " is most often the last to occur --> removing it and " + 
    829                     //                 "checking for further interleavings"); 
    830              
    831                     appData.getLastFoundSubsequences().remove(toRemove); 
    8321085                    continue; 
    833                 } 
    834                  
    835                 // checking now, if there is one sequence, having the lowest index for any of 
    836                 // its collisions and preserve it. If there are several ones with the same minimum 
    837                 // index, check if they are independent. If not, throw an exception 
    838                 int minPosInAnySequence = Integer.MAX_VALUE; 
    839                 List<InterleavingSubsequence> subsequencesWithMinPos = new LinkedList<>(); 
    840                  
    841                 for (InterleavingSubsequence interleaving : interleavings) { 
    842                     for (Collision collision : interleaving.getSuccessorCollisions()) { 
    843                         if (minPosInAnySequence > collision.getLocation().getIndex()) { 
    844                             minPosInAnySequence = collision.getLocation().getIndex(); 
    845                             subsequencesWithMinPos.clear(); 
    846                         } 
    847                          
    848                         if (minPosInAnySequence == collision.getLocation().getIndex()) { 
    849                             // several have the same min pos --> undecidable which to prefer 
    850                             subsequencesWithMinPos.add(interleaving); 
    851                         } 
    852                     } 
    853                 } 
    854                  
    855                 if (subsequencesWithMinPos.size() > 0) { 
    856                     List<Subsequence> subsequencesToRemove = new LinkedList<Subsequence>(); 
    857                      
    858                     for (Subsequence candidate : appData.getLastFoundSubsequences()) { 
    859                         boolean found = false; 
    860                          
    861                         for (InterleavingSubsequence subsequenceWithMinPos : subsequencesWithMinPos) 
    862                         { 
    863                             if (candidate == subsequenceWithMinPos.getSubsequence()) { 
    864                                 found = true; 
    865                             } 
    866                         } 
    867                          
    868                         if (!found) { 
    869                             subsequencesToRemove.add(candidate); 
    870                         } 
    871                     } 
    872                      
    873                     if (subsequencesToRemove.size() > 0) { 
    874                         for (Subsequence candidate : subsequencesToRemove) { 
    875                             appData.getLastFoundSubsequences().remove(candidate); 
    876                         } 
    877                      
    878                         continue; 
    879                     } 
    8801086                } 
    8811087                 
     
    8851091                // directly follow each other. If not, it can not be decided, which of 
    8861092                // them to replace first. Perhaps the one occurring more often as 
    887                 // the first in a session that the other. But this can be implemented 
     1093                // the first in a session than the other. But this can be implemented 
    8881094                // later. 
    8891095                dumpSorted(interleavings, Level.SEVERE); 
     
    21522358         * @return the subsequence 
    21532359         */ 
    2154         private Subsequence getSubsequence() { 
    2155             return subsequence; 
    2156         } 
     2360//        private Subsequence getSubsequence() { 
     2361//            return subsequence; 
     2362//        } 
    21572363 
    21582364        /* (non-Javadoc) 
Note: See TracChangeset for help on using the changeset viewer.