Python, or How Did Another Programming Language Made Me Regret My Choices

​I know, compared to a lot (and by that I mean A LOT) of people, I have no idea of programming. Still, people in my professional circles (in Civil or Transportation Eng.) often ask me for recommendations on the topic.

A couple of days ago, I wanted to pursue something I wanted to do for a long time. I tried to implement my Traffic Assignment Problem code (For Static problems, using Frank-Wolfe optimizer with Bellman-Ford shortest path) into Python. When I initially got that assignment, I implemented the first part (Shortest Path) in C++, and when things got a little out of hand, I chickened out and used MATLAB.

​I didn't like the editor Python supplies when you first install it, so I found this beautiful plugin for Eclipse called PyDev. I knew Eclipse as that's what I use for Java and LaTeX, so it was comfortable for me.

I wanted this to be as close to Object Oriented as possible, so I tried to keep the main function really small, building everything into their individual modules. It was actually fun seeing them interact in their tiny little local ways. One other thing I noticed is, how easy it would be for someone just get my code and read it.

  • Read the data
  • Assign the values
  • Delete the object because you don't need it anymore
  • And then just initialize and run the solver

​Well this is still a work in progress so I haven't implemented the actual optimizer, but here is a problem that I had after finishing this part. It runs SLOW! By slow, I mean it took it a good 5 minutes to finish, whereas C++ took around 5 seconds. Now this specific network is around 13000 nodes and 40000 links. So I went to StackOverflow and a lot of people had similar experiences with just stock Python. Luckily, there is a solution for that as well.

​Meet PyPy, a fast, compliant alternative implementation of the Python language (the developer's words). I initially thought using NumPy vectors as well, but that's left for later on. Well, it worked. Still not good as C++, but around 20 seconds. Now this might be entirely because 

  • I'm using Bellman-Ford
  • I'm using Python, or
  • Evil Masterminds that dwell in my processor(s)

But still, it was fun. It was easy. And, most importantly, it was a good learning experience. Also, it's easier to access, it's free and it can run on Linux if need be.