Using Python to Solve Computationally Hard Problems Using Python to - - PowerPoint PPT Presentation

using python to solve
SMART_READER_LITE
LIVE PREVIEW

Using Python to Solve Computationally Hard Problems Using Python to - - PowerPoint PPT Presentation

Using Python to Solve Computationally Hard Problems Using Python to Solve Computationally Hard Problems Rachael Madsen Optimal Design Software LLC BS in Mathematics Software Engineer & Architect Python programmer


slide-1
SLIDE 1

Using Python to Solve Computationally Hard Problems

slide-2
SLIDE 2

Using Python to Solve Computationally Hard Problems

Rachael Madsen

Optimal Design Software LLC

– BS in Mathematics – Software Engineer & Architect – Python programmer

rachael@optimaldesignsoftware.com

slide-3
SLIDE 3

NP-Complete Problems

slide-4
SLIDE 4

NP-Complete Problems

An individual solution can be checked for correctness in polynomial time, but.. A solution cannot be derived in polynomial time

slide-5
SLIDE 5

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

slide-6
SLIDE 6

NP-Complete Problems

  • Sequencing tasks or objects

for any optimization

  • Database design & normalization
  • Games
slide-7
SLIDE 7

The Traveling Salesman Problem

slide-8
SLIDE 8

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.

slide-9
SLIDE 9

Algorithms

slide-10
SLIDE 10

Algorithms

Changing data may change which algorithm is best

slide-11
SLIDE 11

Algorithms

Searching available software implementations may yield the best results

slide-12
SLIDE 12

Considerations

Algorithms

slide-13
SLIDE 13

Ease of Implementation

Algorithms > Considerations

slide-14
SLIDE 14

Quality of Solution

Algorithms > Considerations

slide-15
SLIDE 15

You are looking for a solution, not the solution

Algorithms > Considerations > Quality of Solution

slide-16
SLIDE 16

Algorithms > Considerations > Quality of Solution

𝜌 = 1 16𝑙 4 8𝑙 + 1 − 2 8𝑙 + 4 − 1 8𝑙 + 5 − 1 8𝑙 + 6

∞ 𝑙=0

slide-17
SLIDE 17

Will this algorithm generate valleys?

Algorithms > Considerations > Quality of Solution

slide-18
SLIDE 18

Complexity

Algorithms > Considerations

slide-19
SLIDE 19
  • Simple

–50 lines of code

  • Complex

–100,000+ lines of code

Algorithms > Considerations > Complexity

slide-20
SLIDE 20

Parallelization

Algorithms > Considerations

slide-21
SLIDE 21

Processing Power

Algorithms > Considerations

slide-22
SLIDE 22

Starting From Scratch

slide-23
SLIDE 23

Starting From Scratch (it’s a bad idea)

slide-24
SLIDE 24

Python Options

slide-25
SLIDE 25

Python Options

Where to Look

slide-26
SLIDE 26

Python Options > Where to Look

  • Google code
  • Git
  • Forums
  • Technical books
slide-27
SLIDE 27

Python Options

Licenses

slide-28
SLIDE 28

Python Options

Evaluation

slide-29
SLIDE 29

Python Options > Evaluation

Operations Research Tools

Developed at Google

http://code.google.com/p/or-tools/source/ browse/trunk/python/tsp.py?r=303

slide-30
SLIDE 30

Runtime

  • Lines of code: 132
  • Hardware availability

Python Options > Evaluation > or-tools

slide-31
SLIDE 31

Python Options > Evaluation > or-tools

Quality of Solution

slide-32
SLIDE 32

Python Options > Evaluation

Github user trevlovett

Python Ant Colony TSP Solver

https://github.com/trevlovett/ Python-Ant-Colony-TSP-Solver

slide-33
SLIDE 33

Runtime

  • Lines of code: 132
  • Hardware availability

Python Options > Evaluation > Ant Colony TSP Solver

slide-34
SLIDE 34

Python Options > Evaluation > Ant Colony TSP Solver

Quality of Solution

slide-35
SLIDE 35

Optimization

slide-36
SLIDE 36
  • Confirm implementation of

algorithm as written

  • Check for most efficient coding

practices

Optimization

slide-37
SLIDE 37
  • Use scientific package such as SciPy

to rewrite code for speed

  • Break out select code into C routine

Optimization

slide-38
SLIDE 38
  • Parallelize

–GPU –CPU

Optimization

slide-39
SLIDE 39

Beware of fencepost errors and differences in hardware

Optimization

slide-40
SLIDE 40

Web Resources

slide-41
SLIDE 41
  • The Stony Brook Code Repository, Concorde TSP Solver

http://www.cs.sunysb.edu/~algorith/implement/concorde/im plement.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

slide-42
SLIDE 42

Bibliography

slide-43
SLIDE 43
  • 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

slide-44
SLIDE 44
  • 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

slide-45
SLIDE 45
  • 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

slide-46
SLIDE 46

Thank You!