Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Try_English_LT.pdf

canonno
February 07, 2021

 Try_English_LT.pdf

canonno

February 07, 2021
Tweet

More Decks by canonno

Other Decks in Programming

Transcript

  1. If Takashi-kun runs from Hokkaido to Okinawa at 10 km

    an hour @canonno_blog Soichiro Kano
  2. I want to learn mathematical optimization in python OK, I

    prepare a toy problem. Well, well…
  3. Conditions • Takashi-kun runs through 47 prefectural office locations (ex.

    Kobe city in Hyogo, Otsu city in Shiga) • Departure: Sapporo city • Destination: Naha city • He is so strong that he run only straight. • He is so strong that he can run through the mountain. • He is so strong that he can run over the sea. • He is so strong that he can run without a break.
  4. My approach ① Get the locations of the 47 prefectural

    office, and calculate the distance from one to another. ② Define the objective (what we want to minimize) ③ Define the constraints ④ Solve! ※Useful packages: networkx: to build and draw networks pulp: to optimize and decide the best condition
  5. ② Define the objective value x2 x1 No.1 No.3 No.4

    No.2 x3 x4 x5 x6 x1~x6: Boolean d1~d6: Distance
  6. ② Define the objective value d2 d1 No.1 No.3 No.4

    No.2 d3 d4 d5 d6 x1~x6: Boolean d1~d6: Distance
  7. ② Define the objective value d2 d1 No.1 No.3 No.4

    No.2 d3 d4 d5 d6 x1~x6: Boolean d1~d6: Distance x1d1 + x2d2 + x3d3+ x4d4+ x5d5+ x6d6 = Total distance
  8. ③ Define the constraints Departure・destination will have only ONE edge

    x1+x3+x4 = 1 x2+x3+x6 = 1 Others will have TWO edges x1+x2+x5 = 2 x4+x5+x6 = 2
  9. The answer is: he has to run for… A. 2.5

    weeks B. 5 weeks C. 7.5 weeks