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
Copy file name to clipboardexpand all lines: All-Pairs Shortest Paths/APSP/APSP/APSP.swift
+5-2
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,9 @@ import Foundation
9
9
import Graph
10
10
11
11
/**
12
-
`APSPAlgorithm` is a protocol for encapsulating an All-Pairs Shortest Paths algorithm. It provides a single function `apply` that accepts a subclass of `AbstractGraph` and returns an object conforming to `APSPResult`.
12
+
`APSPAlgorithm` is a protocol for encapsulating an All-Pairs Shortest Paths algorithm.
13
+
It provides a single function `apply` that accepts a subclass of `AbstractGraph` and
14
+
returns an object conforming to `APSPResult`.
13
15
*/
14
16
publicprotocolAPSPAlgorithm{
15
17
@@ -21,7 +23,8 @@ public protocol APSPAlgorithm {
21
23
}
22
24
23
25
/**
24
-
`APSPResult` is a protocol defining functions `distance` and `path`, allowing for opaque queries into the actual data structures that represent the APSP solution according to the algorithm used.
26
+
`APSPResult` is a protocol defining functions `distance` and `path`, allowing for opaque
27
+
queries into the actual data structures that represent the APSP solution according to the algorithm used.
Copy file name to clipboardexpand all lines: All-Pairs Shortest Paths/APSP/APSP/FloydWarshall.swift
+26-15
Original file line number
Diff line number
Diff line change
@@ -51,12 +51,16 @@ public struct FloydWarshall<T where T: Hashable>: APSPAlgorithm {
51
51
}
52
52
53
53
/**
54
-
For each iteration of `intermediateIdx`, perform the comparison for the dynamic algorith, checking for each pair of start/end vertices, whether a path taken through another vertex produces a shorter path.
54
+
For each iteration of `intermediateIdx`, perform the comparison for the dynamic algorith,
55
+
checking for each pair of start/end vertices, whether a path taken through another vertex
56
+
produces a shorter path.
55
57
56
58
- complexity: `Θ(V^2)` time/space
57
-
- returns: a tuple containing the next distance matrix with weights of currently known shortest paths and the corresponding predecessor matrix
59
+
- returns: a tuple containing the next distance matrix with weights of currently known
60
+
shortest paths and the corresponding predecessor matrix
@@ -85,9 +89,11 @@ public struct FloydWarshall<T where T: Hashable>: APSPAlgorithm {
85
89
86
90
}
87
91
88
-
/**
89
-
We need to map the graph's weight domain onto the one required by the algorithm: the graph stores either a weight as a `Double` or `nil` if no edge exists between two vertices, but the algorithm needs a lack of an edge represented as ∞ for the `min` comparison to work correctly.
90
-
92
+
/**
93
+
We need to map the graph's weight domain onto the one required by the algorithm: the graph
94
+
stores either a weight as a `Double` or `nil` if no edge exists between two vertices, but
95
+
the algorithm needs a lack of an edge represented as ∞ for the `min` comparison to work correctly.
96
+
91
97
- complexity: `Θ(V^2)` time/space
92
98
- returns: weighted adjacency matrix in form ready for processing with Floyd-Warshall
93
99
*/
@@ -116,7 +122,7 @@ public struct FloydWarshall<T where T: Hashable>: APSPAlgorithm {
116
122
117
123
/**
118
124
Make the initial predecessor index matrix. Initially each value is equal to it's row index, it's "from" index when querying into it.
@@ -139,17 +145,20 @@ public struct FloydWarshall<T where T: Hashable>: APSPAlgorithm {
139
145
}
140
146
141
147
/**
142
-
`FloydWarshallResult` encapsulates the result of the computation, namely the minimized distance adjacency matrix, and the matrix of predecessor indices.
143
-
144
-
It conforms to the `APSPResult` procotol which provides methods to retrieve distances and paths between given pairs of start and end nodes.
148
+
`FloydWarshallResult` encapsulates the result of the computation, namely the
149
+
minimized distance adjacency matrix, and the matrix of predecessor indices.
150
+
151
+
It conforms to the `APSPResult` procotol which provides methods to retrieve
152
+
distances and paths between given pairs of start and end nodes.
145
153
*/
146
154
publicstructFloydWarshallResult<T where T:Hashable>:APSPResult{
147
155
148
156
privatevarweights:Distances
149
157
privatevarpredecessors:Predecessors
150
158
151
159
/**
152
-
- returns: the total weight of the path from a starting vertex to a destination. This value is the minimal connected weight between the two vertices, or `nil` if no path exists
160
+
- returns: the total weight of the path from a starting vertex to a destination.
161
+
This value is the minimal connected weight between the two vertices, or `nil` if no path exists
@@ -159,7 +168,8 @@ public struct FloydWarshallResult<T where T: Hashable>: APSPResult {
159
168
}
160
169
161
170
/**
162
-
- returns: the reconstructed path from a starting vertex to a destination, as an array containing the data property of each vertex, or `nil` if no path exists
171
+
- returns: the reconstructed path from a starting vertex to a destination,
172
+
as an array containing the data property of each vertex, or `nil` if no path exists
0 commit comments