Changeset 1850
- Timestamp:
- 12/23/14 11:24:24 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/utils/SimilarTasks.java
r1767 r1850 22 22 23 23 import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 24 import de.ugoe.cs.autoquest.tasktrees.temporalrelation.Task InstanceComparator;24 import de.ugoe.cs.autoquest.tasktrees.temporalrelation.TaskComparator; 25 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskTraversingVisitor; 26 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; … … 28 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 29 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 30 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 31 33 import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; 32 34 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; … … 52 54 53 55 /** 56 * default indicator for unequal tasks 57 */ 58 public static final SimilarTasks UNEQUAL_TASKS = new SimilarTasks(null, null, null); 59 60 /** 54 61 * result of the string like comparison of both task traversals 55 62 */ … … 85 92 */ 86 93 public SimilarTasks(Patch patch, 87 ITask task1,88 94 TaskTraversal traversal1, 89 ITask task2,90 95 TaskTraversal traversal2) 91 96 { 92 this.leftHandSide = task1; 97 if (traversal1 != null) { 98 this.leftHandSide = traversal1.getTask(); 99 } 100 93 101 this.leftHandSideTraversal = traversal1; 94 this.rightHandSide = task2; 102 103 if (traversal2 != null) { 104 this.rightHandSide = traversal2.getTask(); 105 } 106 95 107 this.rightHandSideTraversal = traversal2; 96 108 … … 107 119 * static convenience method to compare two tasks 108 120 */ 109 public static SimilarTasks compareTasks(ITask 110 ITask 111 Task InstanceComparator comparator)121 public static SimilarTasks compareTasks(ITask task1, 122 ITask task2, 123 TaskComparator comparator) 112 124 { 113 return compareTasks(task1, task2, comparator, null, true /* never set to false as a common 114 path may occur several times 115 at distinct places in a traversal 116 and once it may be part of a delta 117 and once not */); 125 return compareTasks(task1, task2, comparator, null); 118 126 } 119 127 120 128 /** 121 129 * static convenience method to compare two tasks but ignoring a given set of subtasks when 122 * creating the traversals. Furhtermore, it can be defined, if subtasks occurring in both 123 * similar tasks are traversed or not. 124 */ 125 public static SimilarTasks compareTasks(ITask task1, 126 ITask task2, 127 TaskInstanceComparator comparator, 128 List<TaskPath> pathsNotToTraverse, 129 boolean traverseCommonPaths) 130 * creating the traversals. 131 */ 132 public static SimilarTasks compareTasks(ITask task1, 133 ITask task2, 134 TaskComparator comparator, 135 List<TaskPath> pathsNotToTraverse) 130 136 { 131 Set<ITask> commonInvolvedTasks; 132 133 if (traverseCommonPaths) { 134 commonInvolvedTasks = new HashSet<ITask>(); 135 } 136 else { 137 commonInvolvedTasks = getCommonInvolvedTasks(task1, task2); 138 } 139 140 TaskTraversal traversal1 = 141 TaskTraversal.getTraversal(task1, commonInvolvedTasks, pathsNotToTraverse); 142 143 TaskTraversal traversal2 = 144 TaskTraversal.getTraversal(task2, commonInvolvedTasks, pathsNotToTraverse); 137 TaskTraversal traversal1 = TaskTraversal.getTraversal(task1, pathsNotToTraverse); 138 TaskTraversal traversal2 = TaskTraversal.getTraversal(task2, pathsNotToTraverse); 145 139 146 140 if ((traversal1.size() <= 0) || (traversal2.size() <= 0)) { 147 141 return null; 148 142 } 149 143 144 return compareTraversals(traversal1, traversal2, comparator); 145 } 146 147 /** 148 * <p> 149 * TODO: comment 150 * </p> 151 * 152 * @param traversal1 153 * @param traversal2 154 * @param comparator 155 * @return 156 */ 157 public static SimilarTasks compareTraversals(TaskTraversal traversal1, 158 TaskTraversal traversal2, 159 TaskComparator comparator) 160 { 150 161 Patch patch = new TaskTraversalMyersDiff(comparator).getDiff(traversal1, traversal2); 151 162 152 SimilarTasks result = new SimilarTasks(patch, t ask1, traversal1, task2, traversal2);163 SimilarTasks result = new SimilarTasks(patch, traversal1, traversal2); 153 164 154 165 return result; … … 161 172 * the remaining traversals can be the basis of a merge. 162 173 */ 163 public static SimilarTasks getMergableLevelOfSimilarity(SimilarTasks 164 Task InstanceComparator comparator)174 public static SimilarTasks getMergableLevelOfSimilarity(SimilarTasks source, 175 TaskComparator comparator) 165 176 { 166 177 SimilarTasks similarTasks = source; … … 175 186 similarTasks = compareTasks 176 187 (similarTasks.getLeftHandSide(), similarTasks.getRightHandSide(), 177 comparator, pathsToIgnore , true);178 179 similarTasks.dump(System.out);188 comparator, pathsToIgnore); 189 190 // similarTasks.dump(System.out); 180 191 181 192 List<TaskPath> furtherPathsToIgnore = similarTasks.getPathsToIgnore(); 182 193 183 for (TaskPath path : furtherPathsToIgnore) { 184 System.out.println(path); 185 } 194 // System.out.println("further paths to ignore:"); 195 // for (TaskPath path : furtherPathsToIgnore) { 196 // System.out.println(" " + path); 197 // } 186 198 187 199 for (TaskPath pathToAdd : furtherPathsToIgnore) { … … 201 213 while (pathsToIgnore.size() > prevPathsToIgnoreCount); 202 214 203 return similarTasks; 215 if (similarTasks.isStillWellAligned()) { 216 return similarTasks; 217 } 218 else { 219 // this may happen, if due to interleaving iterations the similarities of the task 220 // move and the diff algorithm does not align them anymore as optimal as possible 221 // because some similarities were lost due to not comparing all paths anymore. 222 return null; 223 } 204 224 } 205 225 … … 242 262 243 263 return deltas.size() > 0; 264 } 265 266 /** 267 * <p> 268 * TODO: comment 269 * </p> 270 * 271 * @return 272 */ 273 public boolean isStillWellAligned() { 274 if (isInBetweenDifference()) { 275 return true; 276 } 277 else { 278 for (Delta delta : patch.getDeltas()) { 279 if (delta.getType() == Delta.TYPE.INSERT) { 280 if ((delta.getOriginal().getPosition() == 0) || 281 (delta.getOriginal().getPosition() == leftHandSideTraversal.size())) 282 { 283 return false; 284 } 285 } 286 else if (delta.getType() == Delta.TYPE.DELETE) { 287 if ((delta.getRevised().getPosition() == 0) || 288 (delta.getRevised().getPosition() == rightHandSideTraversal.size())) 289 { 290 return false; 291 } 292 } 293 } 294 } 295 296 return true; 244 297 } 245 298 … … 328 381 } 329 382 383 // check for any parent optional that may be empty and can hence not be flattened 384 TaskPath tmppath = new TaskPath(); 385 tmppath.add(leftHandSide, 0); 386 getParentOptionals(tmppath, result); 387 tmppath = new TaskPath(); 388 tmppath.add(rightHandSide, 0); 389 getParentOptionals(tmppath, result); 390 330 391 // check if there are common subtasks on both sides that lie outside any delta and 331 392 // that hence should be ignored (especially when performing flattening of task 332 // instances later with the goal to preserve as many subtasks and respective instances 393 // instances later with the goal to preserve as many subtasks and respective instances) 333 394 int deltaIndex = 0; 334 395 int leftTraversalIndex = 0; … … 823 884 (path2.get(j).getTask() instanceof IIteration)) 824 885 { 825 System.out.println("found paths to real intersecting parents");826 int[] indexBuf = leftHandSideTraversal.getIndexesRootedBy(path1Prefix);827 System.out.println(idxsPath1[0] + "(" + indexBuf[0] + ") " + idxsPath1[1] +828 "(" + indexBuf[1] + ") " + path1Prefix);829 indexBuf = rightHandSideTraversal.getIndexesRootedBy(path2Prefix);830 System.out.println(idxsPath2[0] + "(" + indexBuf[0] + ") " + idxsPath2[1] +831 "(" + indexBuf[1] + ") " + path2Prefix);886 // System.out.println("found paths to real intersecting parents"); 887 // int[] indexBuf = leftHandSideTraversal.getIndexesRootedBy(path1Prefix); 888 // System.out.println(idxsPath1[0] + "(" + indexBuf[0] + ") " + idxsPath1[1] + 889 // "(" + indexBuf[1] + ") " + path1Prefix); 890 // indexBuf = rightHandSideTraversal.getIndexesRootedBy(path2Prefix); 891 // System.out.println(idxsPath2[0] + "(" + indexBuf[0] + ") " + idxsPath2[1] + 892 // "(" + indexBuf[1] + ") " + path2Prefix); 832 893 833 894 paths.add(path1Prefix); … … 854 915 if (!commonPath.get(j).equals(comparePath.get(j))) { 855 916 while (commonPath.size() > j) { 856 commonPath.remove (j);917 commonPath.removeLast(); 857 918 } 858 919 break; … … 957 1018 (indexes[1] < (chunk.getPosition() + chunk.size()))) // ends in the delta 958 1019 { 959 System.out.println("found path to parent task lieing completely in the " +960 "delta: " + path.subPath(0, i + 1));1020 // System.out.println("found path to parent task lieing completely in the " + 1021 // "delta: " + path.subPath(0, i + 1)); 961 1022 result.add(path.subPath(0, i + 1)); 962 1023 break; … … 964 1025 } 965 1026 } 1027 } 1028 } 1029 1030 /** 1031 * 1032 */ 1033 private void getParentOptionals(TaskPath taskPath, List<TaskPath> result) { 1034 ITask task = taskPath.getLast(); 1035 1036 if (task instanceof IOptional) { 1037 result.add(new TaskPath(taskPath)); 1038 } 1039 else if (task instanceof ISequence) { 1040 for (int i = 0; i < ((ISequence) task).getChildren().size(); i++) { 1041 taskPath.add(((ISequence) task).getChildren().get(i), i); 1042 getParentOptionals(taskPath, result); 1043 taskPath.removeLast(); 1044 } 1045 } 1046 else if (task instanceof ISelection) { 1047 for (int i = 0; i < ((ISelection) task).getChildren().size(); i++) { 1048 taskPath.add(((ISelection) task).getChildren().get(i), 0); 1049 getParentOptionals(taskPath, result); 1050 taskPath.removeLast(); 1051 } 1052 } 1053 else if (task instanceof IIteration) { 1054 taskPath.add(((IIteration) task).getMarkedTask(), 0); 1055 getParentOptionals(taskPath, result); 1056 taskPath.removeLast(); 966 1057 } 967 1058 }
Note: See TracChangeset
for help on using the changeset viewer.