Announcements Assignment 4: Due Monday, April 5 at Midnight (due to university regulations). Submit...

Preview:

Citation preview

AnnouncementsAnnouncements

Assignment 4:Assignment 4:

• Due Monday, April 5 at Midnight (due to university regulations).

• Submit solutions to any 2 of the 4 problems.

• Responsible for understanding all 4 problems (related material may be on final exam).

Tutorial:Tutorial:

• Fri, Apr 2 A. Kolokolova 16:00-17:30 PSE 321

Special office hoursSpecial office hours (week prior to exam): MWF (week prior to exam): MWF 2-32-3

The Maximum The Maximum Network Flow Network Flow

ProblemProblem

ExampleExample

Flow(1)

Residual(1)

Flow(2)

Residual(2)

No more augmenting paths max flow attained.

The Basic Ford-Fulkerson The Basic Ford-Fulkerson Algorithm Algorithm

Multiple Sources NetworkMultiple Sources Network

•We have several sources and several targets. We have several sources and several targets. •Want to maximize the total flow from all sources to all targets. Want to maximize the total flow from all sources to all targets. •Reduce to max-flow by creating a supersource and a supersink:Reduce to max-flow by creating a supersource and a supersink:

Maximum Bipartite MatchingMaximum Bipartite Matching

A bipartite graph is a graph G=(V,E) in which V can be divided into two parts L and R such that every edge in E is between a vertex in L and a vertex in R.

e.g. vertices in L represent skilled workers and vertices in R represent jobs. An edge connects workers to jobs they can perform.

A matching in a graph is a subset M of E, such that for all vertices v in V, at most one edge of M is incident on v.

A A maximummaximum matchingmatching is a matching of maximum is a matching of maximum cardinality. cardinality.

not maximum maximum

A Maximum MatchingA Maximum Matching

No matching of No matching of cardinality 4, cardinality 4, because only one of because only one of v and u can be v and u can be matched. matched.

In the workers-jobs In the workers-jobs example a max-example a max-matching provides matching provides work for as many work for as many people as possible. people as possible.

v

u

Solving the Maximum Solving the Maximum Bipartite Matching ProblemBipartite Matching Problem

•Reduce an instance of the maximum Reduce an instance of the maximum bipartite matching problem on graph G to bipartite matching problem on graph G to an instance of the max-flow problem on a an instance of the max-flow problem on a corresponding flow networkcorresponding flow network G’. G’.

•Solve using Ford-Fulkerson method.Solve using Ford-Fulkerson method.

Corresponding Flow NetworkCorresponding Flow Network

•To form the corresponding flow network To form the corresponding flow network G' of the bipartite graph G:G' of the bipartite graph G:• Add a source vertex s and edges from s to L.• Direct the edges in E from L to R. • Add a target vertex t and edges from R to t. • Assign a capacity of 1 to all edges.

•ClaimClaim: max-flow in G’ corresponds to a : max-flow in G’ corresponds to a max-bipartite-matching on G.max-bipartite-matching on G.

ExampleExample

min cut

|M| = 3 max flow = 3

Lemma (CLRS 26.10)Lemma (CLRS 26.10)

( , ) be a bipartite graph with vertex partition Let .G V E V L R

( , ) be its corresponding fl ow netwLet ork. G V E

is a matching in ,I f M G

there is an integer-valued fl ow in with value | |then | | .f G f M

, is an integer-valued fConvers low in ife y ,l f G

there is a matching in with cardinality | |t .n |e |h M G M f

Why can’t we just say max |f| = Why can’t we just say max |f| = max |M|?max |M|?

Problem:Problem: we haven’t shown that f(u,v) is necessarily we haven’t shown that f(u,v) is necessarily integer-valued for all (u,v) when f is a max flow. integer-valued for all (u,v) when f is a max flow.

It follows from the lemma that It follows from the lemma that

max |M| = max [ integral flow], max |M| = max [ integral flow],

but we also need but we also need

max [integral flow] = max |f|max [integral flow] = max |f|

Integrality Theorem (CLRS Integrality Theorem (CLRS 26.11)26.11)

If the capacity function c takes on only integral If the capacity function c takes on only integral values, then:values, then:

1. The maximum flow f produced by the Ford-Fulkerson method has the property that |f| is integer-valued.

2. For all vertices u and v the value f(u,v) of the flow is an integer.

So So |M| = max [integral flow] = max |f||M| = max [integral flow] = max |f|

Conclusion Conclusion

Network flow algorithms allow us to Network flow algorithms allow us to find the maximum bipartite find the maximum bipartite matching fairly easily.matching fairly easily.

Similar techniques are applicable in Similar techniques are applicable in other combinatorial design other combinatorial design problems. problems.

ExampleExample

In a department there are n courses and In a department there are n courses and m instructors.m instructors.Every instructor has a list of courses he or Every instructor has a list of courses he or she can teach. she can teach. Every instructor can teach at most 3 Every instructor can teach at most 3 courses during a year. courses during a year.

The goal: find an allocation of courses to The goal: find an allocation of courses to the instructors subject to these the instructors subject to these constraints.constraints.

Two solutions using network Two solutions using network flowsflows

Solution 1: convert the problem into Solution 1: convert the problem into a bipartite matching problem.a bipartite matching problem.

Solution 2: convert the problem into Solution 2: convert the problem into a flow problem directly. a flow problem directly.

A more complicated problemA more complicated problem

•There are m student groups on campus.There are m student groups on campus.•We would like to form a committee with a president, We would like to form a committee with a president, 3 vice-pres, and 10 members at large.3 vice-pres, and 10 members at large.•The committee is formed by representatives of the The committee is formed by representatives of the groups. groups.

•Can add conditions:Can add conditions:• The first group can be represented by at most 2 members,

any other group can be represented by at most one. • The representative of the third group cannot be the

president.

•Reduce to network flows!Reduce to network flows!

Reducibility and Reducibility and NP-CompletenessNP-Completeness

Computational Complexity Computational Complexity TheoryTheory

Computational Complexity Theory Computational Complexity Theory is is the study of how much of a given the study of how much of a given resource (such as time, space, resource (such as time, space, parallelism, randomness, algebraic parallelism, randomness, algebraic operations, communication, or quantum operations, communication, or quantum steps) is required to solve important steps) is required to solve important problems.problems.

WORST-CASE TIMEWORST-CASE TIME

We say that a program takes We say that a program takes worst-case time T(n), if some worst-case time T(n), if some input of size n takes T(n) steps, input of size n takes T(n) steps, and no input of size n takes and no input of size n takes longer.longer.

The input size is measured in The input size is measured in bits, unless stated otherwise. bits, unless stated otherwise.

Some ExamplesSome Examples

A Graph Named “Gadget”A Graph Named “Gadget”

K-COLORINGK-COLORING

A A k-coloringk-coloring of a graph is an of a graph is an assignment of one color to each vertex assignment of one color to each vertex such that:such that:• No more than k colors are used• No two adjacent vertices receive the

same color

A graph is called A graph is called k-colorablek-colorable iff it has a iff it has a k-coloringk-coloring

A A CCRRAAYYOOLLAA Question! Question!Is Gadget 2-colorable?Is Gadget 2-colorable?

No: it contains a triangle!

Is Gadget 3-colorable?Is Gadget 3-colorable?

A A CCRRAAYYOOLLAA Question! Question!

Yes!

Given a graph G, what is Given a graph G, what is a fast algorithm to decide a fast algorithm to decide

if it can be 2-colored?if it can be 2-colored?

2 2 CCRRAAYYOOLLAASS

PERSPIRATION; BRUTE FORCE: Try out all 2n ways of 2 coloring G.

Given a graph G, what is Given a graph G, what is a fast algorithm to decide a fast algorithm to decide

if it can be 3-colored?if it can be 3-colored?

3 3 CCRRAAYYOOLLAASS

? ? ? ? ? ? ? ?

Let’s consider a completely Let’s consider a completely different problem.different problem.

K-CLIQUESK-CLIQUES

A K-clique is a set of K nodes with all A K-clique is a set of K nodes with all k(K-1)/2 possible edges between k(K-1)/2 possible edges between them.them.

This graph contains a 4-This graph contains a 4-cliqueclique

Given an n-node graph G Given an n-node graph G and a number k, how can and a number k, how can

you decide if G contains a k-you decide if G contains a k-clique? clique?

PERSPIRATION: Try out all n choose PERSPIRATION: Try out all n choose k possible locations for the k cliquek possible locations for the k clique

INSPIRATION: INSPIRATION:

? ? ? ? ? ? ? ?

OK, how about a slightly OK, how about a slightly different problem?different problem?

INDEPENDENT SETINDEPENDENT SET

An An independent setindependent set is a set of is a set of vertices with no edges between vertices with no edges between them.them.

This graph contains an independent set of size

3.

Given an n-node graph G Given an n-node graph G and a number k, how can and a number k, how can

you decide if G contains an you decide if G contains an independent set of size k?independent set of size k?

PERSPIRATION: Try out all n-choose-PERSPIRATION: Try out all n-choose-k possible locations for independent k possible locations for independent setset

INSPIRATION: INSPIRATION: ? ? ? ? ? ? ? ?

One more completely One more completely different problemdifferent problem

Combinational CircuitsCombinational Circuits

AND, OR, NOT, gates wired together AND, OR, NOT, gates wired together with no feedback allowed (acyclic).with no feedback allowed (acyclic).

Logic GatesLogic Gates

Not And Or

Example CircuitExample Circuit

CIRCUIT-SATISFIABILITYCIRCUIT-SATISFIABILITY(decision version)(decision version)

Given a circuit with n-inputs Given a circuit with n-inputs and one output, is there a and one output, is there a way to assign 0-1 values to way to assign 0-1 values to the input wires so that the the input wires so that the output value is 1 (true)?output value is 1 (true)?

CIRCUIT-SATISFIABILITYCIRCUIT-SATISFIABILITY(search version)(search version)

Given a circuit with n-inputs Given a circuit with n-inputs and one output, find an and one output, find an assignment of 0-1 values to assignment of 0-1 values to the input wires so that the the input wires so that the output value is 1 (true), or output value is 1 (true), or determine that no such determine that no such assignment exists.assignment exists.

Satisfiable Circuit ExampleSatisfiable Circuit Example

Satisfiable?Satisfiable?

No!

Given a circuit, is it Given a circuit, is it satisfiable?satisfiable?

PERSPIRATION: Try out all 2PERSPIRATION: Try out all 2nn assignmentsassignments

INSPIRATION: INSPIRATION:

? ? ? ? ? ? ? ?

We have seen 4 problems: coloring, clique,

independent set, and circuit SAT.

They all have a common story: A large space of possibilities only a tiny fraction of which satisfy the constraints. Brute

force takes too long, and no feasible algorithm is

known.

CLIQUE / INDEPENDENT SETCLIQUE / INDEPENDENT SET

Two problems that Two problems that are cosmetically are cosmetically different, but different, but substantially the substantially the samesame

Complement Of GComplement Of G

Given a graph G, let GGiven a graph G, let G**, the , the complementcomplement of G, be the of G, be the graph obtained by the rule graph obtained by the rule that two nodes in Gthat two nodes in G** are are connected if and only if the connected if and only if the corresponding nodes of G are corresponding nodes of G are not connected not connected

ReductionReduction

• Suppose you have a method for solving the k-clique problem.

• How could it be used to solve the independent set problem?

Or what if you have an Or what if you have an Oracle?Oracle?

or·a·cleor·a·cle

Pronunciation:Pronunciation: 'or-&-k&l, 'är- 'or-&-k&l, 'är-

Function:Function: noun noun

Etymology:Etymology: Middle English, from Middle French, from Latin Middle English, from Middle French, from Latin oraculum, from orare to speakoraculum, from orare to speak

1 a : a person (as a priestess of ancient Greece) through 1 a : a person (as a priestess of ancient Greece) through whom a deity is believed to speak whom a deity is believed to speak

2 a : a person giving wise or authoritative decisions or 2 a : a person giving wise or authoritative decisions or opinionsopinions

Let G be an n-node graph.

GIVEN:Clique Oracle

<G,k>

BUILD:Indep.

SetOracle

<G*, k>

Let G be an n-node graph.

GIVEN: Indep.

Set Oracle

<G,k>

BUILD: Clique

Oracle

<G*, k>

Thus, we can quickly reduce clique problem to an independent set

problem and vice versa.

There is a fast method for one if and only if

there is a fast method for the other.

Given an oracle for circuit SAT, how can you quickly

solve 3-colorability?

VVnn(X,Y)(X,Y)

Let VLet Vn n be a circuit that takes an n-node be a circuit that takes an n-node graph X and an assignment Y of colors to graph X and an assignment Y of colors to these nodes, and these nodes, and verifiesverifies that Y is a valid that Y is a valid 3-colouring of X. i.e., V3-colouring of X. i.e., Vnn(X,Y)=1 iff Y is a 3-(X,Y)=1 iff Y is a 3-colouring of X.colouring of X.

X is expressed as an n-choose-2 bit X is expressed as an n-choose-2 bit sequence. Y is expressed as a 2n bit sequence. Y is expressed as a 2n bit sequence. sequence.

Given n, we can construct VGiven n, we can construct Vn n in time O(nin time O(n22).).

Let G be an n-node graph.

GIVEN:SAT

Oracle

G

BUILD:3-

colorOracle

Vn(G,Y)

Given an oracle for circuit SAT, how can you quickly

solve k-clique?

VVn,kn,k(X,Y)(X,Y)

Let VLet Vn n be a circuit that takes an n-node be a circuit that takes an n-node graph X and a subset of nodes Y, and graph X and a subset of nodes Y, and verifiesverifies that Y is a k-clique X. I.e., that Y is a k-clique X. I.e., VVnn(X,Y)=1 iff Y is a k-clique of X.(X,Y)=1 iff Y is a k-clique of X.

X is expressed as an n choose 2 bit X is expressed as an n choose 2 bit sequence. Y is expressed as an n bit sequence. Y is expressed as an n bit sequence. sequence.

Given n, we can construct VGiven n, we can construct Vn,k n,k in time O(nin time O(n22).).

Let G be an n-node graph.

GIVEN:SAT

Oracle

<G,k>

BUILD:CliqueOracle

Vn,k(G,Y)

Given an oracle for 3-colorability, how

can you quickly solve

circuit SAT?

Reducing Circuit-SAT to 3-Reducing Circuit-SAT to 3-ColouringColouring

Goal: map circuit to graph that is 3-Goal: map circuit to graph that is 3-colourable only if circuit is colourable only if circuit is satisfiable.satisfiable.

How do we represent a logic gate as How do we represent a logic gate as a 3-colouring problem?a 3-colouring problem?

X Y

Output

ExampleExample

X and Y and Output are boolean variables in circuit.

Without loss of generality, map truth values to colours, e.g.

0 red

1 green

Add base colour for encoding purposes, e.g. yellow.

X Y

Output

ExampleExample

Note that in a valid 3-colouring, this node cannot have the same colour as X, Y or Output.

Thus, without loss of generality, we can assign it the base colour, yellow.

X Y

Output

ExampleExample

Now suppose we fix this node to represent false.

X Y

Output

ExampleExampleF

Now suppose we fix this node to represent false.

ExampleExampleT F

X Y

Output

Now build a truth table for (X, Y, Output).

What if X=Y=0?

ExampleExampleT F

X Y

Output

Now build a truth table for (X, Y, Output).

What if X=Y=0?

ExampleExampleT F

X Y

Output

Now build a truth table for (X, Y, Output).

What if X=Y=0?

ExampleExampleT F

X Y

Output

Now build a truth table for (X, Y, Output).

What if X=Y=0?

ExampleExampleT F

X Y

Output

Thus (X,Y)=0Output=0

ExampleExampleT F

X Y

Output

Conversely, what if Output=0?

ExampleExampleT F

X Y

Output

Conversely, what if Output=0?

ExampleExampleT F

X Y

Output

Conversely, what if Output=0?

ExampleExampleT F

X Y

Output

Conversely, what if Output=0?

ExampleExampleT F

X Y

Output

Thus Output=0X=Y=0.

ExampleExampleT F

X Y

Output

XX YY OutpOutputut

FF FF FF

FF TT TT

TT FF TT

TT TT TT

What type of gate is this?

An OR gate!

T F

X What type of gate is this?

A NOT gate!

Output

OR

OR

NOT

x y z

xy

z

OR

OR

NOT

x y z

xy

z

Satisfiability of this circuit = 3-colorability of this graph

Let C be an n-input circuit.

GIVEN:3-colorOracle

C

BUILD:SAT

Oracle

Graph composed of gadgets that mimic

the gates in C

Formal StatementFormal Statement

There is a polynomial-time function f There is a polynomial-time function f such that:such that:

C is satisfiable <-> f(C) is 3 C is satisfiable <-> f(C) is 3 colorablecolorable

4 Problems All Equivalent4 Problems All Equivalent

If you can solve one quickly then you If you can solve one quickly then you can solve them all quickly:can solve them all quickly:

Circuit-SATCircuit-SAT

CliqueClique

Independent SetIndependent Set

3 Colorability3 Colorability

That’s All, Folks!That’s All, Folks!

Recommended