Presentation is loading. Please wait.

Presentation is loading. Please wait.

A few m3 tips. Speed Tuning 1.Algorithm 2.Data structures 3.Low level code string streetName1, streetName2; if (streetName1 != streetName2) {... int streetId1,

Similar presentations


Presentation on theme: "A few m3 tips. Speed Tuning 1.Algorithm 2.Data structures 3.Low level code string streetName1, streetName2; if (streetName1 != streetName2) {... int streetId1,"— Presentation transcript:

1 A few m3 tips

2 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?

3 Debugging Algorithms Start with a very simple test case –Adjacent intersections! –Step / breakpoint code in debugger –Make sure it does what you expect!

4 Debugging Algorithms Try a slightly harder case –Two intersections apart –Step / breakpoint code in debugger again! –Make sure code behaving exactly as you expect

5 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?

6 Milestone 4: Courier Company

7 Problem Definition Return: low travel time path Starting and ending at some depot And reaching all N delivery intersections Given M courier truck depots and Given N delivery locations M = 3 here, all intersections N = 8 here, all intersections

8 vector of street segment ids Possible Solution

9 How? Idea: re-use our m3 path-finding algorithm! // Go from first depot to first delivery wholePath = find_path (depot[0], delivery[0]); // Complete other deliveries, in order they were given for (i = 0; i < N; i++) { path = find_path (delivery[i], delivery[i+1]); wholePath += path; } // Go back to the first depot to drop off the truck path = find_path (delivery[N-1], depot[0]); wholePath += path;

10 Lots of wasted travel! Possible Solution 0 1 2 0 1 2 3 4 5 6 7

11 Need to optimize delivery order Recall: More Logical Solution

12 Exhaustive Algorithm? Try all possible delivery orders Pick the one with lowest travel time How many combinations? –M truck depots, N delivery locations –Pick one of M starting locations –Then can pick one of N deliveries to do first –Then one of N-1 for the second –… (repeat until last delivery) –Then M places to drop off truck –M * N * (N-1) * (N-2) * … * 1 * M = M 2 N!

13 Exhaustive Algorithm? Say M = 6, N = 40 6 2 * 40! = 2.9 x 10 49 Invoke find_path () N+1 times to get path between each intersection Say find_path takes 0.1 s (very good!) 2.9 x 10 49 * 41 * 0.1 s = 1.2 x 10 50 s  3.77 x 10 42 years! Lifetime of universe: ~14 x 10 9 years!

14 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, …

15 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 –Showed 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


Download ppt "A few m3 tips. Speed Tuning 1.Algorithm 2.Data structures 3.Low level code string streetName1, streetName2; if (streetName1 != streetName2) {... int streetId1,"

Similar presentations


Ads by Google