1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.analysis
.graph
.core
.criticalpath
;
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
;
22 * Abstract class for critical path algorithms
24 * @author Francis Giraldeau
26 public abstract class AbstractCriticalPathAlgorithm
implements ICriticalPathAlgorithm
{
28 private final TmfGraph fGraph
;
34 * The graph on which to calculate critical path
36 public AbstractCriticalPathAlgorithm(TmfGraph graph
) {
45 public TmfGraph
getGraph() {
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.
54 * The graph on which to add the link
56 * The original graph on which to calculate critical path
58 * The anchor vertex from the path graph
60 * The origin vertex in the main graph
62 * The destination vertex in the main graph
64 * The timestamp of the edge
66 * The type of the edge to create
67 * @return The destination vertex in the path graph
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();
75 TmfVertex tmp
= new TmfVertex(ts
);
76 criticalPath
.add(parentTo
, tmp
);
77 if (parentFrom
== parentTo
) {
78 anchor
.linkHorizontal(tmp
).setType(type
);
80 anchor
.linkVertical(tmp
).setType(type
);
86 * Find the next incoming vertex from another object (in vertical) from a
87 * node in a given direction
92 * The direction in which to search
93 * @return The next incoming vertex
95 public static @Nullable TmfVertex
findIncoming(TmfVertex vertex
, EdgeDirection dir
) {
96 TmfVertex currentVertex
= vertex
;
98 TmfEdge incoming
= currentVertex
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
);
99 if (incoming
!= null) {
100 return currentVertex
;
102 TmfEdge edge
= currentVertex
.getEdge(dir
);
103 if (edge
== null || edge
.getType() != TmfEdge
.EdgeType
.EPS
) {
106 currentVertex
= TmfVertex
.getNeighborFromEdge(edge
, dir
);
112 public String
getID() {
113 return NonNullUtils
.checkNotNull(getClass().getName());
117 public String
getDisplayName() {
118 return NonNullUtils
.checkNotNull(getClass().getSimpleName());