Changeset 1285 for trunk


Ignore:
Timestamp:
07/30/13 09:44:39 (11 years ago)
Author:
pharms
Message:
  • improved performance of task instance trie generation by using different symbol management strategies while creating the trie. This performance improvement is significant and allows to detect tasks now in a much faster manner.
Location:
trunk
Files:
6 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-tasktrees-test/src/test/java/de/ugoe/cs/autoquest/tasktrees/manager/TaskTreeManagerTest.java

    r1146 r1285  
    285285        } 
    286286 
    287         new TaskTreeChecker().assertTaskInstanceList 
     287        new TaskTreeChecker(true).assertTaskInstanceList 
    288288            ("UserSession session {" + 
    289289             "  Iteration iteration2 {" + 
  • trunk/autoquest-core-tasktrees-test/src/test/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskInstanceTrieTest.java

    r1256 r1285  
    3737 
    3838/** 
    39  * The class <code>TaskInstanceTrieTest</code> contains tests for the class <code>{@link TaskInstanceTrie}</code>. 
     39 * The class <code>TaskInstanceTrieTest</code> contains tests for the class 
     40 * <code>{@link TaskInstanceTrie}</code>. 
    4041 *  
    41  * @author Steffen Herbold 
     42 * @author Patrick Harms 
    4243 * @version 1.0 
    4344 */ 
     
    5455     
    5556    /** */ 
    56     private TaskComparator comparator = new TaskComparator(TaskEquality.SEMANTICALLY_EQUAL); 
     57    private TaskHandlingStrategy strategy = 
     58        new TaskHandlingStrategy(TaskEquality.IDENTICAL); 
    5759     
    5860    /** */ 
     
    8486    @Test 
    8587    public void testTaskInstanceTaskInstanceTrie_1() throws Exception { 
    86         TaskInstanceTrie result = new TaskInstanceTrie(comparator); 
     88        TaskInstanceTrie result = new TaskInstanceTrie(strategy); 
    8789 
    8890        assertNotNull(result); 
     
    9597    @Test(expected = java.lang.IllegalArgumentException.class) 
    9698    public void testTaskInstanceTrie_2() throws Exception { 
    97         new TaskInstanceTrie((TaskComparator) null); 
     99        new TaskInstanceTrie((TaskHandlingStrategy) null); 
    98100    } 
    99101 
    100102    @Test 
    101103    public void testTrainSessions_1() throws Exception { 
    102         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     104        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    103105         
    104106        IUserSession session = (IUserSession) decoder.decode 
     
    136138    @Test 
    137139    public void testTrainSessions_2() throws Exception { 
    138         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     140        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    139141         
    140142        IUserSession session = (IUserSession) decoder.decode 
     
    167169    @Test 
    168170    public void testTrainSessions_3() throws Exception { 
    169         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     171        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    170172         
    171173        IUserSession session = (IUserSession) decoder.decode 
     
    199201    @Test 
    200202    public void testTrainSessions_4() throws Exception { 
    201         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     203        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    202204         
    203205        IUserSession session = (IUserSession) decoder.decode 
     
    240242    @Test 
    241243    public void testTrainSessions_5() throws Exception { 
    242         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     244        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    243245         
    244246        IUserSession session = (IUserSession) decoder.decode 
     
    276278    @Test 
    277279    public void testTrainSessions_6() throws Exception { 
    278         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     280        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    279281         
    280282        IUserSession session = (IUserSession) decoder.decode 
     
    313315    @Test 
    314316    public void testTrainSessions_7() throws Exception { 
    315         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     317        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    316318         
    317319        IUserSession session = (IUserSession) decoder.decode 
     
    354356    @Test 
    355357    public void testTrainSessions_8() throws Exception { 
    356         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     358        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    357359         
    358360        IUserSession session = (IUserSession) decoder.decode 
     
    390392    @Test 
    391393    public void testTrainSessions_9() throws Exception { 
    392         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     394        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    393395         
    394396        IUserSession session = (IUserSession) decoder.decode 
     
    428430    @Test 
    429431    public void testGetSequencesWithMostOccurrences_1() throws Exception { 
    430         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     432        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    431433         
    432434        fixture.trainSessions(Arrays.asList(session), 3); 
     
    445447    @Test 
    446448    public void testGetSequencesWithMostOccurrences_2() throws Exception { 
    447         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     449        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    448450         
    449451        fixture.trainSessions(Arrays.asList(session), 3); 
     
    510512    @Test 
    511513    public void testGetSequencesWithMostOccurrences_3() throws Exception { 
    512         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     514        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    513515             
    514516        fixture.trainSessions(Arrays.asList(session), 3); 
     
    554556    @Test 
    555557    public void testGetSequencesWithMostOccurrences_4() throws Exception { 
    556         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     558        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    557559                 
    558560        fixture.trainSessions(Arrays.asList(session), 3); 
     
    566568    @Test 
    567569    public void testGetSequencesWithMostOccurrences_5() throws Exception { 
    568         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     570        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    569571                 
    570572        fixture.trainSessions(Arrays.asList(session), 3); 
     
    583585    @Test 
    584586    public void testGetSequencesWithMostOccurrences_6() throws Exception { 
    585         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     587        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    586588                 
    587589        fixture.trainSessions(Arrays.asList(session), 3); 
     
    596598    @Test 
    597599    public void testGetSequencesWithMostOccurrences_7() throws Exception { 
    598         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     600        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    599601                 
    600602        fixture.trainSessions(Arrays.asList(session), 3); 
     
    629631    @Test 
    630632    public void testGetSequencesWithMostOccurrences_8() throws Exception { 
    631         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     633        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    632634             
    633635        fixture.trainSessions(Arrays.asList(session), 3); 
     
    688690    @Test 
    689691    public void testGetSequencesWithMostOccurrences_9() throws Exception { 
    690         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     692        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    691693             
    692694        fixture.trainSessions(Arrays.asList(session), 3); 
     
    726728    @Test 
    727729    public void testGetSequencesWithMostOccurrences_10() throws Exception { 
    728         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     730        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    729731                
    730732        fixture.trainSessions(Arrays.asList(session), 3); 
     
    738740    @Test 
    739741    public void testGetSequencesWithMostOccurrences_11() throws Exception { 
    740         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     742        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    741743                 
    742744        fixture.trainSessions(Arrays.asList(session), 3); 
     
    762764    @Test 
    763765    public void testGetSequencesWithMostOccurrences_12() throws Exception { 
    764         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     766        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    765767                 
    766768        fixture.trainSessions(Arrays.asList(session), 3); 
     
    809811    @Test 
    810812    public void testGetSequencesWithMostOccurrences_13() throws Exception { 
    811         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     813        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    812814                 
    813815        fixture.trainSessions(Arrays.asList(session), 3); 
     
    822824    @Test 
    823825    public void testGetSequencesWithMostOccurrences_14() throws Exception { 
    824         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     826        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    825827                     
    826828        fixture.trainSessions(Arrays.asList(session), 3); 
     
    835837    @Test 
    836838    public void testGetCount_1() throws Exception { 
    837         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     839        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    838840                         
    839841        fixture.trainSessions(Arrays.asList(session), 3); 
     
    850852    @Test 
    851853    public void testGetCount_2() throws Exception { 
    852         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     854        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    853855                             
    854856        fixture.trainSessions(Arrays.asList(session), 3); 
     
    865867    @Test 
    866868    public void testGetCount_3() throws Exception { 
    867         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     869        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    868870                             
    869871        fixture.trainSessions(Arrays.asList(session), 3); 
     
    879881    @Test 
    880882    public void testGetCount_4() throws Exception { 
    881         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     883        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    882884                             
    883885        fixture.trainSessions(Arrays.asList(session), 3); 
     
    893895    @Test 
    894896    public void testGetCount_5() throws Exception { 
    895         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     897        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    896898                                 
    897899        fixture.trainSessions(Arrays.asList(session), 3); 
     
    908910    @Test 
    909911    public void testGetCount_6() throws Exception { 
    910         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     912        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    911913                                 
    912914        fixture.trainSessions(Arrays.asList(session), 3); 
     
    922924    @Test 
    923925    public void testGetFollowingSymbols_1() throws Exception { 
    924         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     926        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    925927                                     
    926928        fixture.trainSessions(Arrays.asList(session), 3); 
     
    940942    @Test 
    941943    public void testGetFollowingSymbols_2() throws Exception { 
    942         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     944        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    943945                                         
    944946        fixture.trainSessions(Arrays.asList(session), 3); 
     
    956958    @Test 
    957959    public void testGetFollowingSymbols_3() throws Exception { 
    958         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     960        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    959961                                         
    960962        fixture.trainSessions(Arrays.asList(session), 3); 
     
    970972    @Test 
    971973    public void testGetNumLeafAncestors_1() throws Exception { 
    972         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     974        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    973975                                             
    974976        fixture.trainSessions(Arrays.asList(session), 3); 
     
    981983    @Test 
    982984    public void testGetNumLeafs_1() throws Exception { 
    983         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     985        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    984986                                             
    985987        fixture.trainSessions(Arrays.asList(session), 3); 
     
    992994    @Test 
    993995    public void testGetNumSymbols_1() throws Exception { 
    994         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     996        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    995997                                             
    996998        fixture.trainSessions(Arrays.asList(session), 3); 
     
    10041006    @Test 
    10051007    public void testLargeTaskInstanceTrie_1() throws Exception { 
    1006         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1008        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    10071009 
    10081010        int order = 2; 
     
    10241026    @Test 
    10251027    public void testLargeTaskInstanceTrie_2() throws Exception { 
    1026         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1028        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    10271029 
    10281030        int order = 2; 
     
    10441046    @Test 
    10451047    public void testLargeTaskInstanceTrie_3() throws Exception { 
    1046         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1048        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    10471049 
    10481050        int order = 2; 
     
    10641066    @Test 
    10651067    public void testLargeTaskInstanceTrie_4() throws Exception { 
    1066         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1068        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    10671069 
    10681070        int order = 2; 
     
    10841086    @Test 
    10851087    public void testLargeTaskInstanceTrie_5() throws Exception { 
    1086         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1088        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    10871089 
    10881090        int order = 2; 
     
    11041106    @Test 
    11051107    public void testLargeTaskInstanceTrie_6() throws Exception { 
    1106         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1108        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    11071109 
    11081110        int order = 3; 
     
    11241126    @Test 
    11251127    public void testLargeTaskInstanceTrie_7() throws Exception { 
    1126         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1128        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    11271129 
    11281130        int order = 3; 
     
    11441146    @Test 
    11451147    public void testLargeTaskInstanceTrie_8() throws Exception { 
    1146         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1148        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    11471149 
    11481150        int order = 3; 
     
    11641166    @Test 
    11651167    public void testLargeTaskInstanceTrie_9() throws Exception { 
    1166         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1168        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    11671169 
    11681170        int order = 3; 
     
    11841186    @Test 
    11851187    public void testLargeTaskInstanceTrie_10() throws Exception { 
    1186         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1188        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    11871189 
    11881190        int order = 3; 
     
    12041206    @Test 
    12051207    public void testLargeTaskInstanceTrie_11() throws Exception { 
    1206         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1208        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    12071209 
    12081210        int order = 4; 
     
    12241226    @Test 
    12251227    public void testLargeTaskInstanceTrie_12() throws Exception { 
    1226         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1228        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    12271229 
    12281230        int order = 4; 
     
    12441246    @Test 
    12451247    public void testLargeTaskInstanceTrie_13() throws Exception { 
    1246         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1248        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    12471249 
    12481250        int order = 4; 
     
    12641266    @Test 
    12651267    public void testLargeTaskInstanceTrie_14() throws Exception { 
    1266         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1268        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    12671269 
    12681270        int order = 4; 
     
    12841286    @Test 
    12851287    public void testLargeTaskInstanceTrie_15() throws Exception { 
    1286         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1288        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    12871289 
    12881290        int order = 4; 
     
    13041306    @Test 
    13051307    public void testLargeTaskInstanceTrie_16() throws Exception { 
    1306         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1308        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    13071309 
    13081310        int order = 5; 
     
    13241326    @Test 
    13251327    public void testLargeTaskInstanceTrie_17() throws Exception { 
    1326         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1328        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    13271329 
    13281330        int order = 5; 
     
    13441346    @Test 
    13451347    public void testLargeTaskInstanceTrie_18() throws Exception { 
    1346         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1348        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    13471349 
    13481350        int order = 5; 
     
    13641366    @Test 
    13651367    public void testLargeTaskInstanceTrie_19() throws Exception { 
    1366         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1368        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    13671369 
    13681370        int order = 5; 
     
    13841386    @Test 
    13851387    public void testLargeTaskInstanceTrie_20() throws Exception { 
    1386         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1388        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    13871389 
    13881390        int order = 5; 
     
    14041406    @Test 
    14051407    public void testLargeTaskInstanceTrie_21() throws Exception { 
    1406         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1408        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    14071409 
    14081410        int order = 6; 
     
    14241426    @Test 
    14251427    public void testLargeTaskInstanceTrie_22() throws Exception { 
    1426         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1428        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    14271429 
    14281430        int order = 6; 
     
    14441446    @Test 
    14451447    public void testLargeTaskInstanceTrie_23() throws Exception { 
    1446         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1448        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    14471449 
    14481450        int order = 6; 
     
    14641466    @Test 
    14651467    public void testLargeTaskInstanceTrie_24() throws Exception { 
    1466         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1468        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    14671469 
    14681470        int order = 6; 
     
    14841486    @Test 
    14851487    public void testLargeTaskInstanceTrie_25() throws Exception { 
    1486         TaskInstanceTrie fixture = new TaskInstanceTrie(comparator); 
     1488        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
    14871489 
    14881490        int order = 6; 
     
    14931495        fixture.trainSessions(Arrays.asList(tester.userSession), order); 
    14941496        System.out.println("testing session with 10000 task instances and 1000 symbols took " + 
     1497                           (System.currentTimeMillis() - start) + "ms"); 
     1498         
     1499        fixture.process(tester); 
     1500         
     1501        // do not check if counts is empty, as some sequences may not be part of the reduced trie 
     1502        // and may therefore not be processed by the tester. 
     1503        //assertTrue(tester.counts.isEmpty()); 
     1504    } 
     1505 
     1506    @Test 
     1507    public void testLargeTaskInstanceTrie_26() throws Exception { 
     1508        TaskInstanceTrie fixture = new TaskInstanceTrie(strategy); 
     1509 
     1510        int order = 3; 
     1511         
     1512        TaskInstanceTrieTester tester = new TaskInstanceTrieTester(1000, 1000000, order); 
     1513 
     1514        long start = System.currentTimeMillis(); 
     1515        fixture.trainSessions(Arrays.asList(tester.userSession), order); 
     1516        System.out.println("testing session with 1000000 task instances and 1000 symbols took " + 
    14951517                           (System.currentTimeMillis() - start) + "ms"); 
    14961518         
     
    15131535                found = true; 
    15141536                for (int i = 0; i < containedList.size(); i++) { 
    1515                     if (!comparator.equals(candidate.get(0), containedList.get(0))) { 
     1537                    if (!strategy.getTaskComparator().equals(candidate.get(0), containedList.get(0))) { 
    15161538                        found = false; 
    15171539                        break; 
     
    16601682                 
    16611683                for (Map.Entry<Integer, ITaskInstance> entry : symbols.entrySet()) { 
    1662                     if (comparator.equals(entry.getValue(), symbol)) { 
     1684                    if (strategy.getTaskComparator().equals(entry.getValue(), symbol)) { 
    16631685                        symbolIndex = entry.getKey(); 
    16641686                        break; 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java

    r1256 r1285  
    1515package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 
    1616 
     17import java.util.HashMap; 
     18import java.util.HashSet; 
    1719import java.util.Iterator; 
    1820import java.util.LinkedList; 
    1921import java.util.List; 
     22import java.util.Map; 
     23import java.util.Set; 
     24import java.util.logging.Level; 
    2025 
    2126import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 
     
    3237import de.ugoe.cs.autoquest.usageprofiles.TrieProcessor; 
    3338import de.ugoe.cs.util.StopWatch; 
     39import de.ugoe.cs.util.console.Console; 
    3440 
    3541/** 
     
    5965    /** 
    6066     * <p> 
    61      * the task comparator to be used for comparing tasks 
     67     * the task comparator to be used for comparing tasks for preparation 
    6268     * </p> 
    6369     */ 
    64     private TaskComparator taskComparator; 
    65  
     70    private TaskHandlingStrategy preparationTaskHandlingStrategy; 
     71     
     72    /** 
     73     * <p> 
     74     * the task comparator to be used for comparing tasks during iteration detection an trie 
     75     * generation 
     76     * </p> 
     77     */ 
     78    private TaskHandlingStrategy identityTaskHandlingStrategy;; 
     79     
    6680    /** 
    6781     * <p> 
     
    7791        this.taskBuilder = taskBuilder; 
    7892         
    79         this.taskComparator = new TaskComparator(minimalTaskEquality); 
     93        this.preparationTaskHandlingStrategy = new TaskHandlingStrategy(minimalTaskEquality); 
     94        this.identityTaskHandlingStrategy = new TaskHandlingStrategy(TaskEquality.IDENTICAL); 
    8095    } 
    8196 
     
    139154     */ 
    140155    private void harmonizeEventTaskInstancesModel(RuleApplicationData appData) { 
    141         System.out.print("harmonizing task model of event task instances"); 
     156        Console.traceln(Level.INFO, "harmonizing task model of event task instances"); 
    142157        appData.getStopWatch().start("harmonizing event tasks"); 
    143          
    144         SymbolMap<ITaskInstance, ITask> unifiedTaskMap = 
    145             new SymbolMap<ITaskInstance, ITask>(taskComparator); 
     158 
     159        SymbolMap<ITaskInstance, ITask> uniqueTasks = 
     160            preparationTaskHandlingStrategy.createSymbolMap(); 
     161        TaskComparator comparator = preparationTaskHandlingStrategy.getTaskComparator(); 
    146162         
    147163        int unifiedTasks = 0; 
    148          
     164        ITask task; 
    149165        List<IUserSession> sessions = appData.getSessions(); 
    150166        for (IUserSession session : sessions) { 
     167            Console.traceln(Level.FINE, "handling session " + session); 
    151168            for (ITaskInstance taskInstance : session) { 
    152                 ITask task = unifiedTaskMap.getValue(taskInstance); 
     169                task = uniqueTasks.getValue(taskInstance); 
    153170                 
    154171                if (task == null) { 
    155                     unifiedTaskMap.addSymbol(taskInstance, taskInstance.getTask()); 
     172                    uniqueTasks.addSymbol(taskInstance, taskInstance.getTask()); 
    156173                } 
    157174                else { 
     
    160177                } 
    161178            } 
    162         } 
    163          
     179             
     180            comparator.clearBuffers(); 
     181        } 
    164182         
    165183        appData.getStopWatch().stop("harmonizing event tasks"); 
    166         System.out.println(" --> harmonized " + unifiedTasks + " task occurrences (still " + 
    167                            unifiedTaskMap.size() + " different tasks)"); 
    168          
     184        Console.traceln(Level.INFO, "harmonized " + unifiedTasks + " task occurrences (still " + 
     185                        uniqueTasks.size() + " different tasks)"); 
     186 
    169187        appData.getStopWatch().dumpStatistics(System.out); 
     188        appData.getStopWatch().reset(); 
    170189    } 
    171190 
     
    174193     */ 
    175194    private void detectAndReplaceIterations(RuleApplicationData appData) { 
    176         System.out.print("detecting iterations"); 
     195        Console.traceln(Level.FINE, "detecting iterations"); 
    177196        appData.getStopWatch().start("detecting iterations"); 
    178197         
    179198        List<IUserSession> sessions = appData.getSessions(); 
    180         int iteratedTasks = 0; 
    181          
    182         ITask iteratedTask = null; 
    183          
    184         do { 
    185             iteratedTask = searchIteratedTask(sessions); 
    186              
    187             if (iteratedTask != null) { 
    188                 replaceIterationsOf(iteratedTask, sessions, appData); 
    189                 iteratedTasks++; 
    190             } 
    191         } 
    192         while (iteratedTask != null); 
     199         
     200        Set<ITask> iteratedTasks = searchIteratedTasks(sessions); 
     201         
     202        if (iteratedTasks.size() > 0) { 
     203            replaceIterationsOf(iteratedTasks, sessions, appData); 
     204        } 
    193205         
    194206        appData.getStopWatch().stop("detecting iterations"); 
    195         System.out.println(" --> found " + iteratedTasks + " iterated tasks"); 
     207        Console.traceln(Level.INFO, "replaced " + iteratedTasks.size() + " iterated tasks"); 
    196208    } 
    197209 
     
    199211     * 
    200212     */ 
    201     private ITask searchIteratedTask(List<IUserSession> sessions) { 
     213    private Set<ITask> searchIteratedTasks(List<IUserSession> sessions) { 
     214        Set<ITask> iteratedTasks = new HashSet<ITask>(); 
    202215        for (IUserSession session : sessions) { 
    203216            for (int i = 0; i < (session.size() - 1); i++) { 
    204                 if (taskComparator.equals(session.get(i), session.get(i + 1))) { 
    205                     return session.get(i).getTask(); 
    206                 } 
    207             } 
    208         } 
    209          
    210         return null; 
     217                // we prepared the task instances to refer to unique tasks, if they are treated 
     218                // as equal. Therefore, we just compare the identity of the tasks of the task 
     219                // instances 
     220                if (session.get(i).getTask() == session.get(i + 1).getTask()) { 
     221                    iteratedTasks.add(session.get(i).getTask()); 
     222                } 
     223            } 
     224        } 
     225         
     226        return iteratedTasks; 
    211227    } 
    212228 
     
    214230     * 
    215231     */ 
    216 /*    private ITask searchIteratedTask(List<IUserSession> sessions) { 
    217         int minNoOfRepetitions = 2; 
    218         int minNoOfIterationOccurrences = 1; 
    219          
    220         Map<ITask, Integer> iterationsCounter = new HashMap<ITask, Integer>(); 
    221          
    222         for (IUserSession session : sessions) { 
    223             for (int i = 0; i < (session.size() - minNoOfRepetitions + 1); i++) { 
    224                 ITask task = session.get(i).getTask(); 
    225  
    226                 // check if the task is iterated 
    227                 boolean isIterated = true; 
    228                 for (int j = i + 1; j < i + minNoOfRepetitions; j++) { 
    229                     if (!taskComparator.equals(task, session.get(j).getTask())) { 
    230                         isIterated = false; 
    231                         break; 
    232                     } 
    233                 } 
    234                  
    235                 if (isIterated) { 
    236                     Integer currentCounter = null; 
    237                      
    238                     for (Map.Entry<ITask, Integer> entry : iterationsCounter.entrySet()) { 
    239                         if (taskComparator.equals(task, entry.getKey())) { 
    240                             currentCounter = entry.getValue(); 
    241                             break; 
    242                         } 
    243                     } 
    244                      
    245                     if (currentCounter == null) { 
    246                         currentCounter = 1; 
    247                         iterationsCounter.put(task, currentCounter); 
    248                     } 
    249                     else { 
    250                         currentCounter++; 
    251                         iterationsCounter.put(task, currentCounter); 
    252                     } 
    253                      
    254                     if (currentCounter >= minNoOfIterationOccurrences) { 
    255                         return task; 
    256                     } 
    257                 } 
    258             } 
    259         } 
    260          
    261         return null; 
    262     }*/ 
    263  
    264     /** 
    265      * 
    266      */ 
    267     private void replaceIterationsOf(ITask               iteratedTask, 
     232    private void replaceIterationsOf(Set<ITask>          iteratedTasks, 
    268233                                     List<IUserSession>  sessions, 
    269234                                     RuleApplicationData appData) 
    270235    { 
    271         IIteration iteration = taskFactory.createNewIteration(); 
     236        Map<ITask, IIteration> iterations = new HashMap<ITask, IIteration>(); 
     237        Map<IIteration, List<ITaskInstance>> iterationInstances = 
     238                new HashMap<IIteration, List<ITaskInstance>>(); 
     239             
     240        for (ITask iteratedTask : iteratedTasks) { 
     241            IIteration iteration = taskFactory.createNewIteration(); 
     242            iterations.put(iteratedTask, iteration); 
     243            iterationInstances.put(iteration, new LinkedList<ITaskInstance>()); 
     244        } 
     245         
    272246        ITaskInstance iterationInstance = null; 
    273          
    274         List<ITaskInstance> iterationInstances = new LinkedList<ITaskInstance>(); 
    275247         
    276248        for (IUserSession session : sessions) { 
    277249            int index = 0; 
    278250            while (index < session.size()) { 
    279                 if (taskComparator.equals(iteratedTask, session.get(index).getTask())) { 
    280                     if (iterationInstance == null) { 
     251                // we prepared the task instances to refer to unique tasks, if they are treated 
     252                // as equal. Therefore, we just compare the identity of the tasks of the task 
     253                // instances 
     254                ITask currentTask = session.get(index).getTask(); 
     255                IIteration iteration = iterations.get(currentTask); 
     256                if (iteration != null) { 
     257                    if ((iterationInstance == null) || (iterationInstance.getTask() != iteration)) 
     258                    { 
    281259                        iterationInstance = taskFactory.createNewTaskInstance(iteration); 
    282                         iterationInstances.add(iterationInstance); 
     260                        iterationInstances.get(iteration).add(iterationInstance); 
    283261                        taskBuilder.addTaskInstance(session, index, iterationInstance); 
    284262                        index++; 
     
    297275        } 
    298276         
    299         harmonizeIterationInstancesModel(iteration, iterationInstances); 
     277        for (Map.Entry<IIteration, List<ITaskInstance>> entry : iterationInstances.entrySet()) { 
     278            harmonizeIterationInstancesModel(entry.getKey(), entry.getValue()); 
     279        } 
    300280    } 
    301281 
     
    307287    { 
    308288        List<ITask> iteratedTaskVariants = new LinkedList<ITask>(); 
     289        TaskComparator comparator = preparationTaskHandlingStrategy.getTaskComparator(); 
    309290         
    310291        // merge the lexically different variants of iterated task to a unique list  
     
    315296                boolean found = false; 
    316297                for (ITask taskVariant : iteratedTaskVariants) { 
    317                     if (taskComparator.areLexicallyEqual(taskVariant, candidate)) { 
     298                    if (comparator.areLexicallyEqual(taskVariant, candidate)) { 
    318299                        taskBuilder.setTask(executionVariant, taskVariant); 
    319300                        found = true; 
     
    359340     */ 
    360341    private void detectAndReplaceTasks(RuleApplicationData appData) { 
    361         System.out.println("detecting and replacing tasks"); 
     342        Console.traceln(Level.FINE, "detecting and replacing tasks"); 
    362343        appData.getStopWatch().start("detecting tasks"); 
    363344         
     
    370351         
    371352        appData.getStopWatch().stop("replacing tasks"); 
    372         System.out.println("detected and replaced " + appData.getLastFoundTasks().size() + " tasks"); 
     353        Console.traceln(Level.INFO, "detected and replaced " + appData.getLastFoundTasks().size() + 
     354                        " tasks occuring " + appData.getLastFoundTasks().getOccurrenceCount() + 
     355                        "times"); 
    373356    } 
    374357 
     
    377360     */ 
    378361    private void getSequencesOccuringMostOften(RuleApplicationData appData) { 
    379         System.out.println("determining most prominent tasks"); 
     362        Console.traceln(Level.FINE, "determining most prominent tasks"); 
    380363 
    381364        Tasks tasks; 
     
    411394         
    412395        appData.getStopWatch().start("testtrie"); 
    413         Trie<ITaskInstance> trie = new Trie<ITaskInstance>(taskComparator); 
     396        Trie<ITaskInstance> trie = new Trie<ITaskInstance>(identityTaskComparator); 
    414397         
    415398        for (IUserSession session : appData.getSessions()) { 
     
    433416                    tasksEqual = true; 
    434417                    for (int i = 0; i < task1.size(); i++) { 
    435                         if (!taskComparator.equals(task1.get(i).getTask(), task2.get(i).getTask())) 
     418                        if (!identityTaskComparator.equals(task1.get(i).getTask(), task2.get(i).getTask())) 
    436419                        { 
    437420                            tasksEqual = false; 
     
    458441             
    459442            throw new IllegalArgumentException("both tries calculated different subsequences"); 
    460         }*/ 
     443        } 
    461444         
    462445        /*TrieStatisticsDumper dumper = new TrieStatisticsDumper(); 
     
    466449        appData.setLastFoundTasks(tasks); 
    467450 
    468         System.out.println("found " + appData.getLastFoundTasks().size() + " tasks occurring " + 
    469                           appData.getLastFoundTasks().getOccurrenceCount() + " times"); 
     451        Console.traceln(Level.FINE, "found " + appData.getLastFoundTasks().size() + " tasks " + 
     452                        "occurring " + appData.getLastFoundTasks().getOccurrenceCount() + " times"); 
    470453    } 
    471454 
     
    475458     */ 
    476459    private void createNewTrie(RuleApplicationData appData) { 
    477         System.out.println("training trie with a maximum sequence length of " + 
    478                            appData.getTrainedSequenceLength()); 
     460        Console.traceln(Level.FINER, "training trie with a maximum sequence length of " + 
     461                        appData.getTrainedSequenceLength()); 
    479462 
    480463        appData.getStopWatch().start("training trie"); 
    481         appData.setLastTrie(new TaskInstanceTrie(taskComparator)); 
     464         
     465        // we prepared the task instances to refer to unique tasks, if they are treated 
     466        // as equal. Therefore, we just compare the identity of the tasks of the task 
     467        // instances 
     468        appData.setLastTrie(new TaskInstanceTrie(identityTaskHandlingStrategy)); 
    482469     
    483470        appData.getLastTrie().trainSessions 
     
    496483            (appData.getLastFoundTasks().getOccurrenceCount() > 1)) 
    497484        { 
    498             System.out.println("replacing tasks occurrences"); 
     485            Console.traceln(Level.FINER, "replacing tasks occurrences"); 
    499486 
    500487            for (List<ITaskInstance> task : appData.getLastFoundTasks()) { 
    501488                ISequence sequence = taskFactory.createNewSequence(); 
    502489                 
    503                 System.out.println("replacing " + sequence.getId() + ": " + task); 
     490                Console.traceln(Level.FINEST, "replacing " + sequence.getId() + ": " + task); 
    504491 
    505492                List<ITaskInstance> sequenceInstances = 
     
    507494                 
    508495                harmonizeSequenceInstancesModel(sequence, sequenceInstances,task.size()); 
    509                 appData.detectedAndReplacedTasks(sequenceInstances.size() > 0); 
     496                appData.detectedAndReplacedTasks 
     497                    (appData.detectedAndReplacedTasks() || (sequenceInstances.size() > 0)); 
    510498 
    511499                if (sequenceInstances.size() < appData.getLastFoundTasks().getOccurrenceCount()) { 
    512                     System.out.println(sequence.getId() + ": replaced task only " + 
    513                                        sequenceInstances.size() + " times instead of expected " + 
    514                                        appData.getLastFoundTasks().getOccurrenceCount()); 
     500                    Console.traceln(Level.FINE, sequence.getId() + ": replaced task only " + 
     501                                    sequenceInstances.size() + " times instead of expected " + 
     502                                    appData.getLastFoundTasks().getOccurrenceCount()); 
    515503                } 
    516504            } 
     
    526514                                                 int                 sequenceLength) 
    527515    { 
     516        TaskComparator comparator = preparationTaskHandlingStrategy.getTaskComparator(); 
    528517         
    529518        // ensure for each subtask that lexically different variants are preserved 
     
    537526                 
    538527                for (int i = 0; i < subTaskVariants.size(); i++) { 
    539                     if (taskComparator.areLexicallyEqual(subTaskVariants.get(i), candidate)) { 
     528                    if (comparator.areLexicallyEqual(subTaskVariants.get(i), candidate)) { 
    540529                        taskBuilder.setTask 
    541530                            (sequenceInstance.get(subTaskIndex), subTaskVariants.get(i)); 
     
    624613             
    625614            for (int j = 0; j < subList.size(); j++) { 
    626                 if (!taskComparator.equals(list.get(i + j), subList.get(j))) { 
     615                // we prepared the task instances to refer to unique tasks, if they are treated 
     616                // as equal. Therefore, we just compare the identity of the tasks of the task 
     617                // instances 
     618                if (list.get(i + j).getTask() != subList.get(j).getTask()) { 
    627619                    matchFound = false; 
    628620                    break; 
     
    655647             
    656648            for (int j = 0; j < subList.size(); j++) { 
    657                 if (!taskComparator.equals(list.get(i + j), subList.get(j))) { 
     649                // we prepared the task instances to refer to unique tasks, if they are treated 
     650                // as equal. Therefore, we just compare the identity of the tasks of the task 
     651                // instances 
     652                if (list.get(i + j) != subList.get(j)) { 
    658653                    matchFound = false; 
    659654                    break; 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskComparator.java

    r1256 r1285  
    1919import java.util.HashMap; 
    2020 
    21 import de.ugoe.cs.autoquest.eventcore.IEventType; 
    2221import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; 
    2322import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEqualityRuleManager; 
    24 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    25 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
    26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    2823import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2924import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
     
    3934     
    4035    /** */ 
    41     private static final int MAX_BUFFER_SIZE = 10 * 1024 * 1024; 
     36    private static final int MAX_BUFFER_SIZE = 2 * 1024 * 1024; 
    4237 
    4338    /** */ 
     
    7974         
    8075        if (task1 != task2) { 
    81             if ((task1 instanceof IEventTask) && (task2 instanceof IEventTask)) { 
     76            //if ((task1 instanceof IEventTask) && (task2 instanceof IEventTask)) { 
    8277                long key = ((long) System.identityHashCode(task1)) << 32; 
    8378                key += System.identityHashCode(task2); 
     
    9287                    } 
    9388                } 
    94             } 
     89            /*} 
    9590            else { 
    9691                result = false; 
    97             } 
     92            }*/ 
    9893        } 
    9994        else { 
     
    118113            if (result == null) { 
    119114                result = lexicalComparer.compare(task1, task2); 
    120                 if (equalityBuffer.size() < 1024 * 1024 * 10) { 
     115                if (equalityBuffer.size() < MAX_BUFFER_SIZE) { 
    121116                    lexicalEqualityBuffer.put(key, result); 
    122117                } 
     
    130125    } 
    131126     
    132     /* (non-Javadoc) 
    133      * @see SymbolComparator#getBucketSearchOrder(Object) 
    134      */ 
    135     @Override 
    136     public int[] getBucketSearchOrder(ITaskInstance taskInstance) { 
    137         // 0 = sequence; 1 = selection; 2 = iteration; 3 = optional; 4 = event task in general; 
    138         // other = hashCode of name of event type 
    139          
    140         ITask task = taskInstance.getTask(); 
    141          
    142         if (task instanceof IEventTask) { 
    143             // event tasks are most likely equal to those of the event type with the same name, 
    144             // Afterwards, they may be equal to iterations, optionals, other event tasks, 
    145             // selections, and finally the rest. 
    146             IEventType eventType = ((IEventTask) task).getEventType(); 
    147             return new int[] { eventType.getName().hashCode(), 2, 3, 4, 1 };                        
    148         } 
    149         else if (task instanceof ISequence) { 
    150             return new int[] { 0, 2, 3, 1 };                        
    151         } 
    152         else if (task instanceof ISelection) { 
    153             return new int[] { 1, 4, 2, 3 };                        
    154         } 
    155         else if (task instanceof IIteration) { 
    156             return new int[] { 2, 1, 4 };                        
    157         } 
    158          
    159         return null; 
    160     } 
    161  
     127    /** 
     128     * <p> 
     129     * TODO: comment 
     130     * </p> 
     131     * 
     132     */ 
     133    void clearBuffers() { 
     134        equalityBuffer.clear(); 
     135        init(); 
     136    } 
     137     
    162138    /** 
    163139     *  
     
    275251        } 
    276252    } 
     253 
    277254} 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskInstanceTrie.java

    r1273 r1285  
    2020import java.util.Map; 
    2121 
     22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2223import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    2324import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
     
    3334 * @author Patrick Harms 
    3435 */ 
    35 public class TaskInstanceTrie extends Trie<ITaskInstance> { 
     36class TaskInstanceTrie extends Trie<ITaskInstance> { 
    3637 
    3738    /**  */ 
     
    4344     * </p> 
    4445     */ 
    45     private TaskComparator comparator; 
    46  
     46    private TaskHandlingStrategy taskStrategy; 
     47     
    4748    /** 
    4849     * <p> 
     
    5253     * @param taskComparator2 
    5354     */ 
    54     public TaskInstanceTrie(TaskComparator taskComparator) { 
    55         super(taskComparator); 
    56         this.comparator = taskComparator; 
     55    public TaskInstanceTrie(TaskHandlingStrategy taskStrategy) { 
     56        super(taskStrategy); 
     57        this.taskStrategy = taskStrategy; 
    5758    } 
    5859 
     
    6566        } 
    6667         
    67         SymbolMap<ITaskInstance, List<ITaskInstance>> equalTaskInstancesMap = 
    68             new SymbolMap<ITaskInstance, List<ITaskInstance>>(comparator); 
    69          
    70         Map<ITaskInstance, List<ITaskInstance>> taskInstancesMap = 
    71             new HashMap<ITaskInstance, List<ITaskInstance>>(); 
     68        SymbolMap<ITaskInstance, Counter> equalTaskInstancesMap = 
     69            taskStrategy.createSymbolMap(); 
     70         
     71        Map<ITask, Counter> instanceCountMap = new HashMap<ITask, Counter>(); 
    7272         
    7373        System.out.println("preparing training"); 
     74        int noOfTaskInstances = 0; 
    7475        for (IUserSession session : userSessions) { 
    7576            for (ITaskInstance taskInstance : session) { 
    76                 List<ITaskInstance> equalTaskInstances = 
    77                     equalTaskInstancesMap.getValue(taskInstance); 
    78                  
    79                 if (equalTaskInstances == null) { 
    80                     equalTaskInstances = new LinkedList<ITaskInstance>(); 
    81                     equalTaskInstancesMap.addSymbol(taskInstance, equalTaskInstances); 
     77                Counter counter = equalTaskInstancesMap.getValue(taskInstance); 
     78                 
     79                if (counter == null) { 
     80                    counter = new Counter(); 
     81                    equalTaskInstancesMap.addSymbol(taskInstance, counter); 
    8282                } 
    8383                 
    84                 equalTaskInstances.add(taskInstance); 
    85                 taskInstancesMap.put(taskInstance, equalTaskInstances); 
    86             } 
    87         } 
    88          
    89         System.out.println("performing training"); 
     84                counter.count++; 
     85                instanceCountMap.put(taskInstance.getTask(), counter); 
     86                 
     87                noOfTaskInstances++; 
     88            } 
     89        } 
     90         
     91        System.out.println("performing training of " + noOfTaskInstances + " task instances"); 
     92        Counter processedTaskInstances = new Counter(); 
     93        int counterRecheckAt = noOfTaskInstances / 10; // recheck the maximum count after each 
     94                                                       // 10% of processed task instances 
    9095        for (IUserSession session : userSessions) { 
    91             train(session, maxOrder, taskInstancesMap); 
     96            train(session, maxOrder, instanceCountMap, processedTaskInstances, counterRecheckAt); 
    9297        }       
    9398         
     
    122127     *  
    123128     */ 
    124     private void train(IUserSession                            userSession, 
    125                        int                                     maxOrder, 
    126                        Map<ITaskInstance, List<ITaskInstance>> taskInstancesMap) 
     129    private void train(IUserSession        userSession, 
     130                       int                 maxOrder, 
     131                       Map<ITask, Counter> taskInstanceCountMap, 
     132                       Counter             processedTaskInstances, 
     133                       int                 counterRecheckAt) 
    127134    { 
    128135        List<ITaskInstance> executedTasks = userSession.getExecutedTasks(); 
     
    130137        List<ITaskInstance> subsequence = new LinkedList<ITaskInstance>(); 
    131138         
    132         int numberOfTrainedSubsequences = 0; 
    133139        int sequenceMaxCount = 0; 
    134140         
    135141        for (ITaskInstance currentTaskInstance : executedTasks) { 
    136             int occurrenceCount = taskInstancesMap.get(currentTaskInstance).size(); 
    137              
    138             if ((numberOfTrainedSubsequences % 10) == 0) { 
     142             
     143            int occurrenceCount = taskInstanceCountMap.get(currentTaskInstance.getTask()).count; 
     144             
     145            if (processedTaskInstances.count >= counterRecheckAt) { 
    139146                sequenceMaxCount = getCurrentSequenceMaxCount(); 
     147                processedTaskInstances.count = 0; 
    140148            } 
    141149             
     
    158166                    add(subsequence); 
    159167                    subsequence.remove(0); 
    160  
    161                     numberOfTrainedSubsequences++; 
    162168                } 
    163169            } 
     170             
     171            processedTaskInstances.count++; 
    164172        } 
    165173         
     
    219227    } 
    220228     
     229    /** 
     230     * @author Patrick Harms 
     231     */ 
     232    private static class Counter { 
     233        int count = 0; 
     234    } 
     235         
    221236} 
Note: See TracChangeset for help on using the changeset viewer.