Math 5490 Network Flows Lecture 2: Network Representations
Stephen Billups
University of Colorado at Denver
Math 5490Network Flows – p.1/18 Outline
Notation and definitions.
Network Representations.
Assignment Readings: Read Sections 2.3-2.5 Reminder: HWK 1: Exercises 1.1, 1.2, 1.5, 1.7 (Due Next Tuesday (January 24))
Math 5490Network Flows – p.2/18 Notation and Definitions
1 2
4 5
3
6
1. What is the in-degree of node 2?
2. What is the out-degree of node 4?
3. What is the arc adjacency list for node 3?
4. What is the node adjacency list for node 5?
Math 5490Network Flows – p.3/18 Notation and Definitions (cont)
1. What is the difference between a directed graph and a network?
2. What is the difference between a loop and cycle?
3. What is the difference between a walk, a path, and a cycle?
4. How many arcs are in a tree with n nodes?
5. What is the difference between a tree and a spanning tree?
6. Can an out-tree be undirected?
7. How do connected and acyclic relate to graphs and trees?
Math 5490Network Flows – p.4/18 Default Assumptions
Unless otherwise stated, we will make the following assumptions in this course:
Graphs and networks are directed.
No multiarcs or loops.
n = number of nodes.
m = number of arcs.
Math 5490Network Flows – p.5/18 Network Representations
Node-node adjacency matrix.
Adjacency lists.
Forward and reverse star representations.
Math 5490Network Flows – p.6/18 Node-arc incidence matrix
1. Rows correspond to nodes, columns to arcs:
2. The column for arc (i, j) has exactly two non-zero entries: +1 in row i and −1 in row j.
(1,2) (2,3) (2,4) (3,4) (3,5) (4,1) (4,2) (4,5) 1 1 0 0 0 0 −1 0 0 2 3 2 −1 1 1 0 0 0 −1 0 6 7 6 − 7 3 6 0 1 0 1 1 0 0 0 7 6 7 4 6 0 0 −1 −1 0 1 1 1 7 6 7 6 7 5 4 0 0 0 0 −1 0 0 −1 5
(c_ij, u_ij) i j
(7,10) 2 3
(2,5) (9,50) (3,8) (4,20) (5,25) 1 5
(11,30) (4,50) 4
Figure 1
Math 5490Network Flows – p.7/18 Exercise
Draw the graph corresponding to the following node-arc incidence matrix:
1 0 −1 0 0 1 2 3 0 0 1 0 1 0 6 7 6 7 6 0 1 0 −1 −1 0 7 6 7 6 7 4 −1 −1 0 1 0 −1 5
Math 5490Network Flows – p.8/18 Application to linear programming formulation
Recall that a minimum cost flow problem has the following linear programming formulation:
min P(i,j)∈A cij xij
subject to P{j| (i,j)∈A } xij − P{j| (j,i)∈A } xji = b(i) for all i ∈ N. (node balance: flow out - flow in = supply)
lij ≤ xij ≤ uij for all (i, j) ∈ A.
Using the node-arc-incidence matrix, we can write down the LP formulation more compactly as follows:
min cT x subject to N x = b l ≤ x ≤ u
where N is the node-arc-incidence matrix, and c, x, l, and u are vectors with components
cij , xij , lij and uij , respectively, for (i, j) ∈ A in some fixed order, and b = (b1, b2, . . . , n).
Math 5490Network Flows – p.9/18 Space-efficiency
1. Node-arc incidence matrix wastes a lot of space because most of the entries are zeros
Math 5490Network Flows – p.10/18 Answer: 1 2 3 4 5 1 0 0 0 1 0 2 3 2 0 0 0 1 0 6 7 6 7 3 6 0 1 0 0 0 7 6 7 4 6 1 1 1 0 0 7 6 7 6 7 5 4 0 0 1 1 0 5
Node-node adjacency matrix
1. Rows and columns both correspond to nodes.
2. A ’1’ in position (i, j) indicates an arc going from node i to node j.
Question: What is the node-node adjacency matrix for the graph shown in Fig. 1.
Math 5490Network Flows – p.11/18 Node-node adjacency matrix
1. Rows and columns both correspond to nodes.
2. A ’1’ in position (i, j) indicates an arc going from node i to node j.
Question: What is the node-node adjacency matrix for the graph shown in Fig. 1. Answer: 1 2 3 4 5 1 0 0 0 1 0 2 3 2 0 0 0 1 0 6 7 6 7 3 6 0 1 0 0 0 7 6 7 4 6 1 1 1 0 0 7 6 7 6 7 5 4 0 0 1 1 0 5
Math 5490Network Flows – p.11/18 Questions
1. If a graph has n nodes and m arcs, how many 1’s are in the adjacency matrix? How many 0’s?
2. In comparison, how many 1’s are in the node-arc incidence matrix? How many 0’s?
3. Suppose we wanted to identify all of arcs emanating from node i. How would you do that with each of these data structures? How much time would it take?
Math 5490Network Flows – p.12/18 Comment on efficiency
1. Node-node adjacency matrix is space and time efficient only if network is dense.
Math 5490Network Flows – p.13/18 Adjacency Lists
1. For each node i, the arc adjacency list A(i) is stored as a linked list.
2. Each record in the linked list corresponds to an arc (i, j), and stores the following info: (a) The head of the arc j (Why not the tail also?).
(b) The cost cij .
(c) The capacity bounds lij , uij . (d) A pointer to the next record in the linked list.
3. An array of pointers is used to store a pointer to the first record of each linked list.
Math 5490Network Flows – p.14/18 Example
Figure 2 illustrates the adjacency list representation of the network shown in Figure 1.
i j c_ij u_ij
2 2 0 1 5
2 3 7 10 4 4 20 0
3 4 5 25 5 9 50 0
4 1 11 30 2 3 8 5 4 50 0
5
Figure 2: Adjacency list representation
Math 5490Network Flows – p.15/18 Forward Star Representation
Stores same information as adjacency list, but using arrays instead of linked lists.
1. Stores arc information in 4 (or 3 or 5) arrays: tail, head, cost and capacity. Each array has length m (the number of arcs).
2. (Important) The arcs must be ordered according in order of increasing tail nodes.
3. An additional array called point of length n (the number of nodes) is used to tell us where to look for arcs emanating from each node. Specifically, if node i has an arc emanating from it, then point(i) is the index of the first arc emanating from node i. If node i has no arcs emanating from it, then point(i) is set equal to point(i + 1).
Math 5490Network Flows – p.16/18 Example
The forward star representation for our example is as follows:
tail head cost capacity 1 1 2 2 5 point 2 2 3 7 10 1 1 3 2 4 4 20 2 2 4 3 4 5 25 3 4 5 3 5 9 50 4 6 6 4 1 11 30 5 9 7 4 2 3 8 8 4 5 4 50
Math 5490Network Flows – p.17/18 Comparisons
1. Forward star representation requires less memory.
2. Forward star easier to implement, unless the language supports pointers (like C).
3. More difficult to add and delete arcs in forward star. (time is proportional to m, whereas adding or deleting arcs with adjacency lists requires only constant time).
Math 5490Network Flows – p.18/18