1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.tasktrees.treeifc; |
---|
16 | |
---|
17 | import java.util.Collection; |
---|
18 | import java.util.HashMap; |
---|
19 | import java.util.HashSet; |
---|
20 | import java.util.LinkedList; |
---|
21 | import java.util.List; |
---|
22 | import java.util.Map; |
---|
23 | import java.util.Set; |
---|
24 | |
---|
25 | /** |
---|
26 | * <p> |
---|
27 | * TODO comment |
---|
28 | * </p> |
---|
29 | * |
---|
30 | * @author Patrick Harms |
---|
31 | */ |
---|
32 | public class TaskTreeUtils { |
---|
33 | |
---|
34 | /** |
---|
35 | * |
---|
36 | */ |
---|
37 | public static boolean isChild(ITask potentialChild, ITask potentialParent) { |
---|
38 | if (potentialParent instanceof IStructuringTemporalRelationship) { |
---|
39 | for (ITask child : ((IStructuringTemporalRelationship) potentialParent).getChildren()) { |
---|
40 | if (child.equals(potentialChild) || isChild(potentialChild, child)) { |
---|
41 | return true; |
---|
42 | } |
---|
43 | } |
---|
44 | } |
---|
45 | else if (potentialParent instanceof IMarkingTemporalRelationship) { |
---|
46 | ITask child = ((IMarkingTemporalRelationship) potentialParent).getMarkedTask(); |
---|
47 | if (child.equals(potentialChild) || isChild(potentialChild, child)) { |
---|
48 | return true; |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | return false; |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * |
---|
57 | */ |
---|
58 | public static Set<ISequence> getMostProminentTasks(ITaskModel model, |
---|
59 | Collection<ITask> tasks) |
---|
60 | { |
---|
61 | List<ISequence> sequences = new LinkedList<>(); |
---|
62 | |
---|
63 | for (ITask task : tasks) { |
---|
64 | if (task instanceof ISequence) { |
---|
65 | sequences.add((ISequence) task); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | return getMostProminentSequences(model, sequences); |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * |
---|
74 | */ |
---|
75 | public static Set<ISequence> getMostProminentSequences(ITaskModel model, |
---|
76 | Collection<ISequence> tasks) |
---|
77 | { |
---|
78 | Map<Integer, List<ISequence>> sortedSequences = new HashMap<>(); |
---|
79 | |
---|
80 | int maxCoverage = 0; |
---|
81 | |
---|
82 | for (ITask task : tasks) { |
---|
83 | int coveredEvents = |
---|
84 | model.getTaskInfo((ISequence) task).getMeasureValue(TaskMetric.EVENT_COVERAGE); |
---|
85 | |
---|
86 | List<ISequence> sequencesWithSameCoverage = sortedSequences.get(coveredEvents); |
---|
87 | |
---|
88 | if (sequencesWithSameCoverage == null) { |
---|
89 | sequencesWithSameCoverage = new LinkedList<>(); |
---|
90 | sortedSequences.put(coveredEvents, sequencesWithSameCoverage); |
---|
91 | } |
---|
92 | |
---|
93 | sequencesWithSameCoverage.add((ISequence) task); |
---|
94 | |
---|
95 | maxCoverage = Math.max(maxCoverage, coveredEvents); |
---|
96 | } |
---|
97 | |
---|
98 | Set<ISequence> result = new HashSet<>(); |
---|
99 | |
---|
100 | for (int i = maxCoverage; i > 0; i--) { |
---|
101 | List<ISequence> sequencesWithSameCoverage = sortedSequences.get(i); |
---|
102 | |
---|
103 | if (sequencesWithSameCoverage != null) { |
---|
104 | result.addAll(sequencesWithSameCoverage); |
---|
105 | |
---|
106 | if (result.size() * 5 >= tasks.size()) { |
---|
107 | break; |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | return result; |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * |
---|
117 | */ |
---|
118 | private TaskTreeUtils() { /* prevent instantiation */ } |
---|
119 | } |
---|