CSC 173 Tues. Nov 19, 2002 ======================================= Project 5 due Monday Dec 9 Project 6 will be out before then! (a written assignment, ~one week) Quiz on Thursday ======================================= TSP - Traveling salesman Problem -------------------------------- Hamiltonian Cycle of shortest length Simple cycle that contains each vertex Finding an exact solution, naive solution: list all permutations of vertices find the cost of each, select the minimum Not tractable! running time ~ 2^n Triangle inequality - often, it is always cheapest to go directly from a place a to "a" place "c" rather than going through an intermediate stop "b" Going through "b" CANNOT be less expensive Cutting out an intermediate stop never increases the cost always true for graphs where distance is euclidian Approx TSP 1. form a MST 2. Let L be the list of vertices visited in a preorder walk of T 3. Let the TSP path be the vertices in the order L Assuming the graph satisfies triangle inequality, this approximation is never more than twice the cost of an optimal tour. Proof: Let H' be an optimal tour Let H be the tour returned by the above alg. We need to show that cost(H) <= 2*cost(H') Since we can obtain a spanning tree by deleting any edge from a tour, if T is a MST, then cost(T)<=cost(H') A full walk of T lists the vertices when they are first visited and also whenever they are returned to after a visit to a subtree. Call this walk W. This walk traverses every edge exactly twice, so cost(W) = 2*cost(T) because cost(T)<=cost(H') and cost(W) = 2*cost(T), it is implied that cost(W) <= 2*cost(H') so the cost of W is within a factor of 2 of the cost of optimal But W is not a tour, but by triangle inequality, we can delete a visit to any vertex and the cost will not increase. The resulting order after repeatedly removing the edges results in the same order as a preorder walk of the tree. Let H be the cycle corresponding to this preorder walk. H is the same cycle computed by our alg, so cost(H) <= cost(W) ----- Food for thought: if we drop the assumption of triangle inequality, good approximate tours cannot be found in polynomial time If we assume the vertices are points in the plane and cost of an edge is eudlicean distance, an optimal tour never crosses itself! ============== Maximum flow liquid running through pipes parts going through assembly lines information going through communication networks directed graphs, each edge has a capacity (max rate) e.g., 200 gallons per hour, 100 MB/s vertices, no collection (no buffering) sum of inputs must be equal to sum of outputs max flow - greatest rate at which material can be shipped from the source to the sink without violating any capacity constraints ex. cities, trucks shipping crates, edges are roads, labels on edges are number of crates per day along a road. do not care about how long it takes to get a crate to the destination find the max crates per day that can be shipped can convert multiple source, multiple sink to single source, single sink: add new source node s'. Create edges from s' to all original sources. Capacity on the link is infinite! Create a new sink node t'. Creat edges from all original sinks to t'. Capacity on the link is infinite! Ford-Fulkerson 1. start with 0 flow 2. find an augmenting path along which we can push flow 3. incrase flow along this path. 4. iterate until no more augmenting paths can be found This yields the maximum flow! residual networks given a flow network and a flow, the residual network consists of edges that can admit more net flow Augmenting path simple path from source to sink in the residual network residual capacity is the minimum edge weight Cuts of flow networks cut is a partition of vertices, put s and t in different partitions capacity of the cut is the difference between the sum of the forward edges and the sum of the backward edges value of a flow in a network is the net flow across any cut of the network Running time is use BFS or DFS to find augmenting path O(E) at must you must do this f times, where f is the resulting flow of the graph. Overall: O(Ef) good when f is small Show example for what happens if f is large and capacity of one link is very low. BFS will perform better than DFS if we use bfs to find the shortest path, the result is known as the Edmonds-Karp algorithm, and it runs in O(VE^2)