Changeset 1707 for branches/autoquest-core-tasktrees-alignment
- Timestamp:
- 09/01/14 19:03:47 (10 years ago)
- Location:
- branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/ObjectDistanceSubstitionMatrix.java
r1702 r1707 1 1 package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; 2 2 3 import java.io.Serializable; 3 4 import java.util.HashMap; 5 import java.util.concurrent.ExecutorService; 6 import java.util.concurrent.Executors; 7 import java.util.concurrent.TimeUnit; 4 8 import java.util.HashSet; 5 9 import java.util.Iterator; … … 18 22 19 23 20 public class ObjectDistanceSubstitionMatrix implements SubstitutionMatrix { 21 24 public class ObjectDistanceSubstitionMatrix implements SubstitutionMatrix,Serializable { 25 26 /** 27 * 28 */ 29 private static final long serialVersionUID = -4253258274617754083L; 22 30 private HashMap<Integer, Integer> idmapping; 23 31 private ITriangleMatrix matrix; … … 90 98 this.updateEventTaskInstances(newTasks); 91 99 92 for(Iterator<ITask> it = newTasks.iterator();it.hasNext();) {93 int index1 = -1;94 int index2 = -1;95 float distance = 0;96 ITask task1 = it.next();97 for (Iterator<ITask> jt = uniqueTasks.iterator(); jt.hasNext();) {98 ITask task2 = jt.next();99 ITaskInstance ti1 = null;100 ITask Instance ti2 = null;101 // We just need to the first instance here102 if (task1.getInstances().size() > 0) {103 ti1 = (ITaskInstance) task1.getInstances().iterator()104 .next();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 for(Iterator<ITask> it = newTasks.iterator();it.hasNext();) { 108 ITask task1 = it.next(); 109 for (Iterator<ITask> jt = uniqueTasks.iterator(); jt.hasNext();) { 110 ITask task2 = jt.next(); 111 Runnable worker = new DistanceCalculator(task1,task2); 112 executor.execute(worker); 105 113 } 106 if (task2.getInstances().size() > 0) { 107 ti2 = (ITaskInstance) task2.getInstances().iterator() 108 .next(); 109 } 110 IEventTaskInstance eti1 = null; 111 IEventTaskInstance eti2 = null; 112 113 if (ti1 instanceof IEventTaskInstance 114 && ti2 instanceof IEventTaskInstance) { 115 eti1 = (IEventTaskInstance) ti1; 116 index1 = getIndex(eti1); 117 eti2 = (IEventTaskInstance) ti2; 118 index2 = getIndex(eti2); 119 distance = distanceBetweenInstances(eti1, eti2); 120 } else if (ti1 instanceof IEventTaskInstance 121 && !(ti2 instanceof IEventTaskInstance)) { 122 task1 = ((ITaskInstance) ti1).getTask(); 123 index2 = getIndex(task2); 124 eti1 = (IEventTaskInstance) ti1; 125 index1 = getIndex(eti1); 126 distance = distanceBetweenTaskAndInstance(task2, eti1); 127 } else if (!(ti1 instanceof IEventTaskInstance) 128 && ti2 instanceof IEventTaskInstance) { 129 index1 = getIndex(task1); 130 eti2 = (IEventTaskInstance) ti2; 131 index2 = getIndex(eti2); 132 distance = distanceBetweenTaskAndInstance(task1, eti2); 133 } else if (!(ti1 instanceof IEventTaskInstance) 134 && !(ti2 instanceof IEventTaskInstance)) { 135 index1 = getIndex(task1); 136 index2 = getIndex(task2); 137 distance = distanceBetweenTasks(task1, task2); 138 } else { 139 System.out.println("Unknown error"); 140 } 141 142 matrix.set(index1, index2, distance); 143 144 } 145 } 114 } 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 146 125 } 147 126 } … … 158 137 } 159 138 matrix.initialize(0); 160 Console.traceln(Level.INFO, "calculating distances"); 161 int index1 = -1; 162 int index2 = -1; 163 float distance = 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 146 int count=0; 147 int size=uniqueTasks.size(); 164 148 for (Iterator<ITask> it = uniqueTasks.iterator(); it.hasNext();) { 165 149 ITask task1 = it.next(); 150 count++; 151 if((size%count*100)==0) { 152 Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); 153 } 166 154 for (Iterator<ITask> jt = uniqueTasks.iterator(); jt.hasNext();) { 167 155 ITask task2 = jt.next(); 168 ITaskInstance ti1 = null; 169 ITaskInstance ti2 = null; 170 // We just need to the first instance here 171 if (task1.getInstances().size() > 0) { 172 ti1 = (ITaskInstance) task1.getInstances().iterator() 173 .next(); 174 } 175 if (task2.getInstances().size() > 0) { 176 ti2 = (ITaskInstance) task2.getInstances().iterator() 177 .next(); 178 } 179 IEventTaskInstance eti1 = null; 180 IEventTaskInstance eti2 = null; 181 182 if (ti1 instanceof IEventTaskInstance 183 && ti2 instanceof IEventTaskInstance) { 184 eti1 = (IEventTaskInstance) ti1; 185 index1 = getIndex(eti1); 186 eti2 = (IEventTaskInstance) ti2; 187 index2 = getIndex(eti2); 188 distance = distanceBetweenInstances(eti1, eti2); 189 } else if (ti1 instanceof IEventTaskInstance 190 && !(ti2 instanceof IEventTaskInstance)) { 191 task1 = ((ITaskInstance) ti1).getTask(); 192 index2 = getIndex(task2); 193 eti1 = (IEventTaskInstance) ti1; 194 index1 = getIndex(eti1); 195 distance = distanceBetweenTaskAndInstance(task2, eti1); 196 } else if (!(ti1 instanceof IEventTaskInstance) 197 && ti2 instanceof IEventTaskInstance) { 198 index1 = getIndex(task1); 199 eti2 = (IEventTaskInstance) ti2; 200 index2 = getIndex(eti2); 201 distance = distanceBetweenTaskAndInstance(task1, eti2); 202 } else if (!(ti1 instanceof IEventTaskInstance) 203 && !(ti2 instanceof IEventTaskInstance)) { 204 index1 = getIndex(task1); 205 index2 = getIndex(task2); 206 distance = distanceBetweenTasks(task1, task2); 207 } else { 208 System.out.println("Unknown error"); 209 } 210 matrix.set(index1, index2, distance); 211 212 } 213 } 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 214 169 this.firstRoundMaxIndex=index; 215 170 } 216 171 217 private void computeDistance(ITask task1, ITask task2) { 218 219 220 } 221 172 173 222 174 223 175 … … 233 185 .iterator(); it.hasNext();) { 234 186 IEventTaskInstance eti2 = it.next(); 235 int taskId1 = eti1.getTask().getId();236 int taskId2 = eti2.getTask().getId();237 if (scoreExists(taskId1, taskId2)) {238 tmpDistance += getScore(taskId1, taskId2);239 } else {187 //int taskId1 = eti1.getTask().getId(); 188 //int taskId2 = eti2.getTask().getId(); 189 //if (scoreExists(taskId1, taskId2)) { 190 // tmpDistance += getScore(taskId1, taskId2); 191 //} else { 240 192 float dist = distanceBetweenInstances(eti1, eti2); 241 193 matrix.set(getIndex(eti1), getIndex(eti2), dist); 242 194 tmpDistance += dist; 243 }195 //} 244 196 } 245 197 return tmpDistance / eventTaskInstances.size(); … … 249 201 } 250 202 251 public boolean scoreExists(int id, int id2) {203 //public boolean scoreExists(int id, int id2) { 252 204 //return idmapping.containsKey(id) && idmapping.containsKey(id2); 253 return false;254 }205 // return false; 206 //} 255 207 256 208 private float distanceBetweenTasks(ITask task1, ITask task2) { … … 271 223 } 272 224 273 private int getIndex(ITask task) {225 synchronized private int getIndex(ITask task) { 274 226 int tempindex = -1; 275 227 276 228 if (!idmapping.containsKey(task.getId())) { 229 277 230 idmapping.put(task.getId(), index); 278 231 tempindex = index; … … 285 238 } 286 239 287 private int getIndex(IEventTaskInstance eti) {240 synchronized private int getIndex(IEventTaskInstance eti) { 288 241 int tempindex = -1; 289 242 if (!idmapping.containsKey(eti.getTask().getId())) { … … 327 280 328 281 } 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 @Override 296 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 here 306 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 IEventTaskInstance 318 && 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 IEventTaskInstance 325 && !(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 } 329 352 330 353 } -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/StaticTriangleMatrix.java
r1703 r1707 1 1 package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; 2 2 3 public class StaticTriangleMatrix implements ITriangleMatrix { 3 import java.io.Serializable; 4 5 public class StaticTriangleMatrix implements ITriangleMatrix,Serializable { 4 6 7 /** 8 * 9 */ 10 private static final long serialVersionUID = 7599542322424894866L; 5 11 private float[] matrix; 6 12 protected int size; -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleApplicationResult.java
r1146 r1707 15 15 package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 16 16 17 import java.io.Serializable; 17 18 import java.util.ArrayList; 18 19 import java.util.List; … … 31 32 * @author Patrick Harms 32 33 */ 33 class RuleApplicationResult {34 class RuleApplicationResult implements Serializable { 34 35 35 /** */ 36 37 /** 38 * 39 */ 40 private static final long serialVersionUID = -5927099713841481328L; 41 42 /** */ 36 43 private RuleApplicationStatus status = RuleApplicationStatus.NOT_APPLIED; 37 44 -
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1702 r1707 15 15 package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 16 16 17 import java.io.FileInputStream; 18 import java.io.FileOutputStream; 19 import java.io.IOException; 20 import java.io.ObjectInputStream; 21 import java.io.ObjectOutputStream; 22 import java.io.Serializable; 17 23 import java.util.ArrayList; 18 24 import java.util.Collections; … … 27 33 import java.util.logging.Level; 28 34 35 import de.ugoe.cs.autoquest.CommandHelpers; 29 36 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Match; 30 37 import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.MatchOccurence; … … 49 56 import de.ugoe.cs.util.StopWatch; 50 57 import de.ugoe.cs.util.console.Console; 58 import de.ugoe.cs.util.console.GlobalDataContainer; 51 59 52 60 /** … … 66 74 * @author Patrick Harms 67 75 */ 68 class SequenceForTaskDetectionRuleAlignment implements ISessionScopeRule { 76 public class SequenceForTaskDetectionRuleAlignment implements ISessionScopeRule { 77 78 79 public static int nThreads; 80 public static boolean harmonizeSequences; 81 69 82 70 83 private int iteration = 0; … … 137 150 public RuleApplicationResult apply(List<IUserSession> sessions) { 138 151 RuleApplicationData appData = new RuleApplicationData(sessions); 139 140 harmonizeEventTaskInstancesModel(appData); 141 // Generate a substitution matrix between all occurring events. 142 Console.traceln(Level.INFO, "generating substitution matrix"); 143 Console.traceln(Level.INFO,"Got " + appData.getUniqueTasks().size() + "tasks"); 144 appData.getSubmat().generate(appData.getUniqueTasks()); 152 if(SequenceForTaskDetectionRuleAlignment.harmonizeSequences) { 153 harmonizeEventTaskInstancesModel(appData); 154 Console.traceln(Level.INFO, "generating substitution matrix from " + appData.getUniqueTasks().size() + " unique tasks"); 155 appData.getSubmat().generate(appData.getUniqueTasks()); 156 appData.getStopWatch().stop("substitution matrix"); 157 GlobalDataContainer.getInstance().addData("appData", appData); 158 //Saving intermediate results to file 159 Console.traceln(Level.INFO,"saving substitution matrix to file"); 160 String objectName = "appData"; 161 String filename = "appData.dat"; 162 Object dataObject = GlobalDataContainer.getInstance().getData( 163 objectName); 164 if (dataObject == null) { 165 CommandHelpers.objectNotFoundMessage(objectName); 166 } 167 FileOutputStream fos = null; 168 ObjectOutputStream out = null; 169 try { 170 fos = new FileOutputStream(filename); 171 out = new ObjectOutputStream(fos); 172 out.writeObject(dataObject); 173 out.close(); 174 } catch (IOException ex) { 175 Console.logException(ex); 176 } 177 } 178 else { 179 Console.traceln(Level.INFO,"loading substitution matrix from file"); 180 String objectName = "appData"; 181 String filename = "appData.dat"; 182 Object data = null; 183 FileInputStream fis = null; 184 ObjectInputStream in = null; 185 try { 186 fis = new FileInputStream(filename); 187 in = new ObjectInputStream(fis); 188 data = in.readObject(); 189 in.close(); 190 } catch (IOException ex) { 191 Console.logException(ex); 192 } catch (ClassNotFoundException ex) { 193 Console.logException(ex); 194 } 195 if (GlobalDataContainer.getInstance().addData(objectName, data)) { 196 CommandHelpers.dataOverwritten(objectName); 197 } 198 appData = (RuleApplicationData) GlobalDataContainer.getInstance().getData("appData"); 199 } 145 200 146 201 … … 733 788 * 734 789 */ 735 private static class RuleApplicationData { 790 private static class RuleApplicationData implements Serializable { 791 792 /** 793 * 794 */ 795 private static final long serialVersionUID = -7559657686755522960L; 736 796 737 797 private HashMap<Integer, ITask> number2task;
Note: See TracChangeset
for help on using the changeset viewer.