Skip to content

Commit 765fe7f

Browse files
committed
One sentence per line
and other doc formatting
1 parent 9a5b755 commit 765fe7f

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

doc/modules/ROOT/pages/algorithms/dag/dag-algorithms.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
Directed Acyclic Graphs (DAGs) are directed graphs that do not contain cycles.
77
These kind of graphs are commonly used to model dependencies between entities.
88

9-
The canonical algorithm that goes hand in hand with DAGs is topological sort, for which GDS provides an efficient parallel implementation. Running topological sort is the best way to make sure the graph is a DAG.
9+
The canonical algorithm that goes hand in hand with DAGs is topological sort, for which GDS provides an efficient parallel implementation.
10+
Running topological sort is the best way to make sure the graph is a DAG.
1011

11-
Some of the problems that are computationally hard to solve in the general case can be solved efficiently when the scope is limited to DAGs. One of these is the longest path problem, for which GDS provides an efficient algorithm.
12+
Some of the problems that are computationally hard to solve in the general case can be solved efficiently when the scope is limited to DAGs.
13+
One of these is the longest path problem, for which GDS provides an efficient algorithm.
1214

1315
The Neo4j GDS library includes the following DAG algorithms:
1416

doc/modules/ROOT/pages/algorithms/dag/longest-path.adoc

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ include::partial$/operations-reference/alpha-note.adoc[]
1818

1919
Finding the longest path that leads to a node in a graph is possible to do in linear time for the special case of DAGs.
2020

21-
GDS implementation for this algorithm is based on topological sort and takes linear time. If the graph is not a DAG, the runtime is still linear, but the results cannot be trusted. You can use xref:algorithms/dag/topological-sort.adoc[topological sort] to make sure the graph is a DAG.
21+
GDS implementation for this algorithm is based on topological sort and takes linear time.
22+
If the graph is not a DAG, the runtime is still linear, but the results cannot be trusted.
23+
You can use xref:algorithms/dag/topological-sort.adoc[topological sort] to make sure the graph is a DAG.
2224

23-
The algorithm supports weighted and unweighted graphs. Negative weights are currently unsupported.
25+
The algorithm supports weighted and unweighted graphs.
26+
Negative weights are currently unsupported.
2427

2528

2629
=== Usage
2730

28-
One example for usage of this algorithm is in the context of a supply chain graph. If edges indicate the time to supply, then the distance of the longest path to a target node is the time required to manufacture the node from decision to completion.
31+
One example for usage of this algorithm is in the context of a supply chain graph.
32+
If edges indicate the time to supply, then the distance of the longest path to a target node is the time required to manufacture the node from decision to completion.
2933

3034

3135
== Syntax
@@ -76,7 +80,6 @@ include::partial$/algorithms/common-configuration/common-stream-stats-configurat
7680
| nodeIds | List of Integer | Node ids on the path in traversal order.
7781
| costs | List of Float | Accumulated costs for each node on the path.
7882
| path | Path | The path represented as Cypher entity.
79-
8083
|===
8184

8285
// include-with-stream
@@ -110,9 +113,13 @@ CREATE
110113
----
111114

112115
This graph describes a simple supply chain of constructing a table in the Table Maker workshop.
113-
In order to have lumber for the table, the workshop processes timber, which takes 1 day to complete. Once the lumber is ready, it is already in the workshop, therefor it takes zero time to ship it. However, the screws take 3 days to be shipped to the workshop. Only after the workshop has all the requirements met, the table can be constructed, a process that takes 1 day.
116+
In order to have lumber for the table, the workshop processes timber, which takes 1 day to complete.
117+
Once the lumber is ready, it is already in the workshop, therefor it takes zero time to ship it.
118+
However, the screws take 3 days to be shipped to the workshop.
119+
Only after the workshop has all the requirements met, the table can be constructed, a process that takes 1 day.
114120

115-
The longest path to the table node starts with the screws, then the workshop and then the table, in total: 4 days. This is the bottleneck path, and total time that takes to manufacture the table.
121+
The longest path to the table node starts with the screws, then the workshop and then the table, in total: 4 days.
122+
This is the bottleneck path, and total time that takes to manufacture the table.
116123

117124
.The following Cypher statement will project the graph to GDS:
118125
[source, cypher, role=noplay setup-query]
@@ -147,16 +154,17 @@ RETURN
147154
nodes(path) as path
148155
ORDER BY index
149156
----
157+
150158
We use the utility function `asNode` to return the name of node instead of its ID to make results more readable.
151159

152160
.Results
153161
[opts="header"]
154162
|===
155-
| index | sourceNode | targetNode | totalCost | nodeNames | costs | path
156-
| 0 | "Timber" | "Timber" | 0.0 | [Timber] | [0.0] | [Node[0]]
157-
| 1 | "Timber" | "Lumber" | 1.0 | [Timber, Lumber] | [0.0, 1.0] | [Node[0], Node[1]]
158-
| 2 | "Screws" | "Table Maker" | 3.0 | [Screws, Table Maker] | [0.0, 3.0] | [Node[2], Node[3]]
159-
| 3 | "Screws" | "Screws" | 0.0 | [Screws] | [0.0] | [Node[2]]
163+
| index | sourceNode | targetNode | totalCost | nodeNames | costs | path
164+
| 0 | "Timber" | "Timber" | 0.0 | [Timber] | [0.0] | [Node[0]]
165+
| 1 | "Timber" | "Lumber" | 1.0 | [Timber, Lumber] | [0.0, 1.0] | [Node[0], Node[1]]
166+
| 2 | "Screws" | "Table Maker" | 3.0 | [Screws, Table Maker] | [0.0, 3.0] | [Node[2], Node[3]]
167+
| 3 | "Screws" | "Screws" | 0.0 | [Screws] | [0.0] | [Node[2]]
160168
| 4 | "Screws" | "Table" | 4.0 | [Screws, Table Maker, Table] | [0.0, 3.0, 4.0] | [Node[2], Node[3], Node[4]]
161169
|===
162170
--

doc/modules/ROOT/pages/algorithms/dag/topological-sort.adoc

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ include::partial$/operations-reference/alpha-note.adoc[]
1717
A topological sorting of nodes in a graph is an ordering of the nodes in the graph where every node appears only after all the nodes pointing to it have appeared.
1818
For example, for a graph with 4 nodes and these relations: `a->b`, `a->c`, `b->d`, `c->d`, there are two acceptable topological sorts: `a, b, c, d` and `a, c, b, d`.
1919

20-
The topological order of the nodes is defined only for directed acyclic graphs (DAGs). See xref:#topological-sort-cycles[below] for the expected result for graphs with cycles.
20+
The topological order of the nodes is defined only for directed acyclic graphs (DAGs).
21+
See xref:#topological-sort-cycles[below] for the expected result for graphs with cycles.
2122

2223
GDS provides an efficient parallel implementation for this algorithm.
2324

2425

2526
[[topological-sort-cycles]]
2627
=== Cycles
2728

28-
Running the algorithm on a graph with cycles will cause the omitting of part of the nodes from the sorting. The omitted nodes are:
29+
Running the algorithm on a graph with cycles will cause the omitting of part of the nodes from the sorting.
30+
The omitted nodes are:
2931

3032
1. Nodes that are part of a cycle (including self cycles)
3133

@@ -43,11 +45,17 @@ image::example-graphs/{image-file}[Visualization of the example graph,align="cen
4345

4446
=== Usage
4547

46-
Topological ordering of the nodes is beneficial when you want to guarantee a node will only be processed after its dependencies were processed. This is very useful for dependency related tasks such as scheduling or calculations that derive values from their dependencies.
48+
Topological ordering of the nodes is beneficial when you want to guarantee a node will only be processed after its dependencies were processed.
49+
This is very useful for dependency related tasks such as scheduling or calculations that derive values from their dependencies.
50+
4751

4852
==== Cycles detection
4953

50-
The algorithm can also be used to determine if the graph contains a cycle or not. If all the nodes in the graph appear in the sorting, there is no cycle in the graph. If some of the nodes are missing from the sorting, there is a cycle. It does not tell which nodes constitute the cycle, but it does give a clue, as described in the xref:#topological-sort-cycles[cycles] section.
54+
The algorithm can also be used to determine if the graph contains a cycle or not.
55+
If all the nodes in the graph appear in the sorting, there is no cycle in the graph.
56+
If some of the nodes are missing from the sorting, there is a cycle.
57+
It does not tell which nodes constitute the cycle, but it does give a clue, as described in the xref:#topological-sort-cycles[cycles] section.
58+
5159

5260
==== Maximum distance from source
5361

@@ -106,6 +114,7 @@ include::partial$/algorithms/topological-sort/specific-configuration.adoc[]
106114
// tabbed-example
107115
====
108116

117+
109118
== Examples
110119

111120
:algorithm-name: Topological Sort
@@ -133,7 +142,8 @@ CREATE
133142
(n5)-[:REQUIRED]->(n6)
134143
----
135144

136-
This graph describes a simplified supply chain of building a house. Each part of the house cannot be worked on before its requirements are met.
145+
This graph describes a simplified supply chain of building a house.
146+
Each part of the house cannot be worked on before its requirements are met.
137147
For example, we cannot build support before getting the steel, the skeleton is not ready until both support and base are ready.
138148

139149
.The following Cypher statement will project the graph to GDS:
@@ -145,8 +155,11 @@ WITH gds.graph.project("g", n, target, {}) AS g
145155
RETURN g
146156
----
147157

158+
148159
=== Stream
149-
The stream procedure streams the nodes in the graph ordered by a valid topological order. The nodes can then be processed one by one, guaranteeing that each node is processed only after its dependencies were processed.
160+
161+
The stream procedure streams the nodes in the graph ordered by a valid topological order.
162+
The nodes can then be processed one by one, guaranteeing that each node is processed only after its dependencies were processed.
150163

151164
For more details on the stream mode in general, see xref:common-usage/running-algos.adoc#running-algos-stream[Stream].
152165

@@ -160,6 +173,7 @@ YIELD nodeId, maxDistanceFromSource
160173
RETURN gds.util.asNode(nodeId).name AS name, maxDistanceFromSource
161174
ORDER BY maxDistanceFromSource, name
162175
----
176+
163177
We use the utility function `asNode` to return the name of node instead of its ID to make results more readable.
164178

165179
.Results

0 commit comments

Comments
 (0)