Download presentation
Presentation is loading. Please wait.
Published byMervin Mosley Modified over 8 years ago
1
A few m3 tips
2
Street Segment Length / Travel Time Need to compute in double precision –Otherwise too much round off See piazza
3
Speed Tuning 1.Algorithm 2.Data structures 3.Low level code string streetName1, streetName2; if (streetName1 != streetName2) {... int streetId1, streetId2; if (streetId1 != streetId2) {... Any speed difference?
4
Debugging Algorithms Start with a very simple test case –Adjacent intersections! –Step / breakpoint code in debugger –Make sure it does what you expect!
5
Debugging Algorithms Try a slightly harder case –Two intersections apart –Step / breakpoint code in debugger again! –Make sure code behaving exactly as you expect
6
Bigger Cases: Graphics Helps Hard to see large amounts of data in debugger Use graphics to animate / visualize #define VISUALIZE while (wavefront.size() != 0) { waveElem = wavefront.front(); #ifdef VISUALIZE draw_street_seg (waveElem.edgeID); flushinput(); // Draw right away #endif... Can’t leave this in when I submit (will fail unit tests). How do I turn this off when speed testing & before submitting code?
7
Milestone 4: Courier Company
8
Problem Definition Return: low travel time path Starting and ending at some depot And reaching all 2N delivery intersections And always picking up a package before delivering it and Given M courier truck depots Given N deliveries (pick up, drop off) M = 3 here, all intersections N = 4 here, all intersections DD AA AA BB BB CC CC DD
9
No dropping off packages before they’re picked up! Possible Solution? AA AA BB BB CC CC DD DD
10
BB CC Legal Solution AA AA BB CC DD DD Output: vector of street segment ids
11
How? Re-use m3 path-finder // Go from first depot to first package pick up path = find_path (depot[0], delivery[0].pickUp); // Complete deliveries, in order for (i = 0; i < N-1; i++) { path += find_path (delivery[i].pickUp, delivery[i].dropOff); path += find_path (delivery[i].dropOff, delivery[i+1].pickUp); } // Drop off last package path += find_path (delivery[N-1].pickUp, delivery[N-1].dropOff); // Go back to the first depot to drop off the truck path += find_path (delivery[N-1].dropOff, depot[0]);
12
Lots of wasted travel! Possible Solution 0 1 2 AA AA BB BB CC CC DD DD
13
BB CC AA AA BB CC DD DD Need to optimize delivery order Recall: More Logical Solution
14
Exhaustive Algorithm? Try all possible delivery orders Pick the one with lowest travel time How many combinations? –M truck depots –N deliveries 2N pick-up + drop-off intersections –Pick one of M starting locations –Then pick one of 2N pick-up/drop-off intersections –Then one of 2N-1 for the second intersection –… (repeat until last delivery) –Then M places to drop off truck –M * 2N * (2N-1) * (2N-2) * … * 1 * M = M 2 (2N)! Some of these are illegal orders say algorithm checks legality after generating the solution
15
Exhaustive Algorithm? Say M = 10, N = 30 10 2 * (2*30)! = 8.3 x 10 83 Invoke find_path () 2N+1 times to get path between each intersection Say find_path takes 0.1 s (very good!) 8.3 x 10 83 * 61 * 0.1 s = 5.1 x 10 84 s 1.6 x 10 77 years! Lifetime of universe: ~14 x 10 9 years!
16
Traveling Salesman Problem We are solving a variation of the traveling salesman problem Computationally hard problem –For N deliveries, no guaranteed optimal (lowest travel time solution) in polynomial time i.e. > O(N k ), for any k Means at least O(2 N ) –Need to use heuristics to solve Most research problems are computationally hard –Integrated circuit design, drug design, transportation network design, …
17
Pioneer of Complexity Theory Stephen Cook, U of T professor in Computer Science Created the main theory of computationally hard problems NP-complete problems –No polynomial time solution known on conventional computers –Proved that if a method to solve any of these problems in polynomial time was found, then all these problems could be solved in polynomial time –P vs. NP: most famous open problem in computer science 1970: denied tenure at UC Berkeley 1971: published most famous paper 1982: won Turing award
18
Digression Top 10 Programming Languages (source: IEEE Spectrum,Oct2011 Issue)
22
Summary C++: 9% C: 16% (25% total) Java + C#: Another 28% –(Mostly) simplified C++ –Java: Android, web apps, IBM –C#: Microsoft’s answer to Java Objective C: Another 4% –Alternative syntax for adding objects to C –Apple (Mac, iPhone, …) Total: 57% C++ related
23
Grace Hopper Math professor & computer engineer Lead programmer on Harvard Mark I –1 st fully programmable comp Wrote first programming manual Created first compiler A- Known as both a great engineer and great communicator –Pioneering work in programming computers & computer languages
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.