Changeset 1971 for trunk/autoquest-core-tasktrees/src/main/java
- Timestamp:
- 06/18/15 16:42:18 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/CondenseSimilarTasksRule.java
r1967 r1971 27 27 import de.ugoe.cs.autoquest.tasktrees.temporalrelation.utils.SimilarTasks; 28 28 import de.ugoe.cs.autoquest.tasktrees.temporalrelation.utils.TaskTraversal; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor; 29 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 30 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; … … 225 226 } 226 227 228 harmonizeMarkingTemporalRelationships(sessions); 227 229 } 228 230 while (appData.getMostSimilarTasks() != null); … … 268 270 269 271 return appData.finalizeRuleApplicationResult(); 272 } 273 274 /** 275 * 276 */ 277 private void harmonizeMarkingTemporalRelationships(List<IUserSession> sessions) { 278 final Map<ITask, IIteration> harmonizedIterations = new HashMap<>(); 279 final Map<ITask, IOptional> harmonizedOptionals = new HashMap<>(); 280 281 for (IUserSession session : sessions) { 282 for (ITaskInstance instance : session) { 283 instance.accept(new DefaultTaskInstanceTraversingVisitor() { 284 285 @Override 286 public void visit(IIterationInstance iterationInstance) { 287 // visit the children 288 super.visit(iterationInstance); 289 290 // there may have been a model update at the children. If so, set the 291 // new marked task 292 IIteration iteration = iterationInstance.getIteration(); 293 ITask newChildTask = iterationInstance.get(0).getTask(); 294 295 if (newChildTask != iteration.getMarkedTask()) { 296 taskBuilder.setMarkedTask(iteration, newChildTask); 297 } 298 299 // check, if there is a harmonized iteration 300 IIteration harmonizedIteration = 301 harmonizedIterations.get(iteration.getMarkedTask()); 302 303 if ((harmonizedIteration != null) && (iteration != harmonizedIteration)) { 304 // there is a harmonized iteration --> set it as new task 305 /*System.out.println("harmonizing iteration of " + 306 iteration.getMarkedTask() + " from " + iteration + 307 " to " + harmonizedIteration);*/ 308 taskBuilder.setTask(iterationInstance, harmonizedIteration); 309 } 310 else if (harmonizedIteration == null) { 311 // remember this iteration as the harmonized one 312 harmonizedIterations.put(iteration.getMarkedTask(), iteration); 313 } 314 } 315 316 @Override 317 public void visit(IOptionalInstance optionalInstance) { 318 // visit the children 319 super.visit(optionalInstance); 320 321 if (optionalInstance.getChild() == null) { 322 return; 323 } 324 325 // there may have been a model update at the child. If so, set the 326 // new marked task 327 IOptional optional = optionalInstance.getOptional(); 328 ITask newChildTask = optionalInstance.getChild().getTask(); 329 330 if (newChildTask != optional.getMarkedTask()) { 331 taskBuilder.setMarkedTask(optional, newChildTask); 332 } 333 334 // check, if there is a harmonized optional 335 IOptional harmonizedOptional = 336 harmonizedOptionals.get(optional.getMarkedTask()); 337 338 if ((harmonizedOptional != null) && (optional != harmonizedOptional)) { 339 // there is a harmonized optional --> set it as new task 340 /*System.out.println("harmonizing optional of " + 341 optional.getMarkedTask() + " from " + optional + 342 " to " + harmonizedOptional);*/ 343 taskBuilder.setTask(optionalInstance, harmonizedOptional); 344 } 345 else if (harmonizedOptional == null) { 346 // remember this optional as the harmonized one 347 harmonizedOptionals.put(optional.getMarkedTask(), optional); 348 } 349 } 350 351 @Override 352 public void visit(ISelectionInstance selectionInstance) { 353 ITask childTaskBeforeUpdate = selectionInstance.getChild().getTask(); 354 355 super.visit(selectionInstance); 356 357 ITask childTaskAfterUpdate = selectionInstance.getChild().getTask(); 358 359 if (childTaskBeforeUpdate != childTaskAfterUpdate) { 360 // update the selection model if required. 361 ISelection selection = selectionInstance.getSelection(); 362 363 boolean foundOtherInstanceWithOldChild = false; 364 365 for (ITaskInstance instance : selection.getInstances()) { 366 ITask child = ((ISelectionInstance) instance).getChild().getTask(); 367 368 if (child == childTaskBeforeUpdate) { 369 foundOtherInstanceWithOldChild = true; 370 break; 371 } 372 } 373 374 if (!foundOtherInstanceWithOldChild) { 375 taskBuilder.removeChild(selection, childTaskBeforeUpdate); 376 } 377 378 // remove and add the child to ensure to have it only once 379 taskBuilder.removeChild(selection, childTaskAfterUpdate); 380 taskBuilder.addChild(selection, childTaskAfterUpdate); 381 } 382 } 383 384 @Override 385 public void visit(ISequenceInstance sequenceInstance) { 386 ISequence sequence = sequenceInstance.getSequence(); 387 int childIndex = 0; 388 389 for (ITaskInstance child : sequenceInstance) { 390 child.accept(this); 391 392 ITask newChildTask = child.getTask(); 393 394 if (sequence.getChildren().get(childIndex) != newChildTask) { 395 taskBuilder.setChild(sequenceInstance.getSequence(), childIndex, 396 newChildTask); 397 } 398 399 childIndex++; 400 } 401 } 402 403 }); 404 405 } 406 407 // several subsequent instances, which had formerly different tasks, may now have 408 // the same. Hence, they need to be merged. But as everything else would be way too 409 // complex, we only perform the merge, if they occur next to each other on the 410 // same level 411 mergeSubsequentIdenticalMarkingTemporalRelationships(session); 412 } 270 413 } 271 414 … … 430 573 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEST IMPLEMENTATION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 431 574 432 // create also replacements for potential parent iterations or optionals 433 IIteration harmonizedIteration = taskFactory.createNewIteration(); 434 taskBuilder.setMarkedTask(harmonizedIteration, replacementTask); 435 436 IOptional harmonizedOptional = taskFactory.createNewOptional(); 437 taskBuilder.setMarkedTask(harmonizedOptional, replacementTask); 438 575 439 576 for (IUserSession session : appData.getSessions()) { 440 replaceTaskInstances(session, replacements, similarTasks, 441 harmonizedIteration, harmonizedOptional); 442 443 // several subsequent instances, which had formerly different tasks, may now have the 444 // same. Hence, they need to be merged. But as everything else would be way too complex, 445 // we only perform the merge, if they occur next to each other on the same level 446 mergeSubsequentIdenticalMarkingTemporalRelationships(session); 577 replaceTaskInstances(session, replacements, similarTasks); 447 578 } 448 579 … … 1115 1246 private void replaceTaskInstances(ITaskInstanceList taskInstanceList, 1116 1247 Map<ITaskInstance, ITaskInstance> replacements, 1117 SimilarTasks similarTasks, 1118 IIteration harmonizedIteration, 1119 IOptional harmonizedOptional) 1248 SimilarTasks similarTasks) 1120 1249 { 1121 1250 for (int i = 0; i < taskInstanceList.size(); i++) { … … 1129 1258 ISequence task = ((ISequenceInstance) taskInstanceList).getSequence(); 1130 1259 taskBuilder.setChild(task, i, replacement.getTask()); 1260 } 1261 else if (taskInstanceList instanceof IIterationInstance) { 1262 IIteration task = ((IIterationInstance) taskInstanceList).getIteration(); 1263 taskBuilder.setMarkedTask(task, replacement.getTask()); 1131 1264 } 1132 1265 … … 1138 1271 } 1139 1272 else { 1140 ITask modelUpdate = replaceTaskInstances(childInstance, replacements, similarTasks, 1141 harmonizedIteration, harmonizedOptional); 1142 1143 if (modelUpdate != null) { 1144 if (taskInstanceList instanceof ISequenceInstance) { 1145 taskBuilder.setChild 1146 (((ISequenceInstance) taskInstanceList).getSequence(), i, modelUpdate); 1147 } 1148 } 1273 replaceTaskInstances(childInstance, replacements, similarTasks); 1149 1274 } 1150 1275 } … … 1156 1281 private void replaceTaskInstances(IOptionalInstance optionalInstance, 1157 1282 Map<ITaskInstance, ITaskInstance> replacements, 1158 SimilarTasks similarTasks, 1159 IIteration harmonizedIteration, 1160 IOptional harmonizedOptional) 1283 SimilarTasks similarTasks) 1161 1284 { 1162 1285 ITaskInstance childInstance = optionalInstance.getChild(); … … 1175 1298 } 1176 1299 else { 1177 ITask modelUpdate = replaceTaskInstances(childInstance, replacements, similarTasks, 1178 harmonizedIteration, harmonizedOptional); 1179 1180 if (modelUpdate != null) { 1181 taskBuilder.setMarkedTask(optionalInstance.getOptional(), modelUpdate); 1182 } 1300 replaceTaskInstances(childInstance, replacements, similarTasks); 1183 1301 } 1184 1302 } … … 1190 1308 private void replaceTaskInstances(ISelectionInstance selectionInstance, 1191 1309 Map<ITaskInstance, ITaskInstance> replacements, 1192 SimilarTasks similarTasks, 1193 IIteration harmonizedIteration, 1194 IOptional harmonizedOptional) 1310 SimilarTasks similarTasks) 1195 1311 { 1196 1312 TaskComparator comparator = identTaskHandlStrat.getTaskComparator(); … … 1237 1353 } 1238 1354 else { 1239 ITask previousChildTask = childInstance.getTask(); 1240 ITask modelUpdate = replaceTaskInstances(childInstance, replacements, similarTasks, 1241 harmonizedIteration, harmonizedOptional); 1242 1243 if (modelUpdate != null) { 1244 taskBuilder.removeChild(selectionInstance.getSelection(), previousChildTask); 1245 1246 boolean found = false; 1247 for (ITask child : selectionInstance.getSelection().getChildren()) { 1248 if (comparator.equals(child, modelUpdate)) { 1249 found = true; 1250 break; 1251 } 1252 } 1253 1254 if (!found) { 1255 taskBuilder.addChild(selectionInstance.getSelection(), modelUpdate); 1256 } 1257 } 1355 replaceTaskInstances(childInstance, replacements, similarTasks); 1258 1356 } 1259 1357 } … … 1263 1361 * 1264 1362 */ 1265 private ITask replaceTaskInstances(ITaskInstance childInstance, 1266 Map<ITaskInstance, ITaskInstance> replacements, 1267 SimilarTasks similarTasks, 1268 IIteration harmonizedIteration, 1269 IOptional harmonizedOptional) 1363 private void replaceTaskInstances(ITaskInstance childInstance, 1364 Map<ITaskInstance, ITaskInstance> replacements, 1365 SimilarTasks similarTasks) 1270 1366 { 1271 ITask modelUpdate = null;1272 1273 1367 if (childInstance instanceof IIterationInstance) { 1274 ITask markedTask = ((IIterationInstance) childInstance).getIteration().getMarkedTask(); 1275 1276 if ((markedTask == similarTasks.getLeftHandSide()) || 1277 (markedTask == similarTasks.getRightHandSide())) 1278 { 1279 taskBuilder.setTask(childInstance, harmonizedIteration); 1280 modelUpdate = harmonizedIteration; 1281 } 1282 1283 replaceTaskInstances((ITaskInstanceList) childInstance, replacements, similarTasks, 1284 harmonizedIteration, harmonizedOptional); 1368 replaceTaskInstances((ITaskInstanceList) childInstance, replacements, similarTasks); 1285 1369 } 1286 1370 else if (childInstance instanceof IOptionalInstance) { 1287 ITask markedTask = ((IOptionalInstance) childInstance).getOptional().getMarkedTask(); 1288 1289 if ((markedTask == similarTasks.getLeftHandSide()) || 1290 (markedTask == similarTasks.getRightHandSide())) 1291 { 1292 taskBuilder.setTask(childInstance, harmonizedOptional); 1293 modelUpdate = harmonizedOptional; 1294 } 1295 1296 replaceTaskInstances((IOptionalInstance) childInstance, replacements, similarTasks, 1297 harmonizedIteration, harmonizedOptional); 1371 replaceTaskInstances((IOptionalInstance) childInstance, replacements, similarTasks); 1298 1372 } 1299 1373 else if (childInstance instanceof ISelectionInstance) { 1300 replaceTaskInstances((ISelectionInstance) childInstance, replacements, similarTasks, 1301 harmonizedIteration, harmonizedOptional); 1374 replaceTaskInstances((ISelectionInstance) childInstance, replacements, similarTasks); 1302 1375 } 1303 1376 else if (childInstance instanceof ISequenceInstance) { 1304 replaceTaskInstances((ITaskInstanceList) childInstance, replacements, similarTasks, 1305 harmonizedIteration, harmonizedOptional); 1306 } 1307 1308 return modelUpdate; 1377 replaceTaskInstances((ITaskInstanceList) childInstance, replacements, similarTasks); 1378 } 1309 1379 } 1310 1380
Note: See TracChangeset
for help on using the changeset viewer.