edsger 0.1.1__cp311-cp311-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- edsger/.gitignore +1 -0
- edsger/__init__.py +1 -0
- edsger/_version.py +1 -0
- edsger/commons.c +8391 -0
- edsger/commons.cpython-311-darwin.so +0 -0
- edsger/commons.pxd +25 -0
- edsger/commons.pyx +34 -0
- edsger/dijkstra.c +35848 -0
- edsger/dijkstra.cpython-311-darwin.so +0 -0
- edsger/dijkstra.pyx +504 -0
- edsger/networks.py +414 -0
- edsger/path.py +786 -0
- edsger/path_tracking.c +30241 -0
- edsger/path_tracking.cpython-311-darwin.so +0 -0
- edsger/path_tracking.pyx +93 -0
- edsger/pq_4ary_dec_0b.c +35869 -0
- edsger/pq_4ary_dec_0b.cpython-311-darwin.so +0 -0
- edsger/pq_4ary_dec_0b.pxd +33 -0
- edsger/pq_4ary_dec_0b.pyx +692 -0
- edsger/spiess_florian.c +34520 -0
- edsger/spiess_florian.cpython-311-darwin.so +0 -0
- edsger/spiess_florian.pyx +368 -0
- edsger/star.c +33896 -0
- edsger/star.cpython-311-darwin.so +0 -0
- edsger/star.pyx +356 -0
- edsger/utils.py +63 -0
- edsger-0.1.1.dist-info/METADATA +111 -0
- edsger-0.1.1.dist-info/RECORD +32 -0
- edsger-0.1.1.dist-info/WHEEL +5 -0
- edsger-0.1.1.dist-info/licenses/AUTHORS.rst +5 -0
- edsger-0.1.1.dist-info/licenses/LICENSE +21 -0
- edsger-0.1.1.dist-info/top_level.txt +1 -0
Binary file
|
edsger/star.pyx
ADDED
@@ -0,0 +1,356 @@
|
|
1
|
+
"""
|
2
|
+
Forward and reverse star representations of networks.
|
3
|
+
|
4
|
+
|
5
|
+
cpdef functions:
|
6
|
+
|
7
|
+
- convert_graph_to_csr_uint32
|
8
|
+
Convert an edge dataframe in COO format into CSR format, with uint32
|
9
|
+
data.
|
10
|
+
- convert_graph_to_csc_uint32
|
11
|
+
Convert an edge dataframe in COO format into CSC format, with uint32
|
12
|
+
data.
|
13
|
+
- convert_graph_to_csr_float64
|
14
|
+
Convert an edge dataframe in COO format into CSR format, with float64
|
15
|
+
data.
|
16
|
+
- convert_graph_to_csc_float64
|
17
|
+
Convert an edge dataframe in COO format into CSC format, with float64
|
18
|
+
data.
|
19
|
+
|
20
|
+
|
21
|
+
cdef functions:
|
22
|
+
|
23
|
+
- _coo_to_csr_uint32
|
24
|
+
- _coo_to_csc_uint32
|
25
|
+
- _coo_to_csr_float64
|
26
|
+
- _coo_to_csc_float64
|
27
|
+
"""
|
28
|
+
|
29
|
+
import numpy as np
|
30
|
+
cimport numpy as cnp
|
31
|
+
|
32
|
+
|
33
|
+
cpdef convert_graph_to_csr_uint32(edges, tail, head, data, vertex_count):
|
34
|
+
"""
|
35
|
+
Convert an edge dataframe in COO format into CSR format, with uint32
|
36
|
+
data.
|
37
|
+
|
38
|
+
Parameters
|
39
|
+
----------
|
40
|
+
edges : pandas.core.frame.DataFrame
|
41
|
+
The edges dataframe.
|
42
|
+
tail : str
|
43
|
+
The column name in the edges dataframe for the tail vertex index.
|
44
|
+
head : str
|
45
|
+
The column name in the edges dataframe for the head vertex index.
|
46
|
+
data : str
|
47
|
+
The column name in the edges dataframe for the int edge attribute.
|
48
|
+
vertex_count : int
|
49
|
+
The vertex count in the given network edges.
|
50
|
+
|
51
|
+
Returns
|
52
|
+
-------
|
53
|
+
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
|
54
|
+
"""
|
55
|
+
|
56
|
+
fs_indptr = np.zeros(
|
57
|
+
vertex_count + 1, dtype=np.uint32
|
58
|
+
) # make sure it is filled with zeros
|
59
|
+
edge_count = len(edges)
|
60
|
+
fs_indices = np.empty(edge_count, dtype=np.uint32)
|
61
|
+
fs_data = np.empty(edge_count, dtype=np.uint32)
|
62
|
+
|
63
|
+
_coo_to_csr_uint32(
|
64
|
+
edges[tail].values.astype(np.uint32),
|
65
|
+
edges[head].values.astype(np.uint32),
|
66
|
+
edges[data].values.astype(np.uint32),
|
67
|
+
fs_indptr,
|
68
|
+
fs_indices,
|
69
|
+
fs_data,
|
70
|
+
)
|
71
|
+
|
72
|
+
return fs_indptr, fs_indices, fs_data
|
73
|
+
|
74
|
+
|
75
|
+
cpdef convert_graph_to_csc_uint32(edges, tail, head, data, vertex_count):
|
76
|
+
"""
|
77
|
+
Convert an edge dataframe in COO format into CSC format, with uint32
|
78
|
+
data.
|
79
|
+
|
80
|
+
Parameters
|
81
|
+
----------
|
82
|
+
edges : pandas.core.frame.DataFrame
|
83
|
+
The edges dataframe.
|
84
|
+
tail : str
|
85
|
+
The column name in the edges dataframe for the tail vertex index.
|
86
|
+
head : str
|
87
|
+
The column name in the edges dataframe for the head vertex index.
|
88
|
+
data : str
|
89
|
+
The column name in the edges dataframe for the int edge attribute.
|
90
|
+
vertex_count : int
|
91
|
+
The vertex count in the given network edges.
|
92
|
+
|
93
|
+
Returns
|
94
|
+
-------
|
95
|
+
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
|
96
|
+
"""
|
97
|
+
|
98
|
+
rs_indptr = np.zeros(
|
99
|
+
vertex_count + 1, dtype=np.uint32
|
100
|
+
) # make sure it is filled with zeros
|
101
|
+
edge_count = len(edges)
|
102
|
+
rs_indices = np.empty(edge_count, dtype=np.uint32)
|
103
|
+
rs_data = np.empty(edge_count, dtype=np.uint32)
|
104
|
+
|
105
|
+
_coo_to_csc_uint32(
|
106
|
+
edges[tail].values.astype(np.uint32),
|
107
|
+
edges[head].values.astype(np.uint32),
|
108
|
+
edges[data].values.astype(np.uint32),
|
109
|
+
rs_indptr,
|
110
|
+
rs_indices,
|
111
|
+
rs_data,
|
112
|
+
)
|
113
|
+
|
114
|
+
return rs_indptr, rs_indices, rs_data
|
115
|
+
|
116
|
+
|
117
|
+
cpdef convert_graph_to_csr_float64(edges, tail, head, data, vertex_count):
|
118
|
+
"""
|
119
|
+
Convert an edge dataframe in COO format into CSR format, with float64
|
120
|
+
data.
|
121
|
+
|
122
|
+
Parameters
|
123
|
+
----------
|
124
|
+
edges : pandas.core.frame.DataFrame
|
125
|
+
The edges dataframe.
|
126
|
+
tail : str
|
127
|
+
The column name in the edges dataframe for the tail vertex index.
|
128
|
+
head : str
|
129
|
+
The column name in the edges dataframe for the head vertex index.
|
130
|
+
data : str
|
131
|
+
The column name in the edges dataframe for the real edge attribute.
|
132
|
+
vertex_count : int
|
133
|
+
The vertex count in the given network edges.
|
134
|
+
|
135
|
+
Returns
|
136
|
+
-------
|
137
|
+
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
|
138
|
+
"""
|
139
|
+
|
140
|
+
fs_indptr = np.zeros(
|
141
|
+
vertex_count + 1, dtype=np.uint32
|
142
|
+
) # make sure it is filled with zeros
|
143
|
+
edge_count = len(edges)
|
144
|
+
fs_indices = np.empty(edge_count, dtype=np.uint32)
|
145
|
+
fs_data = np.empty(edge_count, dtype=np.float64)
|
146
|
+
|
147
|
+
_coo_to_csr_float64(
|
148
|
+
edges[tail].values.astype(np.uint32),
|
149
|
+
edges[head].values.astype(np.uint32),
|
150
|
+
edges[data].values.astype(np.float64),
|
151
|
+
fs_indptr,
|
152
|
+
fs_indices,
|
153
|
+
fs_data,
|
154
|
+
)
|
155
|
+
|
156
|
+
return fs_indptr, fs_indices, fs_data
|
157
|
+
|
158
|
+
|
159
|
+
cpdef convert_graph_to_csc_float64(edges, tail, head, data, vertex_count):
|
160
|
+
"""
|
161
|
+
Convert an edge dataframe in COO format into CSC format, with float64
|
162
|
+
data.
|
163
|
+
|
164
|
+
Parameters
|
165
|
+
----------
|
166
|
+
edges : pandas.core.frame.DataFrame
|
167
|
+
The edges dataframe.
|
168
|
+
tail : str
|
169
|
+
The column name in the edges dataframe for the tail vertex index.
|
170
|
+
head : str
|
171
|
+
The column name in the edges dataframe for the head vertex index.
|
172
|
+
data : str
|
173
|
+
The column name in the edges dataframe for the real edge attribute.
|
174
|
+
vertex_count : int
|
175
|
+
The vertex count in the given network edges.
|
176
|
+
|
177
|
+
Returns
|
178
|
+
-------
|
179
|
+
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
|
180
|
+
"""
|
181
|
+
|
182
|
+
rs_indptr = np.zeros(
|
183
|
+
vertex_count + 1, dtype=np.uint32
|
184
|
+
) # make sure it is filled with zeros
|
185
|
+
edge_count = len(edges)
|
186
|
+
rs_indices = np.empty(edge_count, dtype=np.uint32)
|
187
|
+
rs_data = np.empty(edge_count, dtype=np.float64)
|
188
|
+
|
189
|
+
_coo_to_csc_float64(
|
190
|
+
edges[tail].values.astype(np.uint32),
|
191
|
+
edges[head].values.astype(np.uint32),
|
192
|
+
edges[data].values.astype(np.float64),
|
193
|
+
rs_indptr,
|
194
|
+
rs_indices,
|
195
|
+
rs_data,
|
196
|
+
)
|
197
|
+
|
198
|
+
return rs_indptr, rs_indices, rs_data
|
199
|
+
|
200
|
+
|
201
|
+
cdef void _coo_to_csr_uint32(
|
202
|
+
cnp.uint32_t [::1] Ai,
|
203
|
+
cnp.uint32_t [::1] Aj,
|
204
|
+
cnp.uint32_t [::1] Ax,
|
205
|
+
cnp.uint32_t [::1] Bp,
|
206
|
+
cnp.uint32_t [::1] Bj,
|
207
|
+
cnp.uint32_t [::1] Bx) nogil noexcept:
|
208
|
+
|
209
|
+
cdef:
|
210
|
+
size_t i, row, dest
|
211
|
+
size_t n_vert = <size_t>(Bp.shape[0] - 1)
|
212
|
+
size_t n_edge = <size_t>Bj.shape[0]
|
213
|
+
cnp.uint32_t temp, cumsum, last
|
214
|
+
|
215
|
+
for i in range(n_edge):
|
216
|
+
Bp[<size_t>Ai[i]] += 1
|
217
|
+
|
218
|
+
cumsum = 0
|
219
|
+
for i in range(n_vert):
|
220
|
+
temp = Bp[i]
|
221
|
+
Bp[i] = cumsum
|
222
|
+
cumsum += temp
|
223
|
+
Bp[n_vert] = <cnp.uint32_t>n_edge
|
224
|
+
|
225
|
+
for i in range(n_edge):
|
226
|
+
row = <size_t>Ai[i]
|
227
|
+
dest = <size_t>Bp[row]
|
228
|
+
Bj[dest] = Aj[i]
|
229
|
+
Bx[dest] = Ax[i]
|
230
|
+
Bp[row] += 1
|
231
|
+
|
232
|
+
last = 0
|
233
|
+
for i in range(n_vert + 1):
|
234
|
+
temp = Bp[i]
|
235
|
+
Bp[i] = last
|
236
|
+
last = temp
|
237
|
+
|
238
|
+
|
239
|
+
cdef void _coo_to_csc_uint32(
|
240
|
+
cnp.uint32_t [::1] Ai,
|
241
|
+
cnp.uint32_t [::1] Aj,
|
242
|
+
cnp.uint32_t [::1] Ax,
|
243
|
+
cnp.uint32_t [::1] Bp,
|
244
|
+
cnp.uint32_t [::1] Bi,
|
245
|
+
cnp.uint32_t [::1] Bx) nogil:
|
246
|
+
|
247
|
+
cdef:
|
248
|
+
size_t i, col, dest
|
249
|
+
size_t n_vert = <size_t>(Bp.shape[0] - 1)
|
250
|
+
size_t n_edge = <size_t>Bi.shape[0]
|
251
|
+
cnp.uint32_t temp, cumsum, last
|
252
|
+
|
253
|
+
for i in range(n_edge):
|
254
|
+
Bp[<size_t>Aj[i]] += 1
|
255
|
+
|
256
|
+
cumsum = 0
|
257
|
+
for i in range(n_vert):
|
258
|
+
temp = Bp[i]
|
259
|
+
Bp[i] = cumsum
|
260
|
+
cumsum += temp
|
261
|
+
Bp[<size_t>n_vert] = <cnp.uint32_t>n_edge
|
262
|
+
|
263
|
+
for i in range(n_edge):
|
264
|
+
col = <size_t>Aj[i]
|
265
|
+
dest = <size_t>Bp[col]
|
266
|
+
Bi[dest] = Ai[i]
|
267
|
+
Bx[dest] = Ax[i]
|
268
|
+
Bp[col] += 1
|
269
|
+
|
270
|
+
last = 0
|
271
|
+
for i in range(n_vert + 1):
|
272
|
+
temp = Bp[i]
|
273
|
+
Bp[i] = last
|
274
|
+
last = temp
|
275
|
+
|
276
|
+
|
277
|
+
cpdef void _coo_to_csr_float64(
|
278
|
+
cnp.uint32_t [::1] Ai,
|
279
|
+
cnp.uint32_t [::1] Aj,
|
280
|
+
cnp.float64_t [::1] Ax,
|
281
|
+
cnp.uint32_t [::1] Bp,
|
282
|
+
cnp.uint32_t [::1] Bj,
|
283
|
+
cnp.float64_t [::1] Bx) nogil noexcept:
|
284
|
+
|
285
|
+
cdef:
|
286
|
+
size_t i, row, dest
|
287
|
+
size_t n_vert = <size_t>(Bp.shape[0] - 1)
|
288
|
+
size_t n_edge = <size_t>Bj.shape[0]
|
289
|
+
cnp.uint32_t temp, cumsum, last
|
290
|
+
|
291
|
+
for i in range(n_edge):
|
292
|
+
Bp[<size_t>Ai[i]] += 1
|
293
|
+
|
294
|
+
cumsum = 0
|
295
|
+
for i in range(n_vert):
|
296
|
+
temp = Bp[i]
|
297
|
+
Bp[i] = cumsum
|
298
|
+
cumsum += temp
|
299
|
+
Bp[n_vert] = <cnp.uint32_t>n_edge
|
300
|
+
|
301
|
+
for i in range(n_edge):
|
302
|
+
row = <size_t>Ai[i]
|
303
|
+
dest = <size_t>Bp[row]
|
304
|
+
Bj[dest] = Aj[i]
|
305
|
+
Bx[dest] = Ax[i]
|
306
|
+
Bp[row] += 1
|
307
|
+
|
308
|
+
last = 0
|
309
|
+
for i in range(n_vert + 1):
|
310
|
+
temp = Bp[i]
|
311
|
+
Bp[i] = last
|
312
|
+
last = temp
|
313
|
+
|
314
|
+
|
315
|
+
cpdef void _coo_to_csc_float64(
|
316
|
+
cnp.uint32_t [::1] Ai,
|
317
|
+
cnp.uint32_t [::1] Aj,
|
318
|
+
cnp.float64_t [::1] Ax,
|
319
|
+
cnp.uint32_t [::1] Bp,
|
320
|
+
cnp.uint32_t [::1] Bi,
|
321
|
+
cnp.float64_t [::1] Bx) nogil noexcept:
|
322
|
+
|
323
|
+
cdef:
|
324
|
+
size_t i, col, dest
|
325
|
+
size_t n_vert = <size_t>(Bp.shape[0] - 1)
|
326
|
+
size_t n_edge = <size_t>Bi.shape[0]
|
327
|
+
cnp.uint32_t temp, cumsum, last
|
328
|
+
|
329
|
+
for i in range(n_edge):
|
330
|
+
Bp[<size_t>Aj[i]] += 1
|
331
|
+
|
332
|
+
cumsum = 0
|
333
|
+
for i in range(n_vert):
|
334
|
+
temp = Bp[i]
|
335
|
+
Bp[i] = cumsum
|
336
|
+
cumsum += temp
|
337
|
+
Bp[<size_t>n_vert] = <cnp.uint32_t>n_edge
|
338
|
+
|
339
|
+
for i in range(n_edge):
|
340
|
+
col = <size_t>Aj[i]
|
341
|
+
dest = <size_t>Bp[col]
|
342
|
+
Bi[dest] = Ai[i]
|
343
|
+
Bx[dest] = Ax[i]
|
344
|
+
Bp[col] += 1
|
345
|
+
|
346
|
+
last = 0
|
347
|
+
for i in range(n_vert + 1):
|
348
|
+
temp = Bp[i]
|
349
|
+
Bp[i] = last
|
350
|
+
last = temp
|
351
|
+
|
352
|
+
|
353
|
+
# author : Francois Pacull
|
354
|
+
# copyright : Architecture & Performance
|
355
|
+
# email: francois.pacull@architecture-performance.fr
|
356
|
+
# license : MIT
|
edsger/utils.py
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
"""This module makes it easy to execute common tasks in Python scripts such as generate random
|
2
|
+
graphs.
|
3
|
+
"""
|
4
|
+
|
5
|
+
import numpy as np
|
6
|
+
import pandas as pd
|
7
|
+
|
8
|
+
|
9
|
+
def generate_random_network(n_edges=100, n_verts=20, seed=124, sort=True):
|
10
|
+
"""
|
11
|
+
Generate a random network with a specified number of edges and vertices.
|
12
|
+
|
13
|
+
Parameters
|
14
|
+
----------
|
15
|
+
n_edges : int, optional
|
16
|
+
The number of edges in the network. Default is 100.
|
17
|
+
n_verts : int, optional
|
18
|
+
The number of vertices in the network. Default is 20.
|
19
|
+
seed : int, optional
|
20
|
+
The seed for the random number generator. Default is 124.
|
21
|
+
sort : bool, optional
|
22
|
+
Whether to sort the edges by tail and head vertices. Default is True.
|
23
|
+
|
24
|
+
Returns
|
25
|
+
-------
|
26
|
+
edges : pandas.DataFrame
|
27
|
+
A DataFrame containing the edges of the network with columns 'tail', 'head', and 'weight'.
|
28
|
+
|
29
|
+
Examples
|
30
|
+
--------
|
31
|
+
>>> generate_random_network(n_edges=5, n_verts=3, seed=42)
|
32
|
+
tail head weight
|
33
|
+
0 0 2 0.975622
|
34
|
+
1 1 0 0.128114
|
35
|
+
2 1 0 0.450386
|
36
|
+
3 1 2 0.786064
|
37
|
+
4 2 0 0.761140
|
38
|
+
|
39
|
+
|
40
|
+
Notes
|
41
|
+
-----
|
42
|
+
The 'tail' and 'head' columns represent the source and destination vertices of each edge,
|
43
|
+
respectively. The 'weight' column represents the weight of each edge, which is a random
|
44
|
+
float between 0 and 1.
|
45
|
+
|
46
|
+
If `sort` is True, the DataFrame is sorted by the 'tail' and 'head' columns and the index
|
47
|
+
is reset.
|
48
|
+
"""
|
49
|
+
rng = np.random.default_rng(seed=seed)
|
50
|
+
tail = rng.integers(low=0, high=n_verts, size=n_edges)
|
51
|
+
head = rng.integers(low=0, high=n_verts, size=n_edges)
|
52
|
+
weight = rng.random(size=n_edges)
|
53
|
+
edges = pd.DataFrame(data={"tail": tail, "head": head, "weight": weight})
|
54
|
+
if sort:
|
55
|
+
edges.sort_values(by=["tail", "head"], inplace=True)
|
56
|
+
edges.reset_index(drop=True, inplace=True)
|
57
|
+
return edges
|
58
|
+
|
59
|
+
|
60
|
+
# author : Francois Pacull
|
61
|
+
# copyright : Architecture & Performance
|
62
|
+
# email: francois.pacull@architecture-performance.fr
|
63
|
+
# license : MIT
|
@@ -0,0 +1,111 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: edsger
|
3
|
+
Version: 0.1.1
|
4
|
+
Summary: Graph algorithms in Cython.
|
5
|
+
Author-email: François Pacull <francois.pacull@architecture-performance.fr>
|
6
|
+
Maintainer-email: François Pacull <francois.pacull@architecture-performance.fr>
|
7
|
+
License: MIT License
|
8
|
+
Project-URL: Repository, https://github.com/aetperf/Edsger
|
9
|
+
Project-URL: Documentation, https://edsger.readthedocs.io
|
10
|
+
Keywords: python,graph,shortest path,Dijkstra
|
11
|
+
Platform: any
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
19
|
+
Classifier: License :: OSI Approved :: MIT License
|
20
|
+
Classifier: Operating System :: OS Independent
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
22
|
+
Requires-Python: >=3.9
|
23
|
+
Description-Content-Type: text/markdown
|
24
|
+
License-File: LICENSE
|
25
|
+
License-File: AUTHORS.rst
|
26
|
+
Requires-Dist: setuptools
|
27
|
+
Requires-Dist: setuptools_scm
|
28
|
+
Requires-Dist: numpy>=1.26
|
29
|
+
Requires-Dist: Cython>=3
|
30
|
+
Requires-Dist: pandas
|
31
|
+
Provides-Extra: dev
|
32
|
+
Requires-Dist: black; extra == "dev"
|
33
|
+
Provides-Extra: test
|
34
|
+
Requires-Dist: pytest; extra == "test"
|
35
|
+
Requires-Dist: scipy<1.11; extra == "test"
|
36
|
+
Provides-Extra: doc
|
37
|
+
Requires-Dist: sphinx; extra == "doc"
|
38
|
+
Requires-Dist: sphinx_design; extra == "doc"
|
39
|
+
Requires-Dist: sphinx_rtd_theme; extra == "doc"
|
40
|
+
Dynamic: license-file
|
41
|
+
|
42
|
+
|
43
|
+

|
44
|
+
[](https://codecov.io/gh/aetperf/edsger)
|
45
|
+
[](https://pypi.org/project/edsger/)
|
46
|
+
[](https://pepy.tech/project/edsger)
|
47
|
+
[](https://pypi.org/project/edsger/)
|
48
|
+
[](https://github.com/psf/black)
|
49
|
+
[](https://github.com/MarcoGorelli/cython-lint)
|
50
|
+
[](https://opensource.org/licenses/MIT)
|
51
|
+
|
52
|
+
# Edsger
|
53
|
+
|
54
|
+
*Graph algorithms in Cython*
|
55
|
+
|
56
|
+
Welcome to our Python library for graph algorithms. So far, the library only includes Dijkstra's algorithm but we should add a range of common path algorithms later. It is also open-source and easy to integrate with other Python libraries. To get started, simply install the library using pip, and import it into your Python project.
|
57
|
+
|
58
|
+
Documentation : [https://edsger.readthedocs.io/en/latest/](https://edsger.readthedocs.io/en/latest/)
|
59
|
+
|
60
|
+
## Small example : Dijkstra's Algorithm
|
61
|
+
|
62
|
+
To use Dijkstra's algorithm, you can import the `Dijkstra` class from the `path` module. The function takes a graph and a source node as input, and returns the shortest path from the source node to all other nodes in the graph.
|
63
|
+
|
64
|
+
```python
|
65
|
+
import pandas as pd
|
66
|
+
|
67
|
+
from edsger.path import Dijkstra
|
68
|
+
|
69
|
+
# Create a DataFrame with the edges of the graph
|
70
|
+
edges = pd.DataFrame({
|
71
|
+
'tail': [0, 0, 1, 2, 2, 3],
|
72
|
+
'head': [1, 2, 2, 3, 4, 4],
|
73
|
+
'weight': [1, 4, 2, 1, 3, 1]
|
74
|
+
})
|
75
|
+
edges
|
76
|
+
```
|
77
|
+
|
78
|
+
| | tail | head | weight |
|
79
|
+
|---:|-------:|-------:|---------:|
|
80
|
+
| 0 | 0 | 1 | 1 |
|
81
|
+
| 1 | 0 | 2 | 4 |
|
82
|
+
| 2 | 1 | 2 | 2 |
|
83
|
+
| 3 | 2 | 3 | 1 |
|
84
|
+
| 4 | 2 | 4 | 3 |
|
85
|
+
| 5 | 3 | 4 | 1 |
|
86
|
+
|
87
|
+
|
88
|
+
```python
|
89
|
+
# Initialize the Dijkstra object
|
90
|
+
dijkstra = Dijkstra(edges)
|
91
|
+
|
92
|
+
# Run the algorithm from a source vertex
|
93
|
+
shortest_paths = dijkstra.run(vertex_idx=0)
|
94
|
+
print("Shortest paths:", shortest_paths)
|
95
|
+
```
|
96
|
+
|
97
|
+
Shortest paths: [0. 1. 3. 4. 5.]
|
98
|
+
|
99
|
+
We get the shortest paths from the source node 0 to all other nodes in the graph. The output is an array with the shortest path length to each node. A path length is the sum of the weights of the edges in the path.
|
100
|
+
|
101
|
+
## Contributing
|
102
|
+
|
103
|
+
We welcome contributions to the Edsger library. If you have any suggestions, bug reports, or feature requests, please open an issue on our [GitHub repository](https://github.com/aetperf/Edsger).
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
Edsger is licensed under the MIT License. See the LICENSE file for more details.
|
108
|
+
|
109
|
+
## Contact
|
110
|
+
|
111
|
+
For any questions or inquiries, please contact François Pacull at [francois.pacull@architecture-performance.fr](mailto:francois.pacull@architecture-performance.fr).
|
@@ -0,0 +1,32 @@
|
|
1
|
+
edsger/spiess_florian.c,sha256=KU6OZ1sliQpUGlMG73c6Odb3wA-E38F9AhMHrQ3c_Tc,1356872
|
2
|
+
edsger/dijkstra.c,sha256=JLA5x6_f9xiNpQtTSx0K1Mljo9vcaFjdxMLnlMawgQc,1429833
|
3
|
+
edsger/_version.py,sha256=8oAxKUG747GUokmxjkrWejyJa5yPNEsoJDlXxoedxTw,21
|
4
|
+
edsger/spiess_florian.cpython-311-darwin.so,sha256=wiIhSju1ENImbR5729POg6GSOtczgfGrj-uDUUlg3Ps,259064
|
5
|
+
edsger/commons.c,sha256=Iuh_KvawjvJjiOliIKzQYMOhFSt4UmS9lK6FuqdIli4,342928
|
6
|
+
edsger/star.c,sha256=n3sC5MnnvC4WawMdnLk6fDCoCRSsbFZQ5eMsnX50lKs,1318992
|
7
|
+
edsger/path_tracking.cpython-311-darwin.so,sha256=li3qGPI5PjVclaufKO4u-8buXrBMy0SZ3pJUlnkVxvU,188576
|
8
|
+
edsger/commons.pyx,sha256=rPWrq1zfN_IuTgLgvvQe8ma7bU1e3V8lWbBEFH5Vaw8,805
|
9
|
+
edsger/pq_4ary_dec_0b.pxd,sha256=l-FIgqJzd8Oelh0DgvqPe59ZMQeo2R3qjPXQwgRGX0w,1002
|
10
|
+
edsger/__init__.py,sha256=CoqO_GHq5NC94S2JrYjf6dVGOKnxJ2TRBDOjikyscOY,40
|
11
|
+
edsger/path_tracking.c,sha256=UFvhkdV4qUNENwWRd8J-Zw2XJbavgwCLNp0DAqGaN2Q,1143858
|
12
|
+
edsger/spiess_florian.pyx,sha256=9CrcMyzwSXaC_EdSl1uiD9yhFH6ACtooZOMfYw6vhvA,9566
|
13
|
+
edsger/pq_4ary_dec_0b.c,sha256=aqjMNaO6Ccc2Cdzigbk-jTKzzt9RZ2kBIOPjSiNUE8g,1367247
|
14
|
+
edsger/dijkstra.cpython-311-darwin.so,sha256=kqSjClwVdpO2P2FHuJyeIPbrUMUMiRBgsjjzH1d8lYU,292112
|
15
|
+
edsger/networks.py,sha256=o_dKC6fcxsqWr3fE0m5sUQkpZO-0B2x-w51l_1fyzAc,10316
|
16
|
+
edsger/commons.pxd,sha256=P9-n7ChbSIMSBRRY_lY3gBwXYUSvqJG-S_6e0dZTYU8,439
|
17
|
+
edsger/.gitignore,sha256=tWvEr3sBkY2ODntRp4_IUz3cidH-xu1efiOQK9DfK04,12
|
18
|
+
edsger/utils.py,sha256=igl2xDpkjTuQ5fhDdynQ0ekMSva52BstrTsZaTtE2RI,2034
|
19
|
+
edsger/pq_4ary_dec_0b.pyx,sha256=mWZUpnybIH9i8KoPYZV_l9cXkbpQz5GvXi_VUIuYwGo,17829
|
20
|
+
edsger/commons.cpython-311-darwin.so,sha256=giTgyHh8ul4WHghmoynf-dZokZdUfSyJ2VFagnWceoI,57184
|
21
|
+
edsger/path_tracking.pyx,sha256=nv3TUqlXaVNOVHexZumK0pScMlCHOsxaraeo1hO3HKU,1807
|
22
|
+
edsger/star.cpython-311-darwin.so,sha256=VpT6A9yBckYJbEE_9y_5Q9FTelYe0WcJlENmn20MLYQ,240120
|
23
|
+
edsger/path.py,sha256=chpFtMyCRLlYiYDqES9EzwGF4anHteF_u0oQMuvCakA,29609
|
24
|
+
edsger/dijkstra.pyx,sha256=8LScm1j_5juXNrPQbM_n6x-G8P6HihzMmT4Nt3FP7gU,16326
|
25
|
+
edsger/star.pyx,sha256=8evOrVygSLI-mMXsXFBfcw9qTqkeo3Ncm0ua5jjEMwE,9246
|
26
|
+
edsger/pq_4ary_dec_0b.cpython-311-darwin.so,sha256=F7N4BvNwRr4yId5HwFksM9SEHYA_3tufOrkB6BB87K8,226552
|
27
|
+
edsger-0.1.1.dist-info/RECORD,,
|
28
|
+
edsger-0.1.1.dist-info/WHEEL,sha256=qxQkdhERtGxJzqnVOBnucx1aUmU2n3HmuzYdln_LyOw,109
|
29
|
+
edsger-0.1.1.dist-info/top_level.txt,sha256=QvhzFORJIIot6GzSnDrtGa9KQt9iifCbOC5ULlzY5dg,7
|
30
|
+
edsger-0.1.1.dist-info/METADATA,sha256=XFq5xeiFwVheYlfC8ApWaFwqoUI8uQZ0272_gQhZQbQ,4678
|
31
|
+
edsger-0.1.1.dist-info/licenses/LICENSE,sha256=eNjfz5CInLrVdczJbhazCKtb8-0qB0UaXZ3bXN0zio0,1111
|
32
|
+
edsger-0.1.1.dist-info/licenses/AUTHORS.rst,sha256=9lqpqjiC4XukK7jdxXwKJJrddqwCV2DjpYTqhpP6znA,105
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Francois Pacull - Architecture & Performance
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
edsger
|