using python to solve computationally hard problemsassets.en.oreilly.com/1/event/80/using python to...
TRANSCRIPT
![Page 1: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/1.jpg)
Using Python to Solve Computationally Hard
Problems
![Page 2: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/2.jpg)
Using Python to Solve Computationally Hard Problems
Rachael Madsen
Optimal Design Software LLC
– BS in Mathematics
– Software Engineer & Architect
– Python programmer
![Page 3: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/3.jpg)
NP-Complete Problems
![Page 4: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/4.jpg)
NP-Complete Problems
An individual solution can be checked for correctness in polynomial time,
but..
A solution cannot be derived in polynomial time
![Page 5: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/5.jpg)
NP-Complete Problems
Nodes 1 5 10 64
Polynomial (𝒏𝟐) 1 25 100 4096
Exponential (𝟐𝒏) 2 32 1024 1.8 x 10 19
Factorial (n!) 1 120 3.6 x 10 6 1.3 x 10 89
![Page 6: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/6.jpg)
NP-Complete Problems
• Sequencing tasks or objects for any optimization
• Database design & normalization
• Games
![Page 7: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/7.jpg)
The
Traveling Salesman
Problem
![Page 8: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/8.jpg)
Traveling Salesman Problem
Given a list of cities and their pairwise distances, find the shortest possible route that visits each city exactly once and returns to the origin city.
![Page 9: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/9.jpg)
Algorithms
![Page 10: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/10.jpg)
Algorithms
Changing data may change which algorithm is best
![Page 11: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/11.jpg)
Algorithms
Searching available software implementations may yield the best results
![Page 12: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/12.jpg)
Considerations
Algorithms
![Page 13: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/13.jpg)
Ease of Implementation
Algorithms > Considerations
![Page 14: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/14.jpg)
Quality of Solution
Algorithms > Considerations
![Page 15: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/15.jpg)
You are looking for a solution, not the solution
Algorithms > Considerations > Quality of Solution
![Page 16: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/16.jpg)
Algorithms > Considerations > Quality of Solution
𝜋 = 1
16𝑘 4
8𝑘 + 1 −
2
8𝑘 + 4 −
1
8𝑘 + 5 −
1
8𝑘 + 6
∞
𝑘=0
![Page 17: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/17.jpg)
Will this algorithm generate valleys?
Algorithms > Considerations > Quality of Solution
![Page 18: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/18.jpg)
Complexity
Algorithms > Considerations
![Page 19: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/19.jpg)
• Simple
–50 lines of code
• Complex
–100,000+ lines of code
Algorithms > Considerations > Complexity
![Page 20: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/20.jpg)
Parallelization
Algorithms > Considerations
![Page 21: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/21.jpg)
Processing Power
Algorithms > Considerations
![Page 22: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/22.jpg)
Starting From Scratch
![Page 23: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/23.jpg)
Starting From Scratch
(it’s a bad idea)
![Page 24: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/24.jpg)
Python Options
![Page 25: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/25.jpg)
Python Options
Where to Look
![Page 26: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/26.jpg)
Python Options > Where to Look
• Google code
• Git
• Forums
• Technical books
![Page 27: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/27.jpg)
Python Options
Licenses
![Page 28: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/28.jpg)
Python Options
Evaluation
![Page 29: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/29.jpg)
Python Options > Evaluation
Operations Research Tools Developed at Google
http://code.google.com/p/or-tools/source/ browse/trunk/python/tsp.py?r=303
![Page 30: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/30.jpg)
Runtime
• Lines of code: 132
• Hardware availability
Python Options > Evaluation > or-tools
![Page 31: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/31.jpg)
Python Options > Evaluation > or-tools
Quality of Solution
![Page 32: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/32.jpg)
Python Options > Evaluation
Github user trevlovett Python Ant Colony TSP Solver
https://github.com/trevlovett/ Python-Ant-Colony-TSP-Solver
![Page 33: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/33.jpg)
Runtime
• Lines of code: 132
• Hardware availability
Python Options > Evaluation > Ant Colony TSP Solver
![Page 34: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/34.jpg)
Python Options > Evaluation > Ant Colony TSP Solver
Quality of Solution
![Page 35: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/35.jpg)
Optimization
![Page 36: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/36.jpg)
• Confirm implementation of algorithm as written
• Check for most efficient coding practices
Optimization
![Page 37: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/37.jpg)
• Use scientific package such as SciPy to rewrite code for speed
• Break out select code into C routine
Optimization
![Page 38: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/38.jpg)
• Parallelize
–GPU
–CPU
Optimization
![Page 39: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/39.jpg)
Beware of fencepost errors and differences in hardware
Optimization
![Page 40: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/40.jpg)
Web Resources
![Page 41: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/41.jpg)
• The Stony Brook Code Repository, Concorde TSP Solver http://www.cs.sunysb.edu/~algorith/implement/concorde/implement.shtml
• TSP, github user denlunev, https://github.com/denlunev/TSP
• Operations Research Tools, Google, http://code.google.com/p/or-tools/source/browse/trunk/python/tsp.py?r=303
• Ant Colony TSP Solver, github user trevlovett https://github.com/trevlovett/Python-Ant-Colony-TSP-Solver
Web Resources
![Page 42: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/42.jpg)
Bibliography
![Page 43: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/43.jpg)
• Introduction to Graph Theory, 2nd Edition, Douglas Brent West, Prentice Hall, 2000
• The Traveling Salesman Problem: A Computational Study, Applegate, Bixby, Chvátal & Cook, Princeton U. Press, 2007
• The Traveling Salesman Problem: A Guided Tour of Combinatorial Optimization, Lawler, Lenstra, Kan & Shmoys, Wiley, 1985
• The Traveling Salesman Problem and its Variations, Gutin & Punnen, Springer, 2002
Bibliography
![Page 44: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/44.jpg)
• Combinatorial Optimization: Theory and Algorithms, 2nd Edition, Korte & Vygen, Springer, 2002
• Combinatorial Optimization, Cook, Cunningham, Pulleyblank & Schrijver, Wiley-Interscience, 1997
• Local Search in Combinatorial Optimization, Aarts & Lenstra, Wiley, 1997
• Combinatorial Algorithms: Generation, Enumeration, and Search, Kreher & Stinson,CRC Press, 1998
Bibliography
![Page 45: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/45.jpg)
• Counting: The Art of Enumerative Combinatorics, Martin, Springer, 2001
• Counting and Configurations, Herman, Kucera & Simsa, Springer, 2003
• Abstract Algebra, 3rd Edition, Dummit & Foote, Wiley, 2003
Bibliography
![Page 46: Using Python to Solve Computationally Hard Problemsassets.en.oreilly.com/1/event/80/Using Python to Solve... · Using Python to Solve Computationally Hard Problems. Using Python to](https://reader034.vdocuments.us/reader034/viewer/2022052309/5b1686ad7f8b9a686d8c7653/html5/thumbnails/46.jpg)
Thank You!