This class provides methods that check structural properties of a given graph.
Remarks
Definitions
- Cycle – An edge path with nodes
n0, n1, n2, ... , nk
forms a cycle ifn0 = nk
and consists of at least one edge. - Acyclic graph – A graph that contains no directed cycle.
- Cyclic graph – A graph that contains a directed cycle.
- Connected graph – A graph in which there exists an undirected path of edges between every pair of nodes.
- Strongly connected graph – A graph in which there exists a directed path between each pair of nodes.
- Biconnected graph – A graph that has no cut vertex or articulation point (i.e., a node whose removal disconnects the graph).
- Bipartite graph – A graph whose nodes can be partitioned into two sets such that each edge connects two nodes of different sets.
- Tree – A acyclic graph, in which any pair of nodes is connected through a path. If one node of a tree is distinguished from the other nodes, then the tree is called rooted tree.
- N-ary tree – A directed rooted tree where each node has a maximum of
n
children. - Forest – A graph whose connected components are trees.
- Simple graph – An undirected graph that contains no self-loops or parallel edges.
- Planar graph – A graph that can be drawn on the plane without edge crossings.
- Multiple Edges – Multiple edges are edges that are incident to the same two nodes.
subgraphNodes and subgraphEdges can be used to run the analysis on an induced subgraph, only. Note that the subgraph will be reevaluated for each analysis.
Examples
const analyzer = new GraphStructureAnalyzer(graph)
Type Details
- yfiles module
- view-layout-bridge
- yfiles-umd modules
- view-layout-bridge
- Legacy UMD name
- yfiles.analysis.GraphStructureAnalyzer
See Also
Constructors
Creates a new instance for the given graph.
Parameters
A map of options to pass to the method.
- graph - IGraph
- The graph to provide analysis methods for.
- subgraphNodes - ItemCollection<INode>
The collection of nodes which define an induced subgraph for the algorithms to work on. This option sets the subgraphNodes property on the created object.
- subgraphEdges - ItemCollection<IEdge>
The collection of edges which define an induced subgraph for the algorithms to work on. This option sets the subgraphEdges property on the created object.
Properties
Gets or sets the collection of edges which define an induced subgraph for the algorithms to work on.
Remarks
If nothing is set, all edges of the graph will be considered.
If only the excludes are set all edges in the graph except those provided in the excludes are processed.
Note that edges which start or end at nodes which are not in the subgraphNodes are automatically not considered by the algorithms.
ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithms.
Examples
Gets or sets the collection of nodes which define an induced subgraph for the algorithms to work on.
Remarks
If nothing is set, all nodes of the graph will be considered.
If only the excludes are set all nodes in the graph except those provided in the excludes are processed.
ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithms.
Examples
Methods
Computes the average degree of the graph.
Remarks
|E| / |V|
for directed graphs2 * |E| / |V|
for undirected graphs
Complexity
O(1)
, O(|V| + |E|)
when subgraph filtering is enabled.
Parameters
A map of options to pass to the method.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪number
- The average degree of the given graph.
Computes the average weighted degree of the graph.
Remarks
edge_weight_sum / |V|
for directed graphs2 * edge_weight_sum / |V|
for undirected graphs
Complexity
O(|E|)
, O(|V| + |E|) when subgraph filtering is enabled
Parameters
A map of options to pass to the method.
- edgeWeights - IMapper<IEdge,number>
- The mapping that provides the weights of the edges.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪number
- The average weighted degree of the given graph
Computes the density of the graph.
Remarks
|E| / (|N| * (|N| - 1))
for directed simple graphs2 * |E| / (|N| * (|N| - 1))
for undirected simple graphs
Parameters
A map of options to pass to the method.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪number
- The density of the given graph.
Computes the diameter of the graph.
Remarks
Parameters
A map of options to pass to the method.
- edgeCosts - IMapper<IEdge,number>
- The mapping that provides the costs of the edges.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪number
- The diameter of the given graph.
Determines the multiple edges of the directed or undirected graph.
Remarks
Complexity
O(|V| + |E|)
Parameters
A map of options to pass to the method.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪IEnumerable<IEnumerable<IEdge>>
- A collection of multiple edges.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Determines the multiple edges adjacent to the given node of the directed or undirected graph.
Remarks
Parameters
A map of options to pass to the method.
- node - INode
- The node that is adjacent to the multiple edge to determine.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪IEnumerable<IEnumerable<IEdge>>
- A collection of multiple edges.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Determines the multiple edges between the source and target node of the given edge of the directed or undirected graph.
Remarks
Parameters
A map of options to pass to the method.
- edge - IEdge
- The edge with the same source and target as the edges to determine.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪IEnumerable<IEdge>
- The multiple edges.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Gets the nodes of the graph in topological order.
Remarks
Complexity
O(|V| + |E|)
Preconditions
- The graph must be
.
Returns
- ↪IEnumerable<INode>
- The nodes of the graph in topological order.
Determines whether or not the directed or undirected graph contains multiple edges.
Remarks
Returns
- ↪boolean
true
if the graph contains multiple edges,false
otherwise
Examples
const isMultipleEdgeFree = new GraphStructureAnalyzer(graph).isSimple()
Sample Graphs
Determines whether the graph is acyclic.
Remarks
Parameters
A map of options to pass to the method.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪boolean
true
if the graph is acyclic,false
, otherwise
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Examples
const isAcyclic = new GraphStructureAnalyzer(graph).isAcyclic(true)
See Also
Sample Graphs
Determines whether or not the undirected graph is biconnected.
Remarks
Returns
- ↪boolean
true
if the graph is biconnected,false
otherwise
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Examples
const isBiconnected = new GraphStructureAnalyzer(graph).isBiconnected()
Sample Graphs
Determines whether or not the undirected graph is bipartite.
Remarks
Returns
- ↪boolean
true
if the graph is bipartite,false
otherwise
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Examples
const isBipartite = new GraphStructureAnalyzer(graph).isBipartite()
Sample Graphs
Determines whether or not the graph is connected.
Remarks
Returns
- ↪boolean
true
if the graph is connected,false
otherwise
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Examples
const isConnected = new GraphStructureAnalyzer(graph).isConnected()
Sample Graphs
Determines whether the graph is cyclic.
Remarks
Parameters
A map of options to pass to the method.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪boolean
true
if the graph is cyclic,false
, otherwise
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Examples
const isCyclic = new GraphStructureAnalyzer(graph).isCyclic(true)
See Also
Sample Graphs
Determines whether the graph is a directed (undirected) forest.
Remarks
Parameters
A map of options to pass to the method.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪boolean
true
if the graph is a forest,false
otherwise
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Examples
const isForest = new GraphStructureAnalyzer(graph).isForest(true)
See Also
Sample Graphs
Determines whether or not the graph is a directed rooted tree where each node has a maximum of n
children.
Returns
- ↪boolean
true
if the graph is a directed rooted tree where each node has at mostn
children,false
otherwise
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Examples
const isNaryTree = new GraphStructureAnalyzer(graph).isNaryTree(3)
See Also
Sample Graphs
Determines whether or not the graph is planar.
Remarks
Returns
- ↪boolean
true
if the graph is planar,false
, otherwise.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Examples
const isPlanar = new GraphStructureAnalyzer(graph).isPlanar()
Sample Graphs
Determines whether or not the given undirected graph is simple.
Remarks
An undirected graph is called simple if there are no two edges that connect the same nodes as well as no self-loops.
Since an IGraph can have edges ending at other edges, a graph containing those constructs will also not be simple.
Returns
- ↪boolean
true
if the graph is simple,false
otherwise
Examples
const isSimple = new GraphStructureAnalyzer(graph).isSimple()
Sample Graphs
Determines whether or not the directed graph is strongly connected.
Remarks
Returns
- ↪boolean
true
if the graph is strongly connected,false
, otherwise
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Examples
const isStronglyConnected = new GraphStructureAnalyzer(
graph
).isStronglyConnected()
Sample Graphs
Determines whether or not the graph is a directed (undirected) tree.
Parameters
A map of options to pass to the method.
- directed - boolean
- Whether or not to respect the direction of the edges.
Returns
- ↪boolean
true
if the graph is a tree,false
otherwise
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph has edge to edge connections.
Examples
const isTree = new GraphStructureAnalyzer(graph).isTree(false)