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

Try_English_LT.pdf

E186140d248e8c3db33a506061e12d37?s=47 canonno
February 07, 2021

 Try_English_LT.pdf

E186140d248e8c3db33a506061e12d37?s=128

canonno

February 07, 2021
Tweet

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. If Takashi-kun runs from Hokkaido to Okinawa at 10 km

    an hour
  4. 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.
  5. Guess which? He has to run for… A. 2.5 weeks

    B. 5 weeks C. 7.5 weeks
  6. 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
  7. ①Get the locations website pandas.DataFrame

  8. ①Calculate the distances pandas.DataFrame pandas.DataFrame

  9. ② Define the objective value x2 x1 No.1 No.3 No.4

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

    No.2 d3 d4 d5 d6 x1~x6: Boolean d1~d6: Distance
  11. ② 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
  12. ② Define the objective value

  13. ② Define the objective value

  14. ② Define the objective value

  15. ③ 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
  16. ④ Solve

  17. ④ Solve 4361km 436.1 hours (if run at 10km/hour) about

    18 days 4 hours about 2.5 weeks
  18. ④ Solve 4361km 436.1 hours (if run at 10km/hour) about

    18 days 4 hours about 2.5 weeks
  19. The answer is: he has to run for… A. 2.5

    weeks B. 5 weeks C. 7.5 weeks
  20. Check it out my Qiita page! Thank you! @canonno_blog