Changeset 1741 for branches/autoquest-core-tasktrees-alignment/src/main
- Timestamp:
- 09/12/14 11:59:02 (10 years ago)
- Location:
- branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/Match.java
r1734 r1741 6 6 import java.io.Serializable; 7 7 import java.util.ArrayList; 8 import java.util.Iterator; 8 9 import java.util.LinkedList; 9 10 … … 12 13 * The Class Match. 13 14 */ 14 public class Match implements Serializable {15 public class Match implements Comparable<Match>,Serializable { 15 16 16 17 /** The Constant serialVersionUID. */ … … 21 22 22 23 /** The occurences. */ 23 private LinkedList<MatchOccur ence> occurences;24 private LinkedList<MatchOccurrence> occurrences; 24 25 25 26 /** … … 28 29 public Match() { 29 30 matchseqs = new ArrayList<NumberSequence>(2); 30 occur ences = new LinkedList<MatchOccurence>();31 occurrences = new LinkedList<MatchOccurrence>(); 31 32 matchseqs.add(null); 32 33 matchseqs.add(null); 33 } 34 } // TODO Auto-generated method stub 34 35 35 36 /** … … 38 39 * @param occurence the occurence 39 40 */ 40 public void addOccurence(MatchOccur ence occurence) {41 occur ences.add(occurence);41 public void addOccurence(MatchOccurrence occurence) { 42 occurrences.add(occurence); 42 43 } 43 44 44 45 /** 45 * Adds the occur ences of.46 * Adds the occurrences of given match to this match . 46 47 * 47 * @param m the m 48 * @param m the match the occurrences should be merged with this one 48 49 */ 49 50 public void addOccurencesOf(Match m) { 50 occur ences.addAll(m.getOccurences());51 occurrences.addAll(m.getOccurences()); 51 52 } 52 53 … … 54 55 * Equals. 55 56 * 56 * @param m the m57 * @return true, if successful57 * @param m the Match the equality should be checked against 58 * @return true, if both Matches are equal 58 59 */ 59 60 public boolean equals(Match m) { … … 77 78 78 79 /** 79 * Gets the occur ences.80 * Gets the occurrences. 80 81 * 81 * @return the occur ences82 * @return the occurrences 82 83 */ 83 public LinkedList<MatchOccur ence> getOccurences() {84 return occur ences;84 public LinkedList<MatchOccurrence> getOccurences() { 85 return occurrences; 85 86 } 86 87 … … 95 96 96 97 /** 97 * Occur ence count.98 * Occurrence count. 98 99 * 99 * @return the int100 * @return the number of occurrences of this match 100 101 */ 101 102 public int occurenceCount() { 102 return occur ences.size();103 return occurrences.size(); 103 104 } 104 105 … … 113 114 114 115 /** 115 * Sets the occur ences.116 * Sets the occurrences. 116 117 * 117 * @param occurences the new occur ences118 * @param occurences the new occurrences 118 119 */ 119 public void setOccurences(LinkedList<MatchOccur ence> occurences) {120 this.occur ences = occurences;120 public void setOccurences(LinkedList<MatchOccurrence> occurences) { 121 this.occurrences = occurences; 121 122 } 122 123 … … 130 131 } 131 132 133 134 /** 135 * Ocurrence id sum. Used for comparing and sorting matches 136 * 137 * @return th 138 */ 139 public int ocurrenceIDSum() { 140 int sum = 0; 141 for(Iterator<MatchOccurrence> it = occurrences.iterator();it.hasNext();) { 142 MatchOccurrence mo = it.next(); 143 sum+=mo.getSequenceId(); 144 } 145 return sum; 146 } 147 148 /** 149 * Task id sum. Used for comparing and sorting matches 150 * 151 * @return 152 */ 153 public int taskIdSum() { 154 int sum = 0; 155 int[] first = this.getFirstSequence().getSequence(); 156 int[] second = this.getSecondSequence().getSequence(); 157 for(int i = 0;i < this.getFirstSequence().size();i++) { 158 sum= first[i]+second[i]; 159 } 160 return sum; 161 } 162 163 public Match cloneWithoutOccurences() throws CloneNotSupportedException { 164 Match result; 165 result = (Match) this.clone(); 166 result.occurrences.clear(); 167 return result; 168 } 169 132 170 /** 133 171 * Size. 134 172 * 135 * @return the int173 * @return the size (number of aligned tasks) 136 174 */ 137 175 public int size() { … … 140 178 } 141 179 180 /* (non-Javadoc) 181 * @see java.lang.Comparable#compareTo(java.lang.Object) 182 */ 183 @Override 184 public int compareTo(Match arg0) { 185 186 return 0; 187 } 188 142 189 } -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/MatchOccurrence.java
r1734 r1741 10 10 * The Class MatchOccurence. 11 11 */ 12 public class MatchOccur ence implements Serializable {12 public class MatchOccurrence implements Serializable { 13 13 14 14 /** The Constant serialVersionUID. */ … … 31 31 * @param sequenceId the sequence id 32 32 */ 33 public MatchOccur ence(int startindex, int endindex, int sequenceId) {33 public MatchOccurrence(int startindex, int endindex, int sequenceId) { 34 34 this.startindex = startindex; 35 35 this.endindex = endindex; -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWatermanRepeated.java
r1734 r1741 262 262 tmpal.setFirstSequence(tmpns1); 263 263 tmpal.setSecondSequence(tmpns2); 264 // tmpal.addOccurence(new265 // MatchOccurence(start,alignment.get(0).getId()));266 // tmpal.addOccurence(new267 // MatchOccurence(start,alignment.get(1).getId()));268 264 result.add(tmpal); 269 265 } -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/ObjectDistanceSubstitionMatrix.java
r1740 r1741 220 220 matrix.initialize(0); 221 221 222 int count = 0;223 final int size = uniqueTasks.size();222 //int count = 0; 223 //final int size = uniqueTasks.size(); 224 224 for (final Iterator<ITask> it = uniqueTasks.iterator(); it.hasNext();) { 225 225 final ITask task1 = it.next(); 226 count++;227 if (((count % (size / 100)) == 0)) {228 Console.traceln(Level.INFO,229 (Math.round(((float) count / size) * 100)) + "%");230 }226 //count++; 227 //if (((count % (size / 100)) == 0)) { 228 // Console.traceln(Level.INFO, 229 // (Math.round(((float) count / size) * 100)) + "%"); 230 //} 231 231 for (final Iterator<ITask> jt = uniqueTasks.iterator(); jt 232 232 .hasNext();) { -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java
r1738 r1741 64 64 final ISequenceInstance subsequence = taskFactory 65 65 .createNewTaskInstance(model); 66 @SuppressWarnings("unused") 66 // TODO: Debugging output 67 /* 67 68 int modelid = model.getId(); 68 69 if(modelid == 5412) { … … 77 78 } 78 79 79 } 80 }*/ 80 81 // TODO: This is dirty, return this in addition with the sequence 81 82 // instance instead … … 125 126 } else if ((parent.get(startIndex).getTask().equals(tmpSel.getChildren().get(0).getId())) 126 127 || (parent.get(startIndex).getTask().equals(tmpSel.getChildren().get(1).getId()))) { 127 //taskBuilder.setChild(selection, parent.get(startIndex));128 //taskBuilder.addChild(subsequence, selection);129 //taskBuilder.removeTaskInstance(parent, startIndex);130 //modelindex++;128 taskBuilder.setChild(selection, parent.get(startIndex)); 129 taskBuilder.addChild(subsequence, selection); 130 taskBuilder.removeTaskInstance(parent, startIndex); 131 modelindex++; 131 132 continue; 132 133 … … 226 227 // Thread.currentThread().getName() + ": " + Math.round((float) 227 228 // count/size*100))+ "%"); 228 // System.out.println(message + " in thread"229 //+ Thread.currentThread().getName() + ": "230 //+ Math.round(((float) count / size) * 100) + "%");229 System.out.println(message + " in thread " 230 + Thread.currentThread().getName() + ": " 231 + Math.round(((float) count / size) * 100) + "%"); 231 232 } 232 233 } else { … … 234 235 // Thread.currentThread().getName() + ": " +Math.round((float) 235 236 // count/size*100))+ "%"); 236 // System.out.println(message + " in thread"237 //+ Thread.currentThread().getName() + ": "238 //+ Math.round(((float) count / size) * 100) + "%");237 System.out.println(message + " in thread " 238 + Thread.currentThread().getName() + ": " 239 + Math.round(((float) count / size) * 100) + "%"); 239 240 240 241 } -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1740 r1741 25 25 import java.util.List; 26 26 import java.util.Map; 27 import java.util.PriorityQueue; 28 import java.util.Queue; 27 29 import java.util.Set; 28 30 import java.util.concurrent.ExecutorService; … … 34 36 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 35 37 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Match; 36 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.MatchOccur ence;38 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.MatchOccurrence; 37 39 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 38 40 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix; … … 72 74 public class SequenceForTaskDetectionRuleAlignment implements ISessionScopeRule { 73 75 74 /** 75 * The Class RuleApplicationData. 76 */ 77 private static class RuleApplicationData implements Serializable { 78 79 /** The Constant serialVersionUID. */ 80 private static final long serialVersionUID = -7559657686755522960L; 81 82 /** 83 * The number2task HashMap. Since we align the tasks just by their 84 * integer id, we need this to convert them back to Tasks again 85 */ 86 private final HashMap<Integer, ITask> number2task; 87 88 /** 89 * The unique tasks, keeps track about all unique tasks TODO: We 90 * Actually just need number2task here, this structure can be removed in 91 * the future. 92 */ 93 private final HashSet<ITask> uniqueTasks; 94 95 /** 96 * The substitution matrix used by the alignment algorithm to be able to 97 * compare distances of tasks 98 */ 99 private final ObjectDistanceSubstitionMatrix submat; 100 101 /** 102 * HashMap for keeping track in which sequence which replacement has 103 * been performed. Neccessary for updating the indices of other 104 * occurrences accordingly 105 */ 106 private HashMap<Integer, List<MatchOccurence>> replacedOccurences; 107 108 /** The list of all found matches */ 109 private LinkedList<Match> matchseqs; 110 111 /** 112 * The generated NumberSequences. This is the integer representation of 113 * the user sessions 114 */ 115 private ArrayList<NumberSequence> numberseqs; 116 117 /** The list of newly created tasks (of one iteration). */ 118 private final LinkedList<ITask> newTasks; 119 120 /** The user sessions containing all EventTasks/Instances */ 121 private final List<IUserSession> sessions; 122 123 /** True if we replaced something in the user sessions in one iteration. */ 124 private boolean detectedAndReplacedTasks; 125 126 /** The result we give autoquest back */ 127 private final RuleApplicationResult result; 128 129 /** Stop Watch to measure performance */ 130 private final StopWatch stopWatch; 131 132 /** 133 * Instantiates a new rule application data. 134 * 135 * @param sessions 136 * The user sessions 137 */ 138 private RuleApplicationData(List<IUserSession> sessions) { 139 this.sessions = sessions; 140 numberseqs = new ArrayList<NumberSequence>(); 141 uniqueTasks = new HashSet<ITask>(); 142 number2task = new HashMap<Integer, ITask>(); 143 stopWatch = new StopWatch(); 144 result = new RuleApplicationResult(); 145 submat = new ObjectDistanceSubstitionMatrix(6, -3, false); 146 newTasks = new LinkedList<ITask>(); 147 this.detectedAndReplacedTasks = true; 148 } 149 150 /** 151 * Detected and replaced tasks. 152 * 153 * @return true, if successful 154 */ 155 private boolean detectedAndReplacedTasks() { 156 return detectedAndReplacedTasks; 157 } 158 159 /** 160 * Gets the matchseqs. 161 * 162 * @return the matchseqs 163 */ 164 public LinkedList<Match> getMatchseqs() { 165 return matchseqs; 166 } 167 168 /** 169 * Gets the new tasks. 170 * 171 * @return the new tasks 172 */ 173 public LinkedList<ITask> getNewTasks() { 174 return newTasks; 175 } 176 177 /** 178 * Gets the number2task. 179 * 180 * @return the number2task HashMap 181 */ 182 private HashMap<Integer, ITask> getNumber2Task() { 183 return number2task; 184 } 185 186 /** 187 * Gets the number sequences. 188 * 189 * @return the number sequences 190 */ 191 private ArrayList<NumberSequence> getNumberSequences() { 192 return numberseqs; 193 } 194 195 /** 196 * Gets the replaced occurrences. 197 * 198 * @return the replaced occurences 199 */ 200 public HashMap<Integer, List<MatchOccurence>> getReplacedOccurrences() { 201 return replacedOccurences; 202 } 203 204 /** 205 * Gets the result. 206 * 207 * @return the result 208 */ 209 private RuleApplicationResult getResult() { 210 return result; 211 } 212 213 /** 214 * Gets the sessions. 215 * 216 * @return the UserSessions as List. 217 */ 218 private List<IUserSession> getSessions() { 219 return sessions; 220 } 221 222 /** 223 * Gets the stop watch. 224 * 225 * @return the stopWatch 226 */ 227 private StopWatch getStopWatch() { 228 return stopWatch; 229 } 230 231 /** 232 * Gets the submat. 233 * 234 * @return the submat 235 */ 236 private ObjectDistanceSubstitionMatrix getSubmat() { 237 return submat; 238 } 239 240 /** 241 * Gets the unique tasks. 242 * 243 * @return the unique tasks 244 */ 245 private HashSet<ITask> getUniqueTasks() { 246 return uniqueTasks; 247 } 248 249 /** 250 * New task created. 251 * 252 * @param task 253 * the task 254 */ 255 private void newTaskCreated(ITask task) { 256 number2task.put(task.getId(), task); 257 newTasks.add(task); 258 } 259 260 /** 261 * Reset newly created tasks. 262 */ 263 synchronized private void resetNewlyCreatedTasks() { 264 uniqueTasks.addAll(newTasks); 265 newTasks.clear(); 266 } 267 268 /** 269 * Sets the number sequences. 270 * 271 * @param numberseqs 272 * the new number sequences 273 */ 274 private void setNumberSequences(ArrayList<NumberSequence> numberseqs) { 275 this.numberseqs = numberseqs; 276 } 277 278 /** 279 * Sets the replaced occurences. 280 * 281 * @param replacedOccurences 282 * the replaced occurences 283 */ 284 public void setReplacedOccurences( 285 HashMap<Integer, List<MatchOccurence>> replacedOccurences) { 286 this.replacedOccurences = replacedOccurences; 287 } 288 289 /** 290 * Update substitution matrix. 291 */ 292 private void updateSubstitutionMatrix() { 293 submat.update(getNewTasks()); 294 resetNewlyCreatedTasks(); 295 } 296 297 } 298 76 299 77 /** The n threads. */ 300 78 public static int nThreads = Runtime.getRuntime().availableProcessors() - 1; … … 380 158 detectAndReplaceIterations(appData); 381 159 appData.getStopWatch().start("task replacement"); 160 //Just does anything if the substitution matrix is created with the option to do so 382 161 appData.updateSubstitutionMatrix(); 383 162 detectAndReplaceTasks(appData); // 384 163 appData.getStopWatch().stop("task replacement"); 385 164 appData.getStopWatch().stop("whole loop"); 386 appData.getStopWatch().dumpStatistics(System.out);165 //appData.getStopWatch().dumpStatistics(System.out); 387 166 appData.getStopWatch().reset(); 388 167 … … 400 179 RuleApplicationStatus.FINISHED); 401 180 } 402 new TaskTreeValidator().validate(appData.getSessions());181 //new TaskTreeValidator().validate(appData.getSessions()); 403 182 return appData.getResult(); 404 183 } … … 488 267 @Override 489 268 public int compare(Match m1, Match m2) { 490 return m2.occurenceCount() - m1.occurenceCount(); 491 269 int cmp = m2.occurenceCount() - m1.occurenceCount(); 270 if(cmp != 0) { 271 return cmp; 272 } 273 else { 274 cmp = m2.size()-m1.size(); 275 if(cmp != 0) { 276 return cmp; 277 } 278 else { 279 //This should rarely happen 280 cmp = m2.ocurrenceIDSum()-m1.ocurrenceIDSum(); 281 if(cmp !=0) { 282 return cmp; 283 } 284 else { 285 cmp = m2.taskIdSum()-m1.taskIdSum(); 286 287 return cmp; 288 } 289 } 290 } 492 291 } 493 292 }; 293 494 294 Collections.sort(appData.getMatchseqs(), comparator); 495 295 appData.getStopWatch().stop("detecting tasks"); 296 496 297 497 298 // Replace matches in the sessions … … 502 303 } 503 304 504 /** 505 * Generate pairwise alignments. 506 * 507 * @param appData 508 * the app data 509 */ 510 private void generatePairwiseAlignments(RuleApplicationData appData) { 511 final int numberSeqSize = appData.getNumberSequences().size(); 512 appData.matchseqs = new LinkedList<Match>(); 513 Console.traceln(Level.INFO, "generating pairwise alignments from " 514 + numberSeqSize + " sessions with " + nThreads + " threads"); 515 516 int newThreads = nThreads; 517 if (numberSeqSize < nThreads) { 518 newThreads = numberSeqSize; 519 } 520 521 final ExecutorService executor = Executors 522 .newFixedThreadPool(newThreads); 523 final int interval = numberSeqSize / newThreads; 524 int rest = numberSeqSize % newThreads; 525 Console.traceln(Level.FINE, "Interval: " + interval + " Rest: " + rest); 526 for (int i = 0; i <= (numberSeqSize - interval); i += interval) { 527 int offset = 0; 528 if (rest != 0) { 529 offset = 1; 530 rest--; 531 } 532 533 final int from = i; 534 final int to = i + interval+offset-1; 535 Console.traceln(Level.FINER, "Aligning: Creating thread for sessions " + from + " till " + to); 536 final ParallelPairwiseAligner aligner = new ParallelPairwiseAligner( 537 appData, from, to); 538 executor.execute(aligner); 539 i+=offset; 540 } 541 executor.shutdown(); 542 try { 543 executor.awaitTermination(2, TimeUnit.HOURS); 544 } catch (final InterruptedException e) { 545 e.printStackTrace(); 546 } 547 } 548 305 306 //TODO: DEBUG METHOD 307 @SuppressWarnings("unused") 308 private void printMatches(RuleApplicationData appData) { 309 LinkedList<Match> matchseqs = appData.getMatchseqs(); 310 if(iteration>1) { 311 System.out.println("PRINTING MATCHES"); 312 for (Iterator<Match> it = matchseqs.iterator(); it.hasNext();) { 313 Match m = it.next(); 314 m.getFirstSequence().printSequence(); 315 m.getSecondSequence().printSequence(); 316 for(Iterator<MatchOccurrence> jt = m.getOccurences().iterator();jt.hasNext();) { 317 MatchOccurrence mo = jt.next(); 318 System.out.print(mo.getSequenceId() + " "); 319 } 320 System.out.println(); 321 System.out.println(); 322 } 323 } 324 } 325 326 549 327 /** 550 328 * <p> … … 879 657 } 880 658 659 private void prepareReplacements(RuleApplicationData appData) { 660 appData.initializeQueues(appData.getSessions().size()); 661 final int matchSeqSize = appData.getMatchseqs().size(); 662 int count = 0; 663 for (Iterator<Match> it = appData.getMatchseqs().iterator(); it.hasNext();) { 664 Match m = it.next(); 665 for(Iterator<MatchOccurrence> jt=m.getOccurences().iterator();jt.hasNext();) { 666 MatchOccurrence mo = jt.next(); 667 668 Match emptyMatch = null; 669 try { 670 emptyMatch = m.cloneWithoutOccurences(); 671 } catch (CloneNotSupportedException e) { 672 e.printStackTrace(); 673 } 674 emptyMatch.addOccurence(mo); 675 appData.getPlannedReplacements()[mo.getSequenceId()].add(m); 676 } 677 count++; 678 679 } 680 } 681 881 682 /** 882 683 * Replace matches. … … 886 687 */ 887 688 private void replaceMatches(RuleApplicationData appData) { 888 appData.setReplacedOccurences(new HashMap<Integer, List<MatchOccur ence>>());689 appData.setReplacedOccurences(new HashMap<Integer, List<MatchOccurrence>>()); 889 690 890 691 final int matchSeqSize = appData.getMatchseqs().size(); 891 692 int count = 0; 892 693 for (int i = 0; i < matchSeqSize; i++) { 893 694 count++; 894 695 // Every pattern consists of 2 sequences, therefore the minimum 895 696 // occurrences here is 2. 896 697 // We just need the sequences also occurring in other sequences 897 698 // as well 699 RuleUtils.printProgressPercentage("Replacement progress", count, matchSeqSize); 898 700 if (appData.getMatchseqs().get(i).occurenceCount() > 2) { 899 701 900 702 final ISequence task = matchAsSequence(appData, appData 901 703 .getMatchseqs().get(i)); 902 invalidOccurence: for (final Iterator<MatchOccur ence> it = appData704 invalidOccurence: for (final Iterator<MatchOccurrence> it = appData 903 705 .getMatchseqs().get(i).getOccurences().iterator(); it 904 706 .hasNext();) { 905 final MatchOccur ence oc = it.next();707 final MatchOccurrence oc = it.next(); 906 708 907 709 // Check if nothing has been replaced in the sequence we … … 911 713 appData.getReplacedOccurrences().put( 912 714 oc.getSequenceId(), 913 new LinkedList<MatchOccur ence>());715 new LinkedList<MatchOccurrence>()); 914 716 } else { 915 717 // check if we have any replaced occurence with … … 928 730 // harmonized. 929 731 930 for (final Iterator<MatchOccur ence> jt = appData732 for (final Iterator<MatchOccurrence> jt = appData 931 733 .getReplacedOccurrences() 932 734 .get(oc.getSequenceId()).iterator(); jt 933 735 .hasNext();) { 934 final MatchOccur ence tmpOC = jt.next();736 final MatchOccurrence tmpOC = jt.next(); 935 737 936 738 if ((oc.getStartindex() >= tmpOC.getStartindex()) … … 1004 806 1005 807 /** 808 * Generate pairwise alignments. 809 * 810 * @param appData 811 * the app data 812 */ 813 private void generatePairwiseAlignments(RuleApplicationData appData) { 814 final int numberSeqSize = appData.getNumberSequences().size(); 815 appData.matchseqs = new LinkedList<Match>(); 816 Console.traceln(Level.INFO, "generating pairwise alignments from " 817 + numberSeqSize + " sessions with " + nThreads + " threads"); 818 819 int newThreads = nThreads; 820 if (numberSeqSize < nThreads) { 821 newThreads = numberSeqSize; 822 } 823 824 final ExecutorService executor = Executors 825 .newFixedThreadPool(newThreads); 826 final int interval = numberSeqSize / newThreads; 827 int rest = numberSeqSize % newThreads; 828 Console.traceln(Level.FINE, "Interval: " + interval + " Rest: " + rest); 829 for (int i = 0; i <= (numberSeqSize - interval); i += interval) { 830 int offset = 0; 831 if (rest != 0) { 832 offset = 1; 833 rest--; 834 } 835 836 final int from = i; 837 final int to = i + interval+offset-1; 838 Console.traceln(Level.FINER, "Aligning: Creating thread for sessions " + from + " till " + to); 839 final ParallelPairwiseAligner aligner = new ParallelPairwiseAligner( 840 appData, from, to); 841 executor.execute(aligner); 842 i+=offset; 843 } 844 executor.shutdown(); 845 try { 846 executor.awaitTermination(2, TimeUnit.HOURS); 847 } catch (final InterruptedException e) { 848 e.printStackTrace(); 849 } 850 } 851 852 853 854 855 /** 1006 856 * Search matches in all sessions. 1007 857 * … … 1089 939 this.to = to; 1090 940 } 1091 1092 941 /* 1093 942 * (non-Javadoc) … … 1124 973 .iterator(); jt.hasNext();) { 1125 974 final int start = jt.next(); 1126 pattern.addOccurence(new MatchOccur ence(start,975 pattern.addOccurence(new MatchOccurrence(start, 1127 976 start + pattern.size(), j)); 1128 977 } … … 1132 981 } 1133 982 } 983 984 1134 985 1135 986 /** … … 1193 1044 } 1194 1045 } 1046 1047 /** 1048 * The Class RuleApplicationData. 1049 */ 1050 private static class RuleApplicationData implements Serializable { 1051 1052 /** The Constant serialVersionUID. */ 1053 private static final long serialVersionUID = -7559657686755522960L; 1054 1055 /** 1056 * The number2task HashMap. Since we align the tasks just by their 1057 * integer id, we need this to convert them back to Tasks again 1058 */ 1059 private final HashMap<Integer, ITask> number2task; 1060 1061 /** 1062 * The unique tasks, keeps track about all unique tasks TODO: We 1063 * Actually just need number2task here, this structure can be removed in 1064 * the future. 1065 */ 1066 private final HashSet<ITask> uniqueTasks; 1067 1068 /** 1069 * The substitution matrix used by the alignment algorithm to be able to 1070 * compare distances of tasks 1071 */ 1072 private final ObjectDistanceSubstitionMatrix submat; 1073 1074 /** 1075 * HashMap for keeping track in which sequence which replacement has 1076 * been performed. Neccessary for updating the indices of other 1077 * occurrences accordingly 1078 */ 1079 private HashMap<Integer, List<MatchOccurrence>> replacedOccurences; 1080 1081 private Queue<Match>[] plannedReplacements; 1082 1083 1084 /** The list of all found matches */ 1085 private LinkedList<Match> matchseqs; 1086 1087 /** 1088 * The generated NumberSequences. This is the integer representation of 1089 * the user sessions 1090 */ 1091 private ArrayList<NumberSequence> numberseqs; 1092 1093 /** The list of newly created tasks (of one iteration). */ 1094 private final LinkedList<ITask> newTasks; 1095 1096 /** The user sessions containing all EventTasks/Instances */ 1097 private final List<IUserSession> sessions; 1098 1099 /** True if we replaced something in the user sessions in one iteration. */ 1100 private boolean detectedAndReplacedTasks; 1101 1102 /** The result we return from this rule */ 1103 private final RuleApplicationResult result; 1104 1105 /** Stop Watch to measure performance */ 1106 private final StopWatch stopWatch; 1107 1108 1109 1110 /** 1111 * Instantiates a new rule application data. 1112 * 1113 * @param sessions 1114 * The user sessions 1115 */ 1116 private RuleApplicationData(List<IUserSession> sessions) { 1117 this.sessions = sessions; 1118 numberseqs = new ArrayList<NumberSequence>(); 1119 uniqueTasks = new HashSet<ITask>(); 1120 number2task = new HashMap<Integer, ITask>(); 1121 stopWatch = new StopWatch(); 1122 result = new RuleApplicationResult(); 1123 submat = new ObjectDistanceSubstitionMatrix(6, -3, false); 1124 newTasks = new LinkedList<ITask>(); 1125 this.detectedAndReplacedTasks = true; 1126 } 1127 1128 private void initializeQueues(int size) { 1129 plannedReplacements = new Queue[size]; 1130 for(int i=0;i<size;i++) { 1131 plannedReplacements[i] = new PriorityQueue<Match>(); 1132 } 1133 } 1134 1135 public Queue<Match>[] getPlannedReplacements() { 1136 return plannedReplacements; 1137 } 1138 1139 public void setPlannedReplacements(Queue<Match>[] plannedReplacements) { 1140 this.plannedReplacements = plannedReplacements; 1141 } 1142 1143 /** 1144 * Detected and replaced tasks. 1145 * 1146 * @return true, if successful 1147 */ 1148 private boolean detectedAndReplacedTasks() { 1149 return detectedAndReplacedTasks; 1150 } 1151 1152 /** 1153 * Gets the matchseqs. 1154 * 1155 * @return the matchseqs 1156 */ 1157 public LinkedList<Match> getMatchseqs() { 1158 return matchseqs; 1159 } 1160 1161 /** 1162 * Gets the new tasks. 1163 * 1164 * @return the new tasks 1165 */ 1166 public LinkedList<ITask> getNewTasks() { 1167 return newTasks; 1168 } 1169 1170 /** 1171 * Gets the number2task. 1172 * 1173 * @return the number2task HashMap 1174 */ 1175 private HashMap<Integer, ITask> getNumber2Task() { 1176 return number2task; 1177 } 1178 1179 /** 1180 * Gets the number sequences. 1181 * 1182 * @return the number sequences 1183 */ 1184 private ArrayList<NumberSequence> getNumberSequences() { 1185 return numberseqs; 1186 } 1187 1188 /** 1189 * Gets the replaced occurrences. 1190 * 1191 * @return the replaced occurences 1192 */ 1193 public HashMap<Integer, List<MatchOccurrence>> getReplacedOccurrences() { 1194 return replacedOccurences; 1195 } 1196 1197 /** 1198 * Gets the result. 1199 * 1200 * @return the result 1201 */ 1202 private RuleApplicationResult getResult() { 1203 return result; 1204 } 1205 1206 /** 1207 * Gets the sessions. 1208 * 1209 * @return the UserSessions as List. 1210 */ 1211 private List<IUserSession> getSessions() { 1212 return sessions; 1213 } 1214 1215 /** 1216 * Gets the stop watch. 1217 * 1218 * @return the stopWatch 1219 */ 1220 private StopWatch getStopWatch() { 1221 return stopWatch; 1222 } 1223 1224 /** 1225 * Gets the submat. 1226 * 1227 * @return the submat 1228 */ 1229 private ObjectDistanceSubstitionMatrix getSubmat() { 1230 return submat; 1231 } 1232 1233 /** 1234 * Gets the unique tasks. 1235 * 1236 * @return the unique tasks 1237 */ 1238 private HashSet<ITask> getUniqueTasks() { 1239 return uniqueTasks; 1240 } 1241 1242 /** 1243 * New task created. 1244 * 1245 * @param task 1246 * can be called when new tasks are created to keep track of all newly created tasks 1247 */ 1248 private void newTaskCreated(ITask task) { 1249 number2task.put(task.getId(), task); 1250 newTasks.add(task); 1251 } 1252 1253 /** 1254 * Reset newly created tasks. 1255 */ 1256 synchronized private void resetNewlyCreatedTasks() { 1257 uniqueTasks.addAll(newTasks); 1258 newTasks.clear(); 1259 } 1260 1261 /** 1262 * Sets the number sequences. 1263 * 1264 * @param numberseqs 1265 * the new number sequences 1266 */ 1267 private void setNumberSequences(ArrayList<NumberSequence> numberseqs) { 1268 this.numberseqs = numberseqs; 1269 } 1270 1271 /** 1272 * Sets the replaced occurences. 1273 * 1274 * @param replacedOccurences 1275 * the replaced occurences 1276 */ 1277 public void setReplacedOccurences( 1278 HashMap<Integer, List<MatchOccurrence>> replacedOccurences) { 1279 this.replacedOccurences = replacedOccurences; 1280 } 1281 1282 /** 1283 * Update substitution matrix. 1284 */ 1285 private void updateSubstitutionMatrix() { 1286 submat.update(getNewTasks()); 1287 resetNewlyCreatedTasks(); 1288 } 1289 1290 } 1291 1292 1195 1293 1196 1294 }
Note: See TracChangeset
for help on using the changeset viewer.