You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2020. It is now read-only.
* Add new search; update some CSS
* Add abstracts to chapters
* Add task to generate complete toc / content map
* Chunk from content map
* Provide section IDs; alight content map
* Fix broken xref
* Add more IDs
* Format source properly; and some content fixes
Copy file name to clipboardExpand all lines: doc/asciidoc/algorithms.adoc
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,13 @@
1
1
[[algorithms]]
2
2
= Algorithms
3
3
4
+
ifdef::env-docs[]
5
+
[abstract]
6
+
--
7
+
This chapter provides explanations and examples for each of the algorithms in the Neo4j Graph Algorithms library.
8
+
--
9
+
endif::env-docs[]
10
+
4
11
Graph algorithms are used to compute metrics for graphs, nodes, or relationships.
5
12
6
13
They can provide insights on relevant entities in the graph (centralities, ranking), or inherent structures like communities (community-detection, graph-partitioning, clustering).
The All Pairs Shortest Path (APSP) calculates the shortest (weighted) path between all pairs of nodes.
5
6
This algorithm has optimisations that make it quicker than calling the Single Source Shortest Path algorithm for every pair of nodes in the graph.
6
-
7
7
// end::introduction[]
8
8
9
+
10
+
[[algorithm-all-pairs-shortest-path-context]]
9
11
== History and explanation
10
12
11
13
// tag::explanation[]
@@ -15,38 +17,34 @@ In this scenario, the algorithm will return `Infinity` value as a result between
15
17
16
18
Plain cypher does not support filtering `Infinity` values, so `algo.isFinite` function was added to help filter `Infinity` values from results.
17
19
20
+
21
+
[[algorithm-all-pairs-shortest-path-usecase]]
18
22
== Use-cases - when to use the All Pairs Shortest Path algorithm
19
23
20
24
// tag::use-case[]
21
25
22
26
* The All Pairs Shortest Path algorithm is used in urban service system problems, such as the location of urban facilities or the distribution or delivery of goods.
23
-
One example of this is determining the traffic load expected on different segments of a transportation grid.
24
-
For more information, see http://web.mit.edu/urban_or_book/www/book/[Urban Operations Research^].
25
-
27
+
One example of this is determining the traffic load expected on different segments of a transportation grid.
28
+
For more information, see http://web.mit.edu/urban_or_book/www/book/[Urban Operations Research^].
26
29
* All pairs shortest path is used as part of the REWIRE data center design algorithm that finds a network with maximum bandwidth and minimal latency.
27
-
There are more details about this approach in https://cs.uwaterloo.ca/research/tr/2011/CS-2011-21.pdf["REWIRE: An Optimization-based Framework for Data Center Network Design"^]
30
+
There are more details about this approach in https://cs.uwaterloo.ca/research/tr/2011/CS-2011-21.pdf["REWIRE: An Optimization-based Framework for Data Center Network Design"^]
28
31
29
32
// end::use-case[]
30
33
31
-
// == Constraints - when not to use the All Pairs Shortest Path algorithm
If our projected graph contains more than 2 billion nodes or relationships, we need to use huge graph projection, as the default label and relationship-type projection has a limitation of 2 billion nodes and 2 billion relationships.
- returns a stream of source-target node to distance tuples for each pair of nodes
133
-
- Since all nodeId's have already been ordered by the idMapping we can use an integer
134
-
instead of a queue which just count's up for each startNodeId as long as it is
135
-
< nodeCount.
134
+
- Returns a stream of source-target node to distance tuples for each pair of nodes
135
+
- Since all nodeId's have already been ordered by the idMapping we can use an integer instead of a queue which just counts up for each startNodeId as long as it is < nodeCount.
136
136
- Each thread tries to take one int from the counter at one time and starts its computation on it.
137
137
- The {@link AllShortestPaths#concurrency} value determines the count of workers that should be spawned.
138
-
- Due to the high memory footprint the result set would have we emit each result into
139
-
a blocking queue. The result stream takes elements from the queue while the workers
140
-
add elements to it.
138
+
- Due to the high memory footprint the result set would have we emit each result into a blocking queue.
139
+
The result stream takes elements from the queue while the workers add elements to it.
141
140
- The result stream is limited by N^2. If the stream gets closed prematurely the workers get closed too.
Copy file name to clipboardExpand all lines: doc/asciidoc/astar.adoc
+34-39Lines changed: 34 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
+
[[algorithms-a_star]]
1
2
= The A* algorithm
2
3
3
4
// tag::introduction[]
4
-
5
5
The A* (pronounced “A-star”) algorithm improves on the classic Dijkstra algorithm.
6
6
It is based upon the observation that some searches are informed, and that by being informed we can make better choices over which paths to take through the graph.
7
-
8
7
// end::introduction[]
9
8
9
+
10
+
[[algorithms-a_star-context]]
10
11
== History and explanation
11
12
12
13
// tag::explanation[]
13
-
14
14
The A* algorithm was first described in 1968 by Peter Hart, Nils Nilsson, and Bertram Raphael.
15
15
For more information, see https://ieeexplore.ieee.org/document/4082128/[A Formal Basis for the Heuristic Determination of Minimum Cost Paths].
16
16
@@ -25,33 +25,28 @@ In A*, we split the path cost into two parts:
25
25
The A* algorithm balances `g(n)` and `h(n)` as it iterates the graph, thereby ensuring that at each iteration it chooses the node with the lowest overall cost `f(n) = g(n) + h(n)`.
26
26
27
27
In our implementation, geospatial distance is used as heurestic.
28
-
29
28
// end::explanation[]
30
29
30
+
31
+
[[algorithms-a_star-usecase]]
31
32
== Use-cases - when to use the A* algorithm
32
33
33
34
// tag::use-case[]
34
-
35
35
* The A* algorithm can be used to find shortest paths between single pairs of locations, where GPS coordinates are known.
36
-
37
36
// end::use-case[]
38
37
39
-
// == Constraints - when not to use the A* algorithm
YIELD nodeId, cost - yields a stream of {nodeId, cost} from start to end (inclusive)
79
76
----
80
77
81
78
.Parameters
82
79
[opts="header",cols="1,1,1,1,4"]
83
80
|===
84
-
| Name | Type | Default | Optional | Description
85
-
| startNode | node | null | no | The start node
86
-
| endNode | node | null | no | The end node
87
-
| weightProperty | string | null | yes | The property name that contains weight
88
-
| propertyKeyLat | string | null | no | The property name that contains latitude coordinate
89
-
| propertyKeyLon | string | null | no | The property name that contains longitude coordinate
90
-
| nodeQuery | string | null | yes | The label to load from the graph. If null, load all nodes
91
-
| relationshipQuery | string | null | yes | The relationship-type to load from the graph. If null, load all nodes
92
-
| defaultValue | float | null | yes | The default value of the weight in case it is missing or invalid
93
-
| direction | string | outgoing | yes | The relationship direction to load from the graph. If 'both', treats the relationships as undirected
81
+
| Name | Type | Default | Optional | Description
82
+
| startNode | node | null | no | The start node
83
+
| endNode | node | null | no | The end node
84
+
| weightProperty | string | null | yes | The property name that contains weight
85
+
| propertyKeyLat | string | null | no | The property name that contains latitude coordinate
86
+
| propertyKeyLon | string | null | no | The property name that contains longitude coordinate
87
+
| nodeQuery | string | null | yes | The label to load from the graph. If null, load all nodes
88
+
| relationshipQuery | string | null | yes | The relationship-type to load from the graph. If null, load all nodes
89
+
| defaultValue | float | null | yes | The default value of the weight in case it is missing or invalid
90
+
| direction | string | outgoing | yes | The relationship direction to load from the graph. If 'both', treats the relationships as undirected
94
91
|===
95
92
96
93
.Results
97
94
[opts="header"]
98
95
|===
99
-
| Name | Type | Description
100
-
| nodeId | int | Node ID
101
-
| cost | int | The cost it takes to get from start node to specific node
96
+
| Name | Type | Description
97
+
| nodeId | int | Node ID
98
+
| cost | int | The cost it takes to get from start node to specific node
102
99
|===
103
100
101
+
104
102
== Cypher projection
105
103
106
104
If label and relationship-type are not selective enough to describe your subgraph to run the algorithm on, you can use Cypher statements to load or project subsets of your graph.
@@ -113,26 +111,21 @@ This can also be used to run algorithms on a virtual graph.
113
111
include::scripts/astar.cypher[tag=cypher-loading]
114
112
----
115
113
114
+
116
115
== Versions
117
116
118
117
We support the following versions of the shortest path algorithms:
119
118
120
119
* [x] directed, unweighted:
121
-
122
120
** direction: 'OUTGOING' or INCOMING, weightProperty: null
123
-
124
121
* [x] directed, weighted
125
-
126
122
** direction: 'OUTGOING' or INCOMING, weightProperty: 'cost'
127
-
128
123
* [x] undirected, unweighted
129
-
130
124
** direction: 'BOTH', weightProperty: null
131
-
132
125
* [x] undirected, weighted
133
-
134
126
** direction: 'BOTH', weightProperty: 'cost'
135
127
128
+
136
129
== Implementations
137
130
138
131
`algo.shortestPath.astar.stream()`
@@ -150,6 +143,7 @@ We support the following versions of the shortest path algorithms:
150
143
ifdef::implementation[]
151
144
// tag::implementation[]
152
145
146
+
153
147
== Implementation details
154
148
155
149
:leveloffset: +1
@@ -169,6 +163,7 @@ ifdef::implementation[]
169
163
170
164
== Details
171
165
166
+
172
167
=== algo.shortestPath.astar.stream()
173
168
174
169
- implementation of A* heuristic function is for geospatial distances.
0 commit comments