Analysis: Add the active path module
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.graph.core / src / org / eclipse / tracecompass / internal / analysis / graph / core / criticalpath / AbstractCriticalPathAlgorithm.java
1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.analysis.graph.core.criticalpath;
11
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker;
14 import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge;
15 import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
16 import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
17 import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex.EdgeDirection;
18 import org.eclipse.tracecompass.analysis.graph.core.criticalpath.ICriticalPathAlgorithm;
19 import org.eclipse.tracecompass.common.core.NonNullUtils;
20
21 /**
22 * Abstract class for critical path algorithms
23 *
24 * @author Francis Giraldeau
25 */
26 public abstract class AbstractCriticalPathAlgorithm implements ICriticalPathAlgorithm {
27
28 private final TmfGraph fGraph;
29
30 /**
31 * Constructor
32 *
33 * @param graph
34 * The graph on which to calculate critical path
35 */
36 public AbstractCriticalPathAlgorithm(TmfGraph graph) {
37 fGraph = graph;
38 }
39
40 /**
41 * Get the graph
42 *
43 * @return the graph
44 */
45 public TmfGraph getGraph() {
46 return fGraph;
47 }
48
49 /**
50 * Copy link of type TYPE between nodes FROM and TO in the graph PATH. The
51 * return value is the tail node for the new path.
52 *
53 * @param criticalPath
54 * The graph on which to add the link
55 * @param graph
56 * The original graph on which to calculate critical path
57 * @param anchor
58 * The anchor vertex from the path graph
59 * @param from
60 * The origin vertex in the main graph
61 * @param to
62 * The destination vertex in the main graph
63 * @param ts
64 * The timestamp of the edge
65 * @param type
66 * The type of the edge to create
67 * @return The destination vertex in the path graph
68 */
69 public TmfVertex copyLink(TmfGraph criticalPath, TmfGraph graph, TmfVertex anchor, TmfVertex from, TmfVertex to, long ts, TmfEdge.EdgeType type) {
70 IGraphWorker parentFrom = graph.getParentOf(from);
71 IGraphWorker parentTo = graph.getParentOf(to);
72 if (parentTo == null) {
73 throw new NullPointerException();
74 }
75 TmfVertex tmp = new TmfVertex(ts);
76 criticalPath.add(parentTo, tmp);
77 if (parentFrom == parentTo) {
78 anchor.linkHorizontal(tmp).setType(type);
79 } else {
80 anchor.linkVertical(tmp).setType(type);
81 }
82 return tmp;
83 }
84
85 /**
86 * Find the next incoming vertex from another object (in vertical) from a
87 * node in a given direction
88 *
89 * @param vertex
90 * The starting vertex
91 * @param dir
92 * The direction in which to search
93 * @return The next incoming vertex
94 */
95 public static @Nullable TmfVertex findIncoming(TmfVertex vertex, EdgeDirection dir) {
96 TmfVertex currentVertex = vertex;
97 while (true) {
98 TmfEdge incoming = currentVertex.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE);
99 if (incoming != null) {
100 return currentVertex;
101 }
102 TmfEdge edge = currentVertex.getEdge(dir);
103 if (edge == null || edge.getType() != TmfEdge.EdgeType.EPS) {
104 break;
105 }
106 currentVertex = TmfVertex.getNeighborFromEdge(edge, dir);
107 }
108 return null;
109 }
110
111 @Override
112 public String getID() {
113 return NonNullUtils.checkNotNull(getClass().getName());
114 }
115
116 @Override
117 public String getDisplayName() {
118 return NonNullUtils.checkNotNull(getClass().getSimpleName());
119 }
120
121 }
This page took 0.049052 seconds and 5 git commands to generate.