Detects SubstructureItems that represent the (undirected) cliques in the specified graph.
Remarks
A clique is a subset of nodes of the same type (nodeTypes) that are all adjacent (i.e., connected) to each other.
Cliques with less than minimumSize nodes are ignored.
Note that finding a maximum clique is NP-hard. Hence, we only use a simple heuristic approach that doesn't guarantee to find all/the largest clique. It only identifies cliques that have at least one node with at most one non-clique neighbor. Furthermore, a node can only be contained in a single clique, i.e., the returned cliques are non-overlapping.
Examples
// prepare the clique detection algorithm
const algorithm = new CliqueSubstructures()
// run the algorithm
const result = algorithm.run(graph)
// highlight the cliques
for (const clique of result.cliques) {
for (const node of clique.nodes) {
graph.setStyle(node, highlightNodeStyle)
}
for (const edge of clique.edges) {
graph.setStyle(edge, highlightEdgeStyle)
}
}
// prepare the clique detection algorithm
const algorithm = new CliqueSubstructures({
// only nodes with the same tags can be a clique
nodeTypes: (node: INode): any => node.tag,
})
// run the algorithm
const result = algorithm.run(graph)
// highlight the cliques
for (const clique of result.cliques) {
for (const node of clique.nodes) {
graph.setStyle(node, highlightNodeStyle)
}
for (const edge of clique.edges) {
graph.setStyle(edge, highlightEdgeStyle)
}
}
Type Details
- yFiles module
- view-layout-bridge
Constructors
Parameters
A map of options to pass to the method.
- minimumSize - number
- The minimum size of a clique. This option sets the minimumSize property on the created object.
- nodeTypes - ItemMapping<INode,any>
- A mapping which maps the type of each node. This option either sets the value directly or recursively sets properties to the instance of the nodeTypes property on the created object.
- subgraphNodes - ItemCollection<INode>
- The collection of nodes which define a subset of the graph for the algorithms to work on. This option either sets the value directly or recursively sets properties to the instance of the subgraphNodes property on the created object.
- subgraphEdges - ItemCollection<IEdge>
- The collection of edges which define a subset of the graph for the algorithms to work on. This option either sets the value directly or recursively sets properties to the instance of the subgraphEdges property on the created object.
Properties
Gets or sets the minimum size of a clique.
Remarks
Cliques with fewer nodes are ignored.
Default is 3
.
3
.Gets or sets a mapping which maps the type of each node.
Remarks
An arbitrary object. Nodes returning equal objects are considered to be of the same type.
If none is provided, all nodes are considered as equal.
Gets or sets the collection of edges which define a subset of the graph for the algorithms to work on.
Remarks
If nothing is set, all edges of the graph will be processed.
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 algorithm.
ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.
Examples
// prepare the clique detection algorithm
const algorithm = new CliqueSubstructures({
// Ignore edges without target arrow heads
subgraphEdges: {
excludes: (edge: IEdge): boolean =>
edge.style instanceof PolylineEdgeStyle &&
edge.style.targetArrow instanceof Arrow &&
edge.style.targetArrow.type === ArrowType.NONE,
},
})
// run the algorithm
const result = algorithm.run(graph)
// highlight the cliques
for (const clique of result.cliques) {
for (const node of clique.nodes) {
graph.setStyle(node, highlightNodeStyle)
}
for (const edge of clique.edges) {
graph.setStyle(edge, highlightEdgeStyle)
}
}
Gets or sets the collection of nodes which define a subset of the graph for the algorithms to work on.
Remarks
If nothing is set, all nodes of the graph will be processed.
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 algorithm.
Examples
// prepare the clique detection algorithm
const algorithm = new CliqueSubstructures({
subgraphNodes: {
// only consider elliptical nodes in the graph
includes: (node: INode): boolean =>
node.style instanceof ShapeNodeStyle &&
node.style.shape === ShapeNodeShape.ELLIPSE,
// but ignore the first node, regardless of its shape
excludes: graph.nodes.first()!,
},
})
// run the algorithm
const result = algorithm.run(graph)
// highlight the cliques
for (const clique of result.cliques) {
for (const node of clique.nodes) {
graph.setStyle(node, highlightNodeStyle)
}
for (const edge of clique.edges) {
graph.setStyle(edge, highlightEdgeStyle)
}
}
Methods
Returns a list of SubstructureItems that represent the (undirected) cliques in the specified graph.
Remarks
A clique is a subset of nodes of the same type (nodeTypes) that are all adjacent (i.e., connected) to each other.
Cliques with less than minimumSize nodes are ignored.
Note that finding a maximum clique is NP-hard. Hence, we only use a simple heuristic approach that doesn't guarantee to find all/the largest clique. It only identifies cliques that have at least one node with at most one non-clique neighbor. Furthermore, a node can only be contained in a single clique, i.e., the returned cliques are non-overlapping.
Parameters
A map of options to pass to the method.
- graph - IGraph
- The graph to find the substructures in.
Returns
- ↪CliqueSubstructuresResult
- A list of SubstructureItems that represent the cliques.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the algorithm can't create a valid result due to an invalid graph structure or wrongly configured properties.
Examples
// prepare the clique detection algorithm
const algorithm = new CliqueSubstructures()
// run the algorithm
const result = algorithm.run(graph)
// highlight the cliques
for (const clique of result.cliques) {
for (const node of clique.nodes) {
graph.setStyle(node, highlightNodeStyle)
}
for (const edge of clique.edges) {
graph.setStyle(edge, highlightEdgeStyle)
}
}
// prepare the clique detection algorithm
const algorithm = new CliqueSubstructures({
// only nodes with the same tags can be a clique
nodeTypes: (node: INode): any => node.tag,
})
// run the algorithm
const result = algorithm.run(graph)
// highlight the cliques
for (const clique of result.cliques) {
for (const node of clique.nodes) {
graph.setStyle(node, highlightNodeStyle)
}
for (const edge of clique.edges) {
graph.setStyle(edge, highlightEdgeStyle)
}
}
3
.