Mar 30 2011

C++, Robots, and unordered_map saves the day

I’ve been really div­ing into my C++ recently. I haven’t done too much of it, start­ing off in the Java world, and then mov­ing onto lots of Python devel­op­ment. But so far, I’ve been enjoy­ing myself quite a bit, mostly because of my Dis­trib­uted Sys­tems course at SFU. We are cur­rently work­ing on a robot sim­u­la­tion across mul­ti­ple com­put­ers, sim­u­lat­ing 1,000,000 robots puck­ing up 1,000,000 pucks.

Its been a chal­lenge, not only from a pro­gram­ming per­spec­tive, but much more so from a Soft­ware Engi­neer­ing per­spec­tive. Richard Vaughan, the pro­fes­sor, decided to have teams of 10 peo­ple, mean­ing that not only do you solve a dis­trib­uted sys­tem over a net­work of com­put­ers, but you also solve it across a team of indi­vid­u­als. The inter­est­ing thing about start­ing with 10 peo­ple is how to appro­pri­ately divvy up the work amongst our­selves (other groups solu­tions — let one guy beast out the entire thing, not cool! They skipped out on half the fun). Usu­ally in a project or startup, you would start with two peo­ple work­ing pas­sion­atly on a project, and high­er­ing more and more peo­ple comes out of neces­sity, where as start­ing a project with a group of 10 peo­ple can get extremely heck­tick. Espe­cially when more then half the group are some pretty close friends. We have had some big prob­lems along the way — heads butting for archi­tec­tural deci­sions, peo­ple not pulling there weight, bad com­mu­ni­ca­tion, etc. But there is a lot to learn out of a project like this, and I won’t talk about those things right now because it’s 3:20am and I’m tired, but I will def­i­nitely have a post mortem on this project. Going good right now though, this last week is going to be intense!

Oh, and unordered_map in the STL is awe­some. Pre­vi­ously, we were using the map datatype from the STL, for what we needed to do, we needed an insane amount of lookup, and because a lookup in a map is O(nlogn), things were slow­ing down big time. A cer­tain func­tion we had for doing bound­ing boxes was tak­ing ~5 min­utes, as we had to sort a list using inser­tion sort. The rea­son we used inser­tion sort is because while it is O(n^2) for the ini­tial sort, it is ~O(n) for any sort with a list that is almost sorted, and because each time step of a robot resulted in posi­tions that were not changed too much, inser­tion sort was per­fect. We also had to main­tain a hash for our objects map­ping to the index of that object in our sorted array, which is why we needed O(1) access. I sim­ply switched out std::map for std::unordered_map, and every­thing worked like a charm. Went from ~5 min­utes on ini­tial sort of 50,000 robots down to ~1.5 min­utes for the ini­tial sort using the unordered_map. Fun times :)

Posted via email from jansepar’s pos­ter­ous


Mar 29 2011

New shoes

Img_1223

Finally got a new pair of shoes. Girl­friend got them — I don’t think
I’d be able to find a pair like this, I would just walk into a champs
or Foot Locker. I need to update my wardrobe/fashion sense. They are
pen­guin brand, which I hadn’t heard of until yes­ter­day. They are
pretty nice, have a look below!

Posted via email from jansepar’s pos­ter­ous