You are on page 1of 20

CO 250: Introduction to Optimization

Module 1: Formulations (Optimization on Graphs)

University
c of Waterloo 1 / 20
Shortest Paths

s a Columbia Ave

Albert St
Fisher Rd d

King St
c

Westmount Rd
Erb St
b f g

Victoria St
t

• Familiar problem: Starting at location s, we wish to travel to t.


What is the best (i.e., shortest) route?

• In the figure above, such a route is indicated in bold.

University
c of Waterloo 2 / 20
Shortest Paths

s a Columbia Ave

Albert St
Fisher Rd d

King St
c

Westmount Rd
Erb St
b f g

Victoria St
t

• Goal: Write the problem of finding the shortest route between s and
t as an integer program!
... How?

University
c of Waterloo 3 / 20
Graph Theory 101

Rephrasing this problem in the language of


graph theory helps!
y
A graph G consists of ...
x

• vertices u, w, . . . ∈ V z
(drawn as filled circles)
w t
• edges uw, wz, . . . ∈ E u

(drawn as lines connecting circles) v

Two vertices u and v are adjacent if


uv ∈ E. Vertices u and v are the
endpoints of edge uv ∈ E, and edge e ∈ E
is incident to u ∈ V if u is an endpoint of e.

University
c of Waterloo 4 / 20
Graphs – Why do we care?

Graphs are useful to


compactly model
many real-world
entities. For example:

• Modeling circuits
in chip design

• Social networks
Lampman, 2008 [Online Image]. Late Medieval Trade Routes. Wikimedia Commons.
http://commons.wikimedia.org/wiki/File:Late Medieval Trade Routes.jpg
• Trade networks

• .... and many


more!

University
c of Waterloo 5 / 20
The Map of Water Town

s a Columbia Ave

Albert St
Fisher Rd d

King St
c

Westmount Rd
Erb St
b f g

Victoria St
t

• We can think of the street map as a graph, G.

• Vertices: Road intersections

• Edges: Road segments connecting adjacent intersections

University
c of Waterloo 6 / 20
The Map of Water Town

s 650 a 830 600

90

80
450
630
900
700
d

590
610
5

250
41
325 c 830 600
325 b g
f
350

0
50

720

700
330

650 800 610


t

• Each edge e ∈ E is labelled by its length ce ≥ 0.

• We are looking for a path connecting s and t of smallest total length!

University
c of Waterloo 7 / 20
Paths
s 650 a 830 600

90

80
450
630
900

700
d

590
610
5

250
41
325 c 830 600
325 b g
f
350

0
50

720

700
330

650 800 610


t

An s, t-path in G = (V, E) is a sequence


v1 v2 , v2 v3 , v3 v4 , . . . , vk−2 vk−1 , vk−1 vk
where
• vi ∈ V and vi vi+1 ∈ E for all i, and

• v1 = s, vk = t, and vi 6= vj for all i 6= j.


(Without this, it is called an s, t-walk)
University
c of Waterloo 8 / 20
Paths

s 650 a
450

d
c(P ) = csa + cad + cdb + cbf + cf g + cgt
= 650 + 490 + 250 + 830 + 600 + 700
250

830 600
= 3520
b f g

700
P= sa, ad, db, bf, fg, gt

The length of a path P = v1 v2 , . . . , vk−1 vk is the sum of the lengths of


the edges on P : X
c(P ) := (ce : e ∈ P ).

University
c of Waterloo 9 / 20
s 650 a 830 600

90

80
450
630
900

700
d

590
610
5

250
41
325 c 830 600
325 b g
350 f

0
50

720

700
330

650 800 610


t

Shortest Path Problem

• Given: Graph G = (V, E), lengths ce ≥ 0 for all e ∈ E, s, t ∈ V

• Find: Minimum-length s, t-path P

Goal: Write an IP whose solutions are the shortest s, t-paths!


−→ Later!

University
c of Waterloo 10 / 20
Example: Matchings

University
c of Waterloo 11 / 20
WaterTech - Job Assignment

WaterTech has a collection of


Jobs
important jobs: Employees
10 20 30 40
J = {10 , 20 , 30 , 40 } 1 - 5 - 7
2 8 - 2 -
that it needs to handle urgently. 3 - 1 - -
4 8 - 3 -
It also has 4 employees:
Note: Some workers are not able to
E = {1, 2, 3, 4} handle certain jobs!
that need to handle these jobs.
Goal: Assign each worker to exactly
Employees have different skill-sets one task so that the total execution
and may take different amounts of time is smallest!
time to execute a job. −→ We will rephrase this in the
language of graphs

University
c of Waterloo 12 / 20
Matchings

1 1’
5 8
7 8
2 2’
Create a graph with one vertex for 4
each employee and job. 3 1 3’

Add an edge ij for i ∈ E and j ∈ J 3


4 4’
if employee i can handle job j.
E J
Let the cost cij of edge ij be the
amount of time needed by i to Jobs
complete j. Employees
10 20 30 40
1 - 5 - 7
2 8 - - 4
3 - 1 - -
4 8 - 3 -

University
c of Waterloo 13 / 20
Matchings

1 1’
5 8
7 8
2 2’
4
Definition 1
3 3’
A collection M ⊆ E is a matching if no two
edges ij, i0 j 0 ∈ M (ij 6= i0 j 0 ) share an 3
4 4’
endpoint; i.e., {i, j} ∩ {i0 , j 0 } = ∅.
E J
Examples

1. M = {140 , 210 , 320 , 430 } is a matching.

2. M = {140 , 320 , 410 , 430 } is not a


matching.

University
c of Waterloo 14 / 20
Matchings

The cost of a matching M is the 1 1’


5 8
sum of costs of its edges: 7 8
2 2’
4
X
c(M ) = (ce : e ∈ M )
3 1 3’

3
4 4’
e.g., M = {140 , 210 , 320 , 430 }
−→ c(M ) = 19 E J

Definition
A matching M is perfect if every E.g., matching in figure is perfect,
vertex v in the graph is incident to and this one is not!
an edge in M .

University
c of Waterloo 15 / 20
Restating the Assignment Problem

1 1’
Definition 7
5 8
8
A matching M is perfect if every vertex v in 2 2’
the graph is incident to an edge in M . 4
3 1 3’
Note: Perfect matchings correspond to 3
feasible assignments of workers to jobs! 4 4’

E.g., the matching shown corresponds to E J


the following assignment:

1 → 40 , 2 → 10 , 3 → 20 , and 4 → 30 Restatement of original


question:
whose execution time equals c(M ) = 19! Find a perfect matching M
in our graph of smallest cost.

University
c of Waterloo 16 / 20
A Little More Notation...

Notation: Use δ(v) to denote the set of 1 1’


5 8
edges incident to v; i.e., 7 8
2 2’
δ(v) = {e ∈ E : e = vu for some u ∈ V }. 4
3 1 3’

3
4 4’
Definition
E J
Given G = (V, E), M ⊆ E is a perfect
matching iff M ∩ δ(v) contains a single
edge for all v ∈ V .
Examples

• δ(2) = {210 , 240 }


• δ(30 ) = {430 }

University
c of Waterloo 17 / 20
An IP for Perfect Matchings

1 1’
Definition 7
5 8
8
Given G = (V, E), M ⊆ E is a perfect 2 2’
matching iff M ∩ δ(v) contains a single 4
edge for all v ∈ V . 3 1 3’

3
The IP will have a binary variable xe for 4 4’
every edge e ∈ E. Idea: E J

xe = 1 ↔ e ∈ M
Objective:
Constraints: For all v ∈ V , need X
X (ce xe : e ∈ E)
(xe : e ∈ δ(v)) = 1

University
c of Waterloo 18 / 20
An IP for Perfect Matchings

X
min (ce xe : e ∈ E) 2
X 1 5
s.t. (xe : e ∈ δ(v)) = 1 (v ∈ V )
4
x ≥ 0, x integer 1
3
3

min (5, 1, 3, 4)x 4

12 13 14 23
 
1 1 1 1 0
 
2
 1 0 0 1 x = 1

s.t.
3 0 1 0 1
 

4 0 0 1 0
x ≥ 0 integer

University
c of Waterloo 19 / 20
Optimization on Graphs

Recap
• Graphs consist of vertices V and edges E ... and are very useful in
modeling many practical problems.

• In particular, graphs can be used to model road networks, where


roads are edges and street intersections are vertices.

• In the shortest path problem, each edge e ∈ E has an associated


weight ce , and we are looking for a path connecting two specific
vertices of smallest total weight.

• A matching is a collection of edges, no two of which share an


endpoint. A perfect matching is a matching that covers all vertices
in V .

University
c of Waterloo 20 / 20

You might also like