source: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/TaskTreeUtils.java @ 2030

Last change on this file since 2030 was 2030, checked in by pharms, 9 years ago
  • moved utility method to identify most prominent tasks to central location
File size: 3.7 KB
Line 
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
15package de.ugoe.cs.autoquest.tasktrees.treeifc;
16
17import java.util.Collection;
18import java.util.HashMap;
19import java.util.HashSet;
20import java.util.LinkedList;
21import java.util.List;
22import java.util.Map;
23import java.util.Set;
24
25/**
26 * <p>
27 * TODO comment
28 * </p>
29 *
30 * @author Patrick Harms
31 */
32public 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}
Note: See TracBrowser for help on using the repository browser.