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
diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/internal/analysis/graph/core/criticalpath/AbstractCriticalPathAlgorithm.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/internal/analysis/graph/core/criticalpath/AbstractCriticalPathAlgorithm.java
new file mode 100644 (file)
index 0000000..ce9051f
--- /dev/null
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.analysis.graph.core.criticalpath;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
+import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex.EdgeDirection;
+import org.eclipse.tracecompass.analysis.graph.core.criticalpath.ICriticalPathAlgorithm;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+
+/**
+ * Abstract class for critical path algorithms
+ *
+ * @author Francis Giraldeau
+ */
+public abstract class AbstractCriticalPathAlgorithm implements ICriticalPathAlgorithm {
+
+    private final TmfGraph fGraph;
+
+    /**
+     * Constructor
+     *
+     * @param graph
+     *            The graph on which to calculate critical path
+     */
+    public AbstractCriticalPathAlgorithm(TmfGraph graph) {
+        fGraph = graph;
+    }
+
+    /**
+     * Get the graph
+     *
+     * @return the graph
+     */
+    public TmfGraph getGraph() {
+        return fGraph;
+    }
+
+    /**
+     * Copy link of type TYPE between nodes FROM and TO in the graph PATH. The
+     * return value is the tail node for the new path.
+     *
+     * @param criticalPath
+     *            The graph on which to add the link
+     * @param graph
+     *            The original graph on which to calculate critical path
+     * @param anchor
+     *            The anchor vertex from the path graph
+     * @param from
+     *            The origin vertex in the main graph
+     * @param to
+     *            The destination vertex in the main graph
+     * @param ts
+     *            The timestamp of the edge
+     * @param type
+     *            The type of the edge to create
+     * @return The destination vertex in the path graph
+     */
+    public TmfVertex copyLink(TmfGraph criticalPath, TmfGraph graph, TmfVertex anchor, TmfVertex from, TmfVertex to, long ts, TmfEdge.EdgeType type) {
+        IGraphWorker parentFrom = graph.getParentOf(from);
+        IGraphWorker parentTo = graph.getParentOf(to);
+        if (parentTo == null) {
+            throw new NullPointerException();
+        }
+        TmfVertex tmp = new TmfVertex(ts);
+        criticalPath.add(parentTo, tmp);
+        if (parentFrom == parentTo) {
+            anchor.linkHorizontal(tmp).setType(type);
+        } else {
+            anchor.linkVertical(tmp).setType(type);
+        }
+        return tmp;
+    }
+
+    /**
+     * Find the next incoming vertex from another object (in vertical) from a
+     * node in a given direction
+     *
+     * @param vertex
+     *            The starting vertex
+     * @param dir
+     *            The direction in which to search
+     * @return The next incoming vertex
+     */
+    public static @Nullable TmfVertex findIncoming(TmfVertex vertex, EdgeDirection dir) {
+        TmfVertex currentVertex = vertex;
+        while (true) {
+            TmfEdge incoming = currentVertex.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE);
+            if (incoming != null) {
+                return currentVertex;
+            }
+            TmfEdge edge = currentVertex.getEdge(dir);
+            if (edge == null || edge.getType() != TmfEdge.EdgeType.EPS) {
+                break;
+            }
+            currentVertex = TmfVertex.getNeighborFromEdge(edge, dir);
+        }
+        return null;
+    }
+
+    @Override
+    public String getID() {
+        return NonNullUtils.checkNotNull(getClass().getName());
+    }
+
+    @Override
+    public String getDisplayName() {
+        return NonNullUtils.checkNotNull(getClass().getSimpleName());
+    }
+
+}
This page took 0.025983 seconds and 5 git commands to generate.