
























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























































































© cR. J. LeVeque
Acknowledgments: These notes are based on many quarters of teaching Math 381. The original notes were compiled by Randy LeVeque in Applied Math at UW. Tim Chartier and Anne Greenbaum contributed significantly to the current version in 2001-2002. Sara Billey contributed to the manuscript in the fall of 2004. Tim Chartier made further contributions as he taught a version of this course at Davidson College in the 2005. Jim Burke contributed a portion of the chapter on linear programming. We thank them for their efforts. Since this document is still evolving, we appreciate the input of our readers in improving the text and its content.
- Math 381 Notes — University of Washington — Winter Math 381 Notes — University of Washington — Winter 2008
In a January, 1998 article “Most Ferries Short Of Life Rafts – Is It A Titanic Problem Or A Reasonable Cost-Control Measure?” the Seattle Times announced that Washington State Ferries, which service the Puget Sound area (see Figure 1.1), were not carrying enough lifeboats for all passengers. In fact, as we will see there is a reason for this decision. The ferries do carry enough life vests to make up the difference. However, the Washington ferries traverse cold waters. As such, it would be better to carry more lifeboats since your chances of surviving are better in a lifeboat than in cold water. However, lifeboats take up much more space and so there is a tradeoff — the capacity of the ferries would be greatly reduced if they had to carry enough lifeboats for everyone. Suppose the XYZ Boat-builders have come to us with the following problem. They are designing a new ferry boat and want to determine the number of lifeboats and life vests to equip it with. They give us the following information:
How many of each should they install?
One might go through the following steps in determining a solution:
x 1 = number of vests x 2 = number of boats
1.2 The goals of 381 3
Figure 1.2: Balancing the load of ferries is important as the boats carry great weights. (Picture taken from http://www.wsdot.wa.gov/ferries/.)
this to XYZ. They respond: “Well sure, the 85m^3 figure was just an approximation. We can easily find another 0.2m^3 if it means we can fit in two more boats.
This simple example illustrates some of the issues involved in mathematical modeling:
The goals of Math 381 are the following:
4 Introduction to Modeling
involved in dealing with real data and complex problems, where we can often only hope to model some small piece of the total problem?
Many modeling problems are better solved with continuous models, in which case different mathe- matical techniques are used, for example differential equations. Such models are studied in AMath
6 Introduction to Modeling
Math 381 Notes — University of Washington — Winter 2008
Imagine you are planning a trip around the United States based on a map showing distances between various cities and points of interest. The map has a labeled point for each city and lines connecting nearby cities are labeled by the distance between the two cities. One might ask a question like “How should we drive if we want to visit every city on the map?” This is an example of a network flow problem from graph theory. More generally, a graph is a collection of vertices or nodes which are connected by edges. A graph is connected if there is a way to get from any vertex to any other vertex by following edges. Figure 2.1 shows a few types of (connected) graphs that arise in many different applications:
Graph Directed graph Network Tree
2
3
6
4
12
3
(^46)
2
8
5 10
Figure 2.1: Some common graphs.
The vertices and edges of a graph might represent any number of different things, depending on the application. For example, the vertices in a digraph might represent legal positions in a game, with an arrow from Vertex A to Vertex B if you can go from Position A to Position B by a single legal move. Or the vertices could represent individuals in a hierarchical organization, with an edge from A to B if Person A reports to Person B. These and other examples are discussed in [Rob76].
2.2 The traveling salesman problem 9
as an addition or multiplication. These are called floating point operations since scientific notation is usually used to represent a large range of values on the computer. For computations of the sort mathematicians, engineers and scientists do, a useful measure of a computer’s speed is the number of floating point operations per second, called flops. Machine speed is often measured in megaflops (millions of floating point operations per second). A 500 MHz machine might do about 40 megaflops. Supercomputer speeds are often measured in gigaflops (billions of flops) or teraflops (trillions of flops). Returning to the traveling salesman problem, note that to compute the length of a single route requires about N additions, adding up the length between each pair of cities on the route, as well as more work to keep track of which route to examine next, which route is shortest, etc. Let’s not worry too much about the exact cost, but suppose that we are working on a machine that can examine ten million routes per second. Then solving the 10-city TSP would take about 1/3 of a second. Not bad. But already with 20 cities it would be difficult to find the answer using this brute force approach. We now have about 2. 4 × 1018 routes to examine, and at a rate of 10 million per second this will take
For an N-city TSP with N sufficiently small, we could solve by enumeration. This requires some algorithm for systematically checking every possibility. Figure 2.2 shows one way to think about enu- merating all the possible routes for the 4-city TSP. In the rightmost column is an enumeration of all 24 routes in the lexicographic order, so called because this is the order that would be obtained by putting the 24 strings representing different routes into alphabetical order. Note that the 3! = 6 routes starting with A come first, then the 6 routes starting with B, and so on. Within each set, the routes are grouped by which city comes second, ordered from “lowest” to “highest” in lexicographic ordering.
Instead of evaluating the cost of every path appearing in the tree of Figure 2.2, one might be able to rule out some paths early if their cost exceeds that of the best path discovered so far. Consider, for example, the network in Figure 2.3. One might first try a greedy algorithm that takes the shortest edge to a new city at each step. This leads to the path O-ADCB-O, which has a total cost of 15. After discovering this, any path in Figure 2. that uses edge BD (or, equivalently, DB) can be eliminated, since the cost of that edge alone is 16. By continuing to check the other paths that start with O-A, one finds that the path O-ABCD-O has a cost of only 14. Examining next the paths that begin with O-D, and discarding any partial paths whose cost exceeds 14, one finds that O-DABC-O costs only 11, and this enables one to eliminate even more possibilities. Paths beginning with O-C and O-B still must be checked, but as soon as the cost of a partial path exceeds 11, that branch of the tree can be eliminated from further consideration. This type of algorithm is sometimes called a branch and bound algorithm. The key idea is to obtain some sort of bound on how good the shortest path within a given subtree could possibly be and, if a less costly path has already been identified, to prune away those branches of the tree, thereby reducing the required computation. If we are unlucky then we might not be able to prune much of the tree and in the worst-case scenario we have to examine the entire tree anyway, which is no improvement in running time. However in practice a good branch and bound algorithm will typically be much faster than pure enumeration, and problems are solved this way which would otherwise be intractable.
10 Graph Theory and Network Flows
ABCD ABDC ACBD ACDB
BDCA
BDAC
BCDA
BCAD
BADC
BACD
ADBC ADCB
ABC ACB ACD ADB ADC
ABD AB AC AD
A
BAC BAD BCA BCD BDA BDC
BA BC BD
CABD CADB CBAD CBDA CDAB CDBA
DABC DACB DBAC DBCA DCAB DCBA
CAB CAD CBA CBD CDA CDB
DAB CAC DBA DBC DCA DCB
CA CB
DB DB
DA
CD
C
B
O
D
Figure 2.2: Decision tree for enumerating all possible routes in a traveling salesman problem starting from City O and visiting four other cities A, B, C, and D. The right column shows an enumeration of all permutations of the 4 cities, in lexicographic order.
Seattle =
Figure 2.3: A traveling salesman network starting from Seattle and visiting four other cities A, B, C, and D.
12 Graph Theory and Network Flows
Given two English words with the same number of letters, how could we determine the shortest word ladder between them? (Assuming there is one, or determine that none exists.) This can be set up as a network flow problem. Suppose we are considering N -letter words, then we could in principle construct a graph where the vertices consist of all N -letter words in the English language. We draw an edge from one vertex to another if those two words are simple mutations of each other in which only a single letter has been changed. A word ladder then corresponds to a path through this graph from one word to the other. In fact this graph (with nearly 6000 vertices) has been constructed for N = 5 by Don Knuth and is available on the web (see the pointer from the class webpage). Word ladders and algorithms for manipulating these graphs are discussed at length in [Knu93], which describes a general platform for combinatorial computing. Finding the shortest word ladder is equivalent to the shortest-path problem through a network if we assign every edge in the graph the weight 1. Given a network and two specific vertices, how do we find the shortest path between them? For small networks this is easy to do by trial and error, particularly if the graph is drawn in such a way that the physical distance between the vertices roughly corresponds to the weight of the edge, as is the case for a map. But the weights may have nothing to do with physical distance and at any rate if there are thousands or millions of vertices and edges it may be impossible to even draw the graph.
One approach to solving a shortest-path problem would be to enumerate all possible paths between the start and end vertices, compute the length of each path, and choose the shortest. To enumerate all paths, we could build a “decision tree” similar to what was illustrated in Figure 2.2 for the TSP. The problem with this approach is that for a graph with N vertices, there may be very many possible paths to choose between. How many? In the worst case, there would be an edge connecting each vertex with each of the N − 1 other vertices. In this case we could visit any or all of the other vertices on the way between the start and finish, and the number of possible paths would be exponential in N , just as for the TSP. The set of all possible paths could be searched more efficiently using a branch and bound algorithm, similar to that described for the TSP. However, for this problem there turn out to be much more efficient algorithms which are guaranteed to give the answer with relatively little work.
Dijkstra’s algorithm is a systematic procedure for finding the shortest path between any two vertices. Actually this algorithm solves the problem by embedding it into what appears to be a harder problem, that of finding the shortest route to all other vertices from a given vertex. The set of all shortest routes is built up in N steps, by finding the closest node in Step 1, the next closest node in Step 2, and so on. By the end we know the best route to every other node and in particular to the destination node. Each step requires examining the distance from the node that was “solved” in the previous step to all unsolved nodes which can be reached from this node. This requires examining at most N − 1 edges, so the work required is O(N ) in each of the N steps, and hence the total work is O(N 2 ). To implement it on a computer for a large network requires some suitable data structure for storing the network with information about which vertices are connected to one another and the weight of each edge. One way to represent a network or directed network on a computer is with a matrix. The rows
2.5 Minimum spanning trees 13
and columns correspond to the nodes of the network and the (i, j) entry of the matrix is the weight on the edge from node i to node j (or, if there is no edge from i to j, that entry can be set to ∞). A matrix representation of the network in Figure 2.3 is:
O A B C D − − − − − O | 0 2 5 4 3 A | 2 0 2 9 1 B | 5 2 0 1 16 C | 4 9 1 0 6 D | 3 1 16 6 0
We’ll go through some simple examples of Dijkstra’s algorithm in class. It is described in many books, e.g., [HL95] and [Rob84]. A writing assignment will be to produce your own description of this algorithm.
Another type of problem that arises in many applications is to connect a collection of vertices at the lowest possible cost. Examples include highway construction and telephone line installation: the vertices represent cities and the roads or phone lines correspond to edges constructed so that there is some path between every pair of vertices. In graph theoretic terms, this is accomplished via a minimal cost spanning tree. Recall that a tree is a graph that is connected and has no circuits. If a group of vertices is connected by edges that do contain a circuit, then it is not hard to see that one (or more) of the edges can be removed without destroying the connectedness of the graph. This is illustrated in Figure 2.4. Since each edge has a nonnegative cost associated with it, clearly the least expensive way to connect the vertices will be via a graph with no circuits (i.e., a spanning tree).
Figure 2.4: Graphs with circuits and corresponding spanning trees
In a spanning tree, the number of edges is always one less than the number of vertices: e = N − 1. Each graph in Figure 2.4 has N = 5 vertices, and the two trees have e = 4 edges. There are two well- known algorithms for finding a minimal cost spanning tree in a connected network: Kruskal’s algorithm and Prim’s algorithm.
Kruskal’s algorithm begins by sorting the edges of the graph in order of increasing cost. For the network shown in Figure 2.5 this order is: {AB}(8), {CD}(10), {CE}(12), {DE}(22), {BC}(53), {BE}(54), {AD}(63), and {AE}(70). Each edge is then considered in turn and, if it does not form a circuit with edges already in the good set, it is added to the good set. This is continued until the good set has N − 1 edges. Since the good set has no circuits, it is a tree. If all edges have been examined and the good set still does not have N − 1 edges, it means that the original graph must not have been connected, and this fact can be reported to the user. The first edges added to the tree from Figure 2.5 are {AB},
2.6 Eulerian closed chains 15
While there is no known polynomial time algorithm for solving the Euclidean TSP, there is an easy way to find a route whose cost is within a factor of two of the optimal: Construct a minimum spanning tree. Starting at the origin node, move along edges of the minimum spanning tree until you can go no further. Then backtrack along these edges until you reach a point from which you can traverse a new edge to visit a new node or until all of the nodes have been visited and you can return to the origin. This is illustrated in Figure 2.6, where the minimum spanning tree is marked and the suggested path is ODOABCBAO. The total cost of this path is twice the cost of the minimum spanning tree. Another possible path is OABCBAODO, which also traverses each edge of the minimum spanning tree twice.
5
8
7
9 C
5
7
13
11
12
10
O
A B
D
Figure 2.6: Euclidean TSP network with minimum spanning tree. Path OD-O-ABC-BA-O costs twice as much as the minimum spanning tree, and tour ODABCO is within a factor of two of optimal.
The path constructed in this way is not a legitimate tour for the TSP, since it visits some nodes more than once. But because the weights satisfy the triangle inequality, any path between nodes that visits other nodes along the way that have already been visited can be replaced by a direct route between the given nodes, and the cost will be no greater. Thus one arrives at a tour whose cost is at most twice that of the minimum spanning tree. For the example in Figure 2.6, this tour is ODABCO and has a total cost of 40. Had we chosen the other path, OABCBAODO, it would have been replaced by the tour OABCDO, which has a total cost of 34 (and turns out to be the optimal tour for this problem). Since the minimal cost spanning tree is the lowest cost set of edges that connects all of the vertices, any traveling salesman tour that visits all of the vertices must cost at least as much as the minimal cost spanning tree: 25 for our example. This gives a lower bound on the cost of the optimal tour, while the tour derived above, whose cost is within a factor of two of this value, provides an upper bound. This information can be used within a branch and bound algorithm to hone in on the actual optimal tour.
Still another type of graph thoeretic problem that arises in many applications is that of finding an Eulerian closed chain: A path that starts at a given node, traverses each edge of the graph exactly once, and returns to the starting point. This problem might arise, for example, in scheduling snowplows or street sweepers. If the edges of the graph represent streets, then the object is to plow or sweep each street once but, if possible, not to backtrack over streets that have already been serviced. This type of problem is also popular in many mathematical games. In fact, it is said that graph theory was invented by Euler in the process of settling the famous K¨onigsberg bridge problem. The situation is pictured in Figure 2.7. There are seven bridges and the question is whether one can start at a particular point, cross each bridge exactly once, and return to the starting point. If you try it for a while, you can probably convince yourself that the answer is “No”. To see this in a more formal way, let the land masses in the problem be represented by nodes and the bridges by edges in a multigraph (a graph that can have more than one edge between a pair of nodes). This multigraph is shown in Figure 2.8. Note that if we start at a particular node in the multigraph and travel along one edge to a different node, then we must leave that node along a different edge. If there is only one edge through the node then this will not be possible. Moreover, if there are three or five or
16 Graph Theory and Network Flows
D
A
B
C
Figure 2.7: The bridges of K¨onigsberg
D
A
B
C
Figure 2.8: Multigraph representing the bridges of K¨onigsberg
any odd number of edges through that node, then in order to traverse all of these edges, we will have to enter then leave the node until there is only one unused edge remaining. But at that point we are stuck, because we must enter the node in order to use that edge, but then we cannot leave. The same holds for the starting node. If there is only one edge through it, then we can leave but never return, and if there are an odd number of edges through it, then we can leave and return a certain number of times but eventually we will be at the starting node with one unused edge remaining to traverse. The degree of a vertex is defined as the number of edges through that vertex. Using the above sort of reasoning Euler proved the following:
Theorem (Euler[1736]). A multigraph G has an Eulerian closed chain if and only if it is connected up to isolated vertices and every vertex of G has even degree.
The condition that the graph be connected up to isolated vertices just means that there is no edge that cannot be reached at all. There is no Eulerian closed chain in Figure 2.8 since, for example, vertex D has degree 3. (In fact, all of the vertices in this multigraph have odd degree.) A good way to establish the sufficiency of Euler’s theorem is by describing an algorithm for computing an Eulerian closed chain in an even connected multigraph. Consider, for example, the multigraph in Figure 2.9. Start at any vertex and travel to other vertices along unused edges until you can go no further. For example, we might start at A, go to B, C, D, back to B, and then to A. For each of the vertices visited we use an even number of edges — one to enter and one to leave — each time we visit the vertex, so that the number of unused edges through each vertex remains even. Moreover, once we leave the initial vertex, it is the only one with an odd number of unused edges through it; for every other vertex, if we enter we can also leave. Therefore our path can end only back at the original vertex. At this point, we may not have traversed all of the edges of the multigraph, so go to any vertex that has some unused edges through it: vertex C, for example, and repeat. Take one of the unused edges to a new vertex and again continue until you can go no further. For example, we might go from C to E to F to G to E to C. This path can be combined with our previous one to form the chain: