11
11
:target: https://landscape.io/github/brooksandrew/postman_problems/master
12
12
:alt: Code Health
13
13
14
+ *Note to those reading this on PyPI: For a better reading experience, checkout the README on GitHub *
15
+ `here <https://github.com/brooksandrew/postman_problems/blob/master/README.rst >`__. *GitHub and PyPI are not
16
+ cooperating on rendering SVGs *.
17
+
18
+
14
19
15
20
.. sectnum ::
16
21
@@ -49,14 +54,14 @@ guarantees they'll be stable.
49
54
50
55
1. Clone the repo.
51
56
52
- .. code :: bash
57
+ .. code ::
53
58
54
59
git clone https://github.com/brooksandrew/postman_problems.git
55
60
cd postman_problems
56
61
57
62
2. Install with pip. Builds are tested on Python 2.7, 3.3, 3.4, 3.5, 3.6.
58
63
59
- .. code :: bash
64
+ .. code ::
60
65
61
66
pip install .
62
67
@@ -71,7 +76,7 @@ installing viz dependencies, if they so choose.
71
76
72
77
1. Install optional Python visualization libraries.
73
78
74
- .. code :: bash
79
+ .. code ::
75
80
76
81
pip install postman_problems[viz]
77
82
@@ -81,15 +86,15 @@ installing viz dependencies, if they so choose.
81
86
82
87
For Mac, this should be as easy as:
83
88
84
- .. code :: bash
89
+ .. code ::
85
90
86
- brew install graphviz
91
+ brew install graphviz
87
92
88
93
For Linux,
89
94
90
- .. code :: bash
95
+ .. code ::
91
96
92
- sudo apt-get install graphviz
97
+ sudo apt-get install graphviz
93
98
94
99
These are the installs I'm currently using on my builds for the `tests on TravisCI `_. YMMV. For Windows users and
95
100
for those where these methods fail, I defer to the Graphviz download docs.
@@ -118,14 +123,14 @@ A note on some edge attributes:
118
123
- ``required ``: must be provided for the RPP. 0 is used for optional edges, 1 for required.
119
124
- ``distance ``: default edge attribute used for shortest path computations. Can be overridden with ``edge_weight ``.
120
125
- ``id ``: recommended to not include, but will be used if provided. This will be generated automatically to assist with
121
- computation of parallel edges. If provided, it should be unique to ensure stable computation.
126
+ computation of parallel edges. If provided, it should be unique to ensure stable computation.
122
127
123
128
Arguments: others
124
129
~~~~~~~~~~~~~~~~~
125
130
126
131
For the complete list of optional arguments run one of the following:
127
132
128
- .. code :: bash
133
+ .. code ::
129
134
130
135
chinese_postman --help
131
136
rural_postman --help
@@ -140,21 +145,21 @@ Simple example
140
145
Below we solve the CPP on the `Seven Bridges of Konigsberg `_ network. The edgelist is provided in this repo, but you
141
146
can swap this out for any comma delimited text file where the first two columns represent the node pairs in your network.
142
147
143
- .. code :: bash
148
+ .. code ::
144
149
145
150
chinese_postman --edgelist postman_problems/examples/seven_bridges/edgelist_seven_bridges.csv
146
151
147
152
148
153
If the ``chinese_postman `` entry point is not working for whatever reason, you can run the script directly with:
149
154
150
- .. code :: bash
155
+ .. code ::
151
156
152
157
python postman_problems/chinese_postman.py --edgelist postman_problems/examples/seven_bridges/edgelist_seven_bridges.csv
153
158
154
159
155
160
You should see output that describes the CPP route solution (Eulerian circuit through each edge). Something like this:
156
161
157
- .. code ::
162
+ .. code ::
158
163
159
164
('A', 'C', 1, {'trail': 'd', 'distance': 10, 'id': 3})
160
165
('C', 'D', 0, {'trail': 'g', 'distance': 3, 'id': 6, 'augmented': True})
@@ -179,7 +184,7 @@ with two exceptions:
179
184
180
185
A summary report of the solution should be printed. Something like this:
181
186
182
- .. code ::
187
+ .. code ::
183
188
184
189
Solution summary stats:
185
190
distance_walked : 39
@@ -205,20 +210,19 @@ The snippet below should produce exactly the same output as printed above in `CL
205
210
206
211
.. code :: python
207
212
208
- from postman_problems.solver import cpp
209
- from postman_problems.stats import calculate_postman_solution_stats
213
+ from postman_problems.solver import cpp
214
+ from postman_problems.stats import calculate_postman_solution_stats
210
215
211
- # find CPP solution
212
- circuit, graph = cpp(edgelist_filename = ' postman_problems/examples/seven_bridges/edgelist_seven_bridges.csv' ,
213
- start_node = ' D' )
216
+ # find CPP solution
217
+ circuit, graph = cpp(edgelist_filename = ' postman_problems/examples/seven_bridges/edgelist_seven_bridges.csv' , start_node = ' D' )
214
218
215
- # print solution route
216
- for e in circuit:
217
- print (e)
219
+ # print solution route
220
+ for e in circuit:
221
+ print (e)
218
222
219
- # print solution summary stats
220
- for k, v in calculate_postman_solution_stats(circuit).items():
221
- print (k, v)
223
+ # print solution summary stats
224
+ for k, v in calculate_postman_solution_stats(circuit).items():
225
+ print (k, v)
222
226
223
227
224
228
Examples
@@ -257,7 +261,7 @@ right and this property is a key part of solving the Postman Problems.
257
261
258
262
This contrived example has been bundled and parameterized into a script that can be run with:
259
263
260
- .. code :: bash
264
+ .. code ::
261
265
262
266
chinese_postman_seven_bridges
263
267
@@ -266,7 +270,7 @@ The example can also be run using the verbose method below which allows you to p
266
270
Many of the options provided below are defaults and can be excluded in practice. They are included here simply to convey
267
271
what the possibilities are:
268
272
269
- .. code :: bash
273
+ .. code ::
270
274
271
275
chinese_postman --edgelist postman_problems/examples/seven_bridges/edgelist_seven_bridges.csv \
272
276
--viz \
@@ -282,7 +286,7 @@ what the possibilities are:
282
286
283
287
``base_cpp_graph.svg ``: This is the starting graph. Edges are annotated by distance.
284
288
285
- .. image :: . /postman_problems/examples/seven_bridges/output/base_cpp_graph.svg
289
+ .. image :: https://github.com/brooksandrew/postman_problems/raw/master /postman_problems/examples/seven_bridges/output/base_cpp_graph.svg
286
290
287
291
288
292
``cpp_graph.svg ``: Edges are annotated with the order in which they are walked, starting at 0. Edges walked more than
@@ -299,7 +303,7 @@ once are annotated by a sequence of numbers (walk order) and **bolded**.
299
303
``cpp_graph ``: dot representation of the graph is also provided. This is mostly for reference, but in rare cases you may
300
304
want to tweak graphviz parameters directly here.
301
305
302
- .. code ::
306
+ .. code ::
303
307
304
308
graph {
305
309
graph [forcelabels=true "strict"=false]
@@ -325,7 +329,7 @@ This is a simple example that demonstrates the power of the RPP vs CPP.
325
329
326
330
Run with:
327
331
328
- .. code :: bash
332
+ .. code ::
329
333
330
334
rural_postman_star
331
335
@@ -369,7 +373,7 @@ That's all I'll say here. I wrote more about the personal motivation and Sleepi
369
373
370
374
Run this example with:
371
375
372
- .. code :: bash
376
+ .. code ::
373
377
374
378
rural_postman_sleeping_giant
375
379
@@ -386,7 +390,7 @@ annotating their order in the route).
386
390
387
391
Here are the solution summary stats.
388
392
389
- .. code ::
393
+ .. code ::
390
394
391
395
RPP Solution summary stats:
392
396
@@ -408,7 +412,7 @@ so it is omitted here.
408
412
For a base of comparison on RPP vs CPP, selected stats are printed below for the CPP. the RPP shortens the CPP solution
409
413
route by about 1 mile.
410
414
411
- .. code ::
415
+ .. code ::
412
416
413
417
CPP Solution summary stats:
414
418
@@ -429,33 +433,33 @@ If you'd like to fork or contribute directly to this project (PRs welcome), or s
429
433
430
434
1. Full install with test and viz dependencies.
431
435
432
- .. code :: bash
436
+ .. code ::
433
437
434
438
pip install .[test,viz]
435
439
436
440
Or do an editable install from the beginning. This is my typical approach when developing.
437
441
438
- .. code :: bash
442
+ .. code ::
439
443
440
- pip install -e .[test,viz]
444
+ pip install -e .[test,viz]
441
445
442
446
2.
443
447
444
448
.. image :: http://troll.me/images/x-all-the-things/run-all-the-tests.jpg
445
449
446
- .. code :: bash
450
+ .. code ::
447
451
448
- python -m pytest
449
- pytest --cov
452
+ python -m pytest
453
+ pytest --cov
450
454
451
455
Some tests take quite a while to run. Namely the examples that write visualizations to the filesystem for large networks.
452
456
453
457
As I have limited patience while developing, but am too cautious to drop them completely, I've kept and marked them with the ``@slow `` and ``@long `` decorators. ``conftest.py `` is configured to exclude them by default with a simple run of ``pytest `` or ``python -m pytest ``, but the full test suite can be run by:
454
458
455
- .. code :: bash
459
+ .. code ::
456
460
457
- python -m pytest --runslow
458
- pytest --cov --runslow
461
+ python -m pytest --runslow
462
+ pytest --cov --runslow
459
463
460
464
461
465
Release Notes
0 commit comments