Changeset 1711
- Timestamp:
- 09/02/14 13:19:33 (10 years ago)
- Location:
- branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 2 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/ObjectDistanceSubstitionMatrix.java
r1707 r1711 3 3 import java.io.Serializable; 4 4 import java.util.HashMap; 5 import java.util.concurrent.ExecutorService;6 import java.util.concurrent.Executors;7 import java.util.concurrent.TimeUnit;8 5 import java.util.HashSet; 9 6 import java.util.Iterator; … … 97 94 } 98 95 this.updateEventTaskInstances(newTasks); 99 100 int nThreads = de.ugoe.cs.autoquest.tasktrees.temporalrelation.SequenceForTaskDetectionRuleAlignment.nThreads;101 ExecutorService executor = Executors.newFixedThreadPool(nThreads);102 103 104 int count=0;105 int size=uniqueTasks.size();106 107 96 for(Iterator<ITask> it = newTasks.iterator();it.hasNext();) { 108 97 ITask task1 = it.next(); 109 98 for (Iterator<ITask> jt = uniqueTasks.iterator(); jt.hasNext();) { 110 99 ITask task2 = jt.next(); 111 Runnable worker = new DistanceCalculator(task1,task2); 112 executor.execute(worker); 100 computeDistance(task1,task2); 113 101 } 114 102 } 115 116 executor.shutdown(); 117 // Wait until all threads are finish 118 try { 119 executor.awaitTermination(60, TimeUnit.MINUTES); 120 } catch (InterruptedException e) { 121 e.printStackTrace(); 122 } 123 System.out.println("Finished all threads"); 124 125 } 126 } 127 103 } 104 } 105 106 private void computeDistance(ITask task1, ITask task2) { 107 int index1 = -1; 108 int index2 = -1; 109 float distance = 0; 110 ITaskInstance ti1 = null; 111 ITaskInstance ti2 = null; 112 // We just need to the first instance here 113 if (task1.getInstances().size() > 0) { 114 ti1 = (ITaskInstance) task1.getInstances().iterator() 115 .next(); 116 } 117 if (task2.getInstances().size() > 0) { 118 ti2 = (ITaskInstance) task2.getInstances().iterator() 119 .next(); 120 } 121 IEventTaskInstance eti1 = null; 122 IEventTaskInstance eti2 = null; 123 124 if (ti1 instanceof IEventTaskInstance 125 && ti2 instanceof IEventTaskInstance) { 126 eti1 = (IEventTaskInstance) ti1; 127 index1 = getIndex(eti1); 128 eti2 = (IEventTaskInstance) ti2; 129 index2 = getIndex(eti2); 130 distance = distanceBetweenInstances(eti1, eti2); 131 } else if (ti1 instanceof IEventTaskInstance 132 && !(ti2 instanceof IEventTaskInstance)) { 133 task1 = ((ITaskInstance) ti1).getTask(); 134 index2 = getIndex(task2); 135 eti1 = (IEventTaskInstance) ti1; 136 index1 = getIndex(eti1); 137 distance = distanceBetweenTaskAndInstance(task2, eti1); 138 } else if (!(ti1 instanceof IEventTaskInstance) 139 && ti2 instanceof IEventTaskInstance) { 140 index1 = getIndex(task1); 141 eti2 = (IEventTaskInstance) ti2; 142 index2 = getIndex(eti2); 143 distance = distanceBetweenTaskAndInstance(task1, eti2); 144 } else if (!(ti1 instanceof IEventTaskInstance) 145 && !(ti2 instanceof IEventTaskInstance)) { 146 index1 = getIndex(task1); 147 index2 = getIndex(task2); 148 distance = distanceBetweenTasks(task1, task2); 149 } else { 150 System.out.println("Unknown error"); 151 } 152 matrix.set(index1, index2, distance); 153 } 154 155 128 156 public void generate(HashSet<ITask> uniqueTasks) { 129 157 this.uniqueTasks = uniqueTasks; … … 137 165 } 138 166 matrix.initialize(0); 139 140 141 int nThreads = de.ugoe.cs.autoquest.tasktrees.temporalrelation.SequenceForTaskDetectionRuleAlignment.nThreads;142 Console.traceln(Level.INFO, "calculating distances with " + nThreads + " threads");143 ExecutorService executor = Executors.newFixedThreadPool(nThreads);144 145 167 146 168 int count=0; … … 149 171 ITask task1 = it.next(); 150 172 count++; 151 if(( size%count*100)==0) {173 if((count%(size/100)==0)) { 152 174 Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); 153 175 } 154 176 for (Iterator<ITask> jt = uniqueTasks.iterator(); jt.hasNext();) { 155 177 ITask task2 = jt.next(); 156 Runnable worker = new DistanceCalculator(task1,task2); 157 executor.execute(worker); 158 } 159 } 160 executor.shutdown(); 161 // Wait until all threads are finish 162 try { 163 executor.awaitTermination(60, TimeUnit.MINUTES); 164 } catch (InterruptedException e) { 165 e.printStackTrace(); 166 } 167 System.out.println("Finished all threads"); 168 178 computeDistance(task1,task2); 179 } 180 } 169 181 this.firstRoundMaxIndex=index; 170 182 } … … 280 292 281 293 } 282 283 284 private class DistanceCalculator implements Runnable {285 286 private ITask task1;287 private ITask task2;288 289 public DistanceCalculator(ITask task1, ITask task2){290 this.task1 = task1;291 this.task2 = task2;292 }293 294 295 @Override296 public void run() {297 computeDistance(task1,task2);298 }299 private void computeDistance(ITask task1, ITask task2) {300 int index1 = -1;301 int index2 = -1;302 float distance = 0;303 ITaskInstance ti1 = null;304 ITaskInstance ti2 = null;305 // We just need to the first instance here306 if (task1.getInstances().size() > 0) {307 ti1 = (ITaskInstance) task1.getInstances().iterator()308 .next();309 }310 if (task2.getInstances().size() > 0) {311 ti2 = (ITaskInstance) task2.getInstances().iterator()312 .next();313 }314 IEventTaskInstance eti1 = null;315 IEventTaskInstance eti2 = null;316 317 if (ti1 instanceof IEventTaskInstance318 && ti2 instanceof IEventTaskInstance) {319 eti1 = (IEventTaskInstance) ti1;320 index1 = getIndex(eti1);321 eti2 = (IEventTaskInstance) ti2;322 index2 = getIndex(eti2);323 distance = distanceBetweenInstances(eti1, eti2);324 } else if (ti1 instanceof IEventTaskInstance325 && !(ti2 instanceof IEventTaskInstance)) {326 task1 = ((ITaskInstance) ti1).getTask();327 index2 = getIndex(task2);328 eti1 = (IEventTaskInstance) ti1;329 index1 = getIndex(eti1);330 distance = distanceBetweenTaskAndInstance(task2, eti1);331 } else if (!(ti1 instanceof IEventTaskInstance)332 && ti2 instanceof IEventTaskInstance) {333 index1 = getIndex(task1);334 eti2 = (IEventTaskInstance) ti2;335 index2 = getIndex(eti2);336 distance = distanceBetweenTaskAndInstance(task1, eti2);337 } else if (!(ti1 instanceof IEventTaskInstance)338 && !(ti2 instanceof IEventTaskInstance)) {339 index1 = getIndex(task1);340 index2 = getIndex(task2);341 distance = distanceBetweenTasks(task1, task2);342 } else {343 System.out.println("Unknown error");344 }345 matrix.set(index1, index2, distance);346 //return distance;347 348 }349 350 351 }352 353 294 } -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1710 r1711 34 34 35 35 import de.ugoe.cs.autoquest.CommandHelpers; 36 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithm; 37 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentAlgorithmFactory; 36 38 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Match; 37 39 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.MatchOccurence; 38 40 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.NumberSequence; 39 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentGenerator;40 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.PairwiseAlignmentStorage;41 41 import de.ugoe.cs.autoquest.tasktrees.alignment.matrix.ObjectDistanceSubstitionMatrix; 42 42 import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; … … 203 203 } 204 204 else { 205 Console.traceln(Level.INFO,"loading substitution matrixfrom file");205 Console.traceln(Level.INFO,"loading harmonized sessions from file"); 206 206 appData = loadAppData("harmonized"); 207 207 } 208 208 System.out.println(SequenceForTaskDetectionRuleAlignment.loadSubstutionMatrix); 209 209 if(!SequenceForTaskDetectionRuleAlignment.loadSubstutionMatrix) { 210 210 Console.traceln(Level.INFO, "generating substitution matrix from " + appData.getUniqueTasks().size() + " unique tasks"); … … 216 216 } 217 217 else { 218 Console.traceln(Level.INFO,"loading substitution matrix from file"); 218 219 appData = loadAppData("substitution"); 219 220 } … … 649 650 650 651 // Generate pairwise alignments 652 int size = appData.getNumberSequences().size(); 651 653 Console.traceln(Level.INFO, "generating pairwise alignments"); 652 654 LinkedList<Match> matchseqs = new LinkedList<Match>(); 653 PairwiseAlignmentStorage alignments = PairwiseAlignmentGenerator 654 .generate(appData.getNumberSequences(), appData.getSubmat(), 9); 655 656 // Retrieve all matches reached a specific threshold 657 Console.traceln(Level.INFO, "retrieving significant sequence pieces"); 655 int count = 0; 656 658 657 for (int i = 0; i < appData.getNumberSequences().size(); i++) { 658 NumberSequence ns1 = appData.getNumberSequences().get(i); 659 count++; 660 if((count%(size/100)==0)) { 661 Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); 662 } 659 663 for (int j = 0; j < appData.getNumberSequences().size(); j++) { 664 NumberSequence ns2 = appData.getNumberSequences().get(j); 660 665 if (i != j) { 661 matchseqs.addAll(alignments.get(i, j).getMatches()); 666 667 Console.traceln(Level.FINEST,"Aligning sequence " + i + " with sequence " + j); 668 AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); 669 aa.align(ns1, ns2, appData.getSubmat(),9); 670 matchseqs.addAll(aa.getMatches()); 662 671 } 663 672 } … … 799 808 } 800 809 } 801 802 alignments = null;803 810 matchseqs = null; 804 811 appData.getStopWatch().stop("replacing tasks");
Note: See TracChangeset
for help on using the changeset viewer.