-
Notifications
You must be signed in to change notification settings - Fork 7
Add documentation for missing procedures (fixes #268) #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6ae4adc
Add documentation for missing procedures (fixes #268)
shahar-biron b231f2d
Fix PR issues: markdown, link fragments, and spelling
shahar-biron 3fba1c6
Remove accidentally committed files and fix spelling
shahar-biron 73bcdd9
Add MSF to wordlist
shahar-biron 70df0c6
Fix alphabetical order in wordlist per CodeRabbit review
shahar-biron e061d7f
Merge branch 'main' into docs/add-missing-procedures-268
gkorland 9906401
Apply suggestion from @coderabbitai[bot]
AviAvni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| --- | ||
| title: "MSF" | ||
| description: "Minimum Spanning Forest Algorithm" | ||
| parent: "Algorithms" | ||
| nav_order: 9 | ||
| --- | ||
|
|
||
| # Minimum Spanning Forest (MSF) | ||
|
|
||
| The Minimum Spanning Forest algorithm computes the minimum spanning forest of a graph. A minimum spanning forest is a collection of minimum spanning trees, one for each connected component in the graph. | ||
|
|
||
| ## What is a Minimum Spanning Forest? | ||
|
|
||
| - For a **connected graph**, the MSF is a single minimum spanning tree (MST) that connects all nodes with the minimum total edge weight | ||
| - For a **disconnected graph**, the MSF consists of multiple MSTs, one for each connected component | ||
| - The forest contains no cycles and has exactly `N - C` edges, where `N` is the number of nodes and `C` is the number of connected components | ||
|
|
||
| ## Use Cases | ||
|
|
||
| - **Network Design**: Minimize cable/pipeline costs when connecting multiple locations | ||
| - **Clustering**: Identify natural groupings in data by analyzing the forest structure | ||
| - **Image Segmentation**: Group similar pixels using edge weights as similarity measures | ||
| - **Road Networks**: Optimize road construction to connect all cities with minimum cost | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```cypher | ||
| CALL algo.MSF( | ||
| config: MAP | ||
| ) YIELD src, dest, weight, relationshipType | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| | Parameter | Type | Description | | ||
| |-----------|------|-------------| | ||
| | `config` | MAP | Configuration map containing algorithm parameters | | ||
|
|
||
| #### Configuration Options | ||
|
|
||
| | Option | Type | Required | Default | Description | | ||
| |--------|------|----------|---------|-------------| | ||
| | `sourceNodes` | List of Nodes | No | All nodes | Starting nodes for the algorithm. If not provided, all nodes in the graph are considered | | ||
| | `relationshipTypes` | List of Strings | No | All types | Relationship types to traverse. If not provided, all relationship types are considered | | ||
| | `relationshipWeightProperty` | String | No | `null` | Property name containing edge weights. If not specified, all edges have weight 1.0 | | ||
| | `defaultValue` | Float | No | `1.0` | Default weight for edges that don't have the weight property | | ||
|
|
||
| ### Returns | ||
|
|
||
| | Field | Type | Description | | ||
| |-------|------|-------------| | ||
| | `src` | Node | Source node of the edge in the spanning forest | | ||
| | `dest` | Node | Destination node of the edge in the spanning forest | | ||
| | `weight` | Float | Weight of the edge | | ||
| | `relationshipType` | String | Type of the relationship | | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Example 1: Basic MSF with Unweighted Graph | ||
|
|
||
| Find the minimum spanning forest treating all edges equally: | ||
|
|
||
| ```cypher | ||
| CALL algo.MSF({}) YIELD src, dest, weight, relationshipType | ||
| RETURN src.name AS source, dest.name AS destination, weight, relationshipType | ||
| ``` | ||
|
|
||
| ### Example 2: MSF with Weighted Edges | ||
|
|
||
| Consider a graph representing cities connected by roads with distances: | ||
|
|
||
| ```cypher | ||
| // Create a weighted graph | ||
| CREATE (a:City {name: 'A'}), (b:City {name: 'B'}), (c:City {name: 'C'}), | ||
| (d:City {name: 'D'}), (e:City {name: 'E'}) | ||
| CREATE (a)-[:ROAD {distance: 2}]->(b), | ||
| (a)-[:ROAD {distance: 3}]->(c), | ||
| (b)-[:ROAD {distance: 1}]->(c), | ||
| (b)-[:ROAD {distance: 4}]->(d), | ||
| (c)-[:ROAD {distance: 5}]->(d), | ||
| (d)-[:ROAD {distance: 6}]->(e) | ||
|
|
||
| // Find minimum spanning forest using distance weights | ||
| CALL algo.MSF({ | ||
| relationshipWeightProperty: 'distance' | ||
| }) YIELD src, dest, weight | ||
| RETURN src.name AS from, dest.name AS to, weight AS distance | ||
| ORDER BY weight | ||
| ``` | ||
|
|
||
| **Result:** | ||
| ```text | ||
| from | to | distance | ||
| -----|----|--------- | ||
| B | C | 1.0 | ||
| A | B | 2.0 | ||
| A | C | 3.0 | ||
| B | D | 4.0 | ||
| D | E | 6.0 | ||
| ``` | ||
|
|
||
| ### Example 3: MSF on Specific Relationship Types | ||
|
|
||
| Find the spanning forest considering only specific relationship types: | ||
|
|
||
| ```cypher | ||
| CALL algo.MSF({ | ||
| relationshipTypes: ['ROAD', 'HIGHWAY'], | ||
| relationshipWeightProperty: 'distance' | ||
| }) YIELD src, dest, weight, relationshipType | ||
| RETURN src.name AS from, dest.name AS to, weight, relationshipType | ||
| ``` | ||
|
|
||
| ### Example 4: MSF Starting from Specific Nodes | ||
|
|
||
| Compute the spanning forest starting from a subset of nodes: | ||
|
|
||
| ```cypher | ||
| MATCH (start:City) WHERE start.name IN ['A', 'B'] | ||
| WITH collect(start) AS startNodes | ||
| CALL algo.MSF({ | ||
| sourceNodes: startNodes, | ||
| relationshipWeightProperty: 'distance' | ||
| }) YIELD src, dest, weight | ||
| RETURN src.name AS from, dest.name AS to, weight | ||
| ``` | ||
|
|
||
| ### Example 5: Disconnected Graph | ||
|
|
||
| For a graph with multiple components, MSF returns multiple trees: | ||
|
|
||
| ```cypher | ||
| // Create two disconnected components | ||
| CREATE (a:Node {name: 'A'})-[:CONNECTED {weight: 1}]->(b:Node {name: 'B'}), | ||
| (b)-[:CONNECTED {weight: 2}]->(c:Node {name: 'C'}), | ||
| (x:Node {name: 'X'})-[:CONNECTED {weight: 3}]->(y:Node {name: 'Y'}) | ||
|
|
||
| // Find MSF | ||
| CALL algo.MSF({ | ||
| relationshipWeightProperty: 'weight' | ||
| }) YIELD src, dest, weight | ||
| RETURN src.name AS from, dest.name AS to, weight | ||
| ``` | ||
|
|
||
| **Result:** Two separate trees (A-B-C and X-Y) | ||
|
|
||
| ## Algorithm Details | ||
|
|
||
| FalkorDB's MSF implementation uses an efficient matrix-based approach optimized for graph databases: | ||
|
|
||
| 1. **Connected Components**: First identifies all connected components in the graph | ||
| 2. **MST per Component**: Computes a minimum spanning tree for each component using a variant of Kruskal's or Prim's algorithm | ||
| 3. **Edge Selection**: Selects edges in order of increasing weight, avoiding cycles | ||
|
|
||
| ### Performance Characteristics | ||
|
|
||
| - **Time Complexity**: O(E log V) where E is the number of edges and V is the number of vertices | ||
| - **Space Complexity**: O(V + E) | ||
| - **Optimized**: Uses sparse matrix representation for efficient computation | ||
|
|
||
| ## Best Practices | ||
|
|
||
| 1. **Weight Properties**: Ensure weight properties are numeric (integers or floats) | ||
| 2. **Missing Weights**: Use `defaultValue` to handle edges without weight properties | ||
| 3. **Large Graphs**: For large graphs (100K+ nodes), consider filtering by `sourceNodes` or `relationshipTypes` | ||
| 4. **Directed vs Undirected**: The algorithm treats relationships as undirected for spanning forest purposes | ||
|
|
||
| ## Related Algorithms | ||
|
|
||
| - **[WCC (Weakly Connected Components)](./wcc.md)**: Identify connected components before running MSF | ||
| - **[BFS](./bfs.md)**: Traverse the resulting spanning forest | ||
| - **[SPpath](./sppath.md)**: Find shortest paths using the spanning forest structure | ||
|
|
||
| ## See Also | ||
|
|
||
| - [Cypher Procedures](../cypher/procedures.md) | ||
| - [Graph Algorithms Overview](./index.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,10 @@ GRAPH.QUERY social "CALL db.labels() YIELD label" | |
| | db.idx.fulltext.createNodeIndex | `label`, `property` [, `property` ...] | none | Builds a full-text searchable index on a label and the 1 or more specified properties. | | ||
| | db.idx.fulltext.drop | `label` | none | Deletes the full-text index associated with the given label. | | ||
| | db.idx.fulltext.queryNodes | `label`, `string` | `node`, `score` | Retrieve all nodes that contain the specified string in the full-text indexes on the given label. | | ||
| | db.idx.fulltext.queryRelationships | `relationshipType`, `string` | `relationship`, `score` | Retrieve all relationships that contain the specified string in the full-text indexes on the given relationship type. See [Full-Text Indexing](/cypher/indexing#full-text-indexing) for details. | | ||
|
||
| | db.idx.vector.queryNodes | `label`, `attribute`, `k`, `query` | `node`, `score` | Retrieve up to k nodes with vectors most similar to the query vector using the specified label and attribute. See [Vector Indexing](/cypher/indexing#vector-indexing) for details. | | ||
| | db.idx.vector.queryRelationships | `relationshipType`, `attribute`, `k`, `query` | `relationship`, `score` | Retrieve up to k relationships with vectors most similar to the query vector using the specified relationship type and attribute. See [Vector Indexing](/cypher/indexing#vector-indexing) for details. | | ||
| | algo.pageRank | `label`, `relationship-type` | `node`, `score` | Runs the pagerank algorithm over nodes of given label, considering only edges of given relationship type. | | ||
| | [algo.BFS](#BFS) | `source-node`, `max-level`, `relationship-type` | `nodes`, `edges` | Performs BFS to find all nodes connected to the source. A `max level` of 0 indicates unlimited and a non-NULL `relationship-type` defines the relationship type that may be traversed. | | ||
| | algo.BFS | `source-node`, `max-level`, `relationship-type` | `nodes`, `edges` | Performs BFS to find all nodes connected to the source. A `max level` of 0 indicates unlimited and a non-NULL `relationship-type` defines the relationship type that may be traversed. See [BFS Algorithm](/algorithms/bfs) for details. | | ||
| | algo.MSF | `config` | `src`, `dest`, `weight`, `relationshipType` | Computes the Minimum Spanning Forest of the graph. See [MSF Algorithm](/algorithms/msf) for details. | | ||
| | dbms.procedures() | none | `name`, `mode` | List all procedures in the DBMS, yields for every procedure its name and mode (read/write). | | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example result is incorrect. According to Kruskal's/Prim's algorithm for MSF, once nodes A, B, and C are connected (via edges B-C with weight 1.0 and A-B with weight 2.0), the edge A-C with weight 3.0 would create a cycle and should not be included in the MSF. The correct result should only include edges with weights 1.0, 2.0, 4.0, and 6.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shahar-biron