Index
MCFSolverInterface
Bases: Protocol
Interface for an MCF solver implementation.
A solver can be initialized with a planar graph and can be repeatedly invoked with different input. See the documentation of PlanarGraphInterface for restrictions on supported graphs.
Attributes:
| Name | Type | Description |
|---|---|---|
npoints |
int
|
Number of points in primal graph. |
nedges |
int
|
Number of edges in primal graph. |
ncycles |
int
|
Number of cycles in primal graph. |
cycle_length |
int
|
Length of cycles in primal graph. |
points |
ArrayLike
|
2D array of size (npoints, 2) with coordinates. |
edges |
ArrayLike
|
2D array of size (nedges, 2) where values indicate index into points array. Edges always go from lower index to higher index. |
cycles |
ArrayLike
|
2D array of size (ncycles, cycle_length) where values indicate index points array. All cycles are oriented in one direction. |
dual_edges |
ArrayLike
|
2D array of size (nedges, 2) where values indicate 1-index into cycles array. zero indicates a boundary edge in primal graph. |
dual_edge_dir |
ArrayLike
|
2D array of size (nedges, 2) where values orientation of edge into 1-indexed cycles array. zero indicates a boundary edge in primal graph. |
Source code in src/spurt/mcf/_interface.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
cycle_length
property
Length of cycles in primal graph.
cycles
property
Cycles in primal graph.
dual_edge_dir
property
Array containing orientation of edge in cycle.
This is of size (nedges, 2).
dual_edges
property
Returns dual edges of the graph.
This is of size (nedges, 2)
edges
property
Edges in primal graph.
ncycles
property
Number of cycles in primal graph.
nedges
property
Number of links in primal graph.
npoints
property
Number of points in primal graph.
points
property
Points in primal graph.
__init__(graph)
Initialize solver with the graph.
Source code in src/spurt/mcf/_interface.py
53 54 | |
compute_residues(wrapdata)
Solver should return residues corresponding to input wrapped data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wrapdata
|
ArrayLike
|
1D array as input in radians or complex numbers. Same size as number of points in the graph. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
residues |
ArrayLike
|
1D array of integer residues corresponding to the cycles in the graph. Includes the grounding node. |
Source code in src/spurt/mcf/_interface.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
compute_residues_from_gradients(graddata)
Solver should return residues corresponding to edge gradients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graddata
|
ArrayLike
|
1D array as input in radians. Same size as number of edges in the primal graph. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
residues |
ArrayLike
|
1D array of integer residues corresponding to the cycles in the graph. Includes the grounding node. |
Source code in src/spurt/mcf/_interface.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
residues_to_flows(residues, cost, revcost=None)
Solver should return integer flows corresponding to given residues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
residues
|
ArrayLike
|
1D array of integer residues. Same size as number of cycles in graph plus one to accommodate the grounding node. Array must sum to zero. |
required |
cost
|
ArrayLike
|
1D array of nonnegative integer costs. Same size as number of edges in the graph. Represents forward directional cost when used in combination with revcost. |
required |
revcost
|
ArrayLike | None
|
1D array of nonnegative integer costs on links in reverse direction. Same size as number of edges in the graph. cost is used if not provided. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
flows |
ArrayLike
|
1D array of integer flows along each of the edges in the graph. |
Source code in src/spurt/mcf/_interface.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
residues_to_flows_many(residues, cost, revcost=None, worker_count=None, chunksize=1)
Solver should return integer flows corresponding to given residues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
residues
|
ArrayLike
|
2D array of integer residues of size (nruns, ncycles + 1). Each row of the array must sum to zero. |
required |
cost
|
ArrayLike
|
1D array of nonnegative integer costs. Same size as number of edges in the graph. Represents forward directional cost when used in combination with revcost. |
required |
revcost
|
ArrayLike | None
|
1D array of nonnegative integer costs on links in reverse direction. Same size as number of edges in the graph. cost is used if not provided. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
flows |
ArrayLike
|
2D array of integer flows of along each of the edges in the graph. Returned array is of size (nruns, nedges). |
Source code in src/spurt/mcf/_interface.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
unwrap_one(wrapdata, cost, revcost=None)
Solver should return unwrapped phase and flows on the edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wrapdata
|
ArrayLike
|
1D array as input in radians or as complex numbers. Same size as number of points in the graph. |
required |
cost
|
ArrayLike
|
1D array of nonnegative integer costs. Same size as number of edges in the graph. Represents forward directional cost when used in combination with revcost. |
required |
revcost
|
ArrayLike | None
|
1D array of nonnegative integer costs on links in reverse direction. Same size as number of edges in the graph. cost is used if not provided. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
unwdata |
ArrayLike
|
1D array of unwrapped phase in radians. Same size as number of points in the graph. |
flows |
ArrayLike
|
1D array of integer flows along each of the edges in the graph. |
Source code in src/spurt/mcf/_interface.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
ORMCFSolver
Bases: MCFSolverInterface
Minimum cost flow solver interface.
Implementation of MCF solver using OR tools python bindings.
Source code in src/spurt/mcf/_ortools.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
__init__(graph)
Initialize solver using a planar graph.
Initializes with information related to the dual graph as well to allow us to efficiently reuse the solver with multiple inputs
Source code in src/spurt/mcf/_ortools.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
compute_residues(wrapdata)
Compute phase residues for one set of input wrapped data.
Source code in src/spurt/mcf/_ortools.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
residues_to_flows(residues, cost, revcost=None)
Return flows on the edges corresponding to given set of residues.
This is exposed to allow for unwrapping with gradients.
Source code in src/spurt/mcf/_ortools.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
residues_to_flows_many(residues, cost, revcost=None, worker_count=None, chunksize=1)
Parallel version of residues_to_flows.
The worker_count is set to get_cpu_count() - 1 if not provided. Treating costs as 1D arrays for now. Can consider 2D at a later time, if necessary.
Source code in src/spurt/mcf/_ortools.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
unwrap_one(wrapdata, cost, revcost=None)
Get the unwrapped phase solution for one set of input wrapped data.
Source code in src/spurt/mcf/_ortools.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |