Class GraphHelper
- java.lang.Object
-
- org.eclipse.viatra.query.runtime.base.itc.alg.misc.GraphHelper
-
public class GraphHelper extends java.lang.Object
Utility class for graph related operations.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V> java.util.List<V>
constructPath(V source, V target, java.util.Set<V> nodesInGraph, IGraphDataSource<V> graphDataSource)
Constructs a path between source and target in the given graph.static <V> int
getEdgeCount(V node, IGraphDataSource<V> graphDataSource)
Returns the number of self-loop edges for the given node.static <V> int
getEdgeCount(V source, V target, IGraphDataSource<V> graphDataSource)
Returns the number of edges between the given source and target nodes.static <V> Graph<V>
getSubGraph(java.util.Collection<V> nodesInSubGraph, IBiDirectionalGraphDataSource<V> graphDataSource)
Returns the subgraph from the givenIBiDirectionalGraphDataSource
which contains the given set of nodes.
-
-
-
Method Detail
-
getSubGraph
public static <V> Graph<V> getSubGraph(java.util.Collection<V> nodesInSubGraph, IBiDirectionalGraphDataSource<V> graphDataSource)
Returns the subgraph from the givenIBiDirectionalGraphDataSource
which contains the given set of nodes.- Parameters:
nodesInSubGraph
- the nodes that are present in the subgraphgraphDataSource
- the graph data source for the original graph- Returns:
- the subgraph associated to the given nodes
-
constructPath
public static <V> java.util.List<V> constructPath(V source, V target, java.util.Set<V> nodesInGraph, IGraphDataSource<V> graphDataSource)
Constructs a path between source and target in the given graph. Both theIGraphDataSource
and the set of nodes are used, this way it is possible to construct a path in a given subgraph. The returnedList
contains the nodes along the path (this means that there is an edge in the graph between two consecutive nodes). A self loop (one edge) is indicated with the source node being present two times in the returnedList
.- Parameters:
source
- the source nodetarget
- the target nodenodesInGraph
- the nodes that are present in the subgraphgraphDataSource
- the graph data source- Returns:
- the path between the two nodes
-
getEdgeCount
public static <V> int getEdgeCount(V node, IGraphDataSource<V> graphDataSource)
Returns the number of self-loop edges for the given node.- Parameters:
node
- the nodegraphDataSource
- the graph data source- Returns:
- the number of self-loop edges
-
getEdgeCount
public static <V> int getEdgeCount(V source, V target, IGraphDataSource<V> graphDataSource)
Returns the number of edges between the given source and target nodes.- Parameters:
source
- the source nodetarget
- the target nodegraphDataSource
- the graph data source- Returns:
- the number of parallel edges between the two nodes
-
-