Upload
mouniga-ve
View
218
Download
0
Embed Size (px)
Citation preview
8/7/2019 activity1[1]
1/9
The activity selection problem
Given a set S = {1, 2, . . . , n} of activities that wish to use aresource, which can be used only by one activity at the time.
Activity i has a start time si and a finishing time fi, fi > si.Activities i and j are comparable if [sifi) (sjfj] = .The goal is to maximize the set of mutually compatible activities.Notice, F = {A|A S, A is compatible } and f(A) = |A|.
http://find/http://goback/http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-8/7/2019 activity1[1]
2/9
Example.
Activity (A): 1 2 3 4 5 6 7 8Start (s): 3 2 2 1 8 6 4 7Finish (f): 5 5 3 5 9 9 5 8
4
41 5 6 7 82 3 9 10
1 5
2 6
3 7 8
http://find/http://goback/http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-8/7/2019 activity1[1]
3/9
The Activity Selection problem.
Given a set A of activities, wish to maximize the number ofcompatible activities.
Activity selection A
Sort A by increasing order of fiS := {1}j := 1
from i = 2 to n doif si > fjS := S {i} and j := i
return S.
A : 3 1 2 7 8 5 6f : 3 5 5 5 8 9 9SOL: 3 1 8 5
4
1 5
2 6
3 7 8
http://find/http://goback/http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-8/7/2019 activity1[1]
4/9
TheoremThe previous algorithm produces an optimal solution to the activity
selection problem.
Proof.Given A = {1, . . . , n} sorted by finishing time, we must show thereis an optimal solution that begins with activity 1. Lest
S = {k, . . . , m} be a solution. If k = 1 done.Otherwise, define B = (S {k}) {1}. As f1 fk the activities inB are disjoint. As |B| = |S|, B is also an optimal solution.If S is an optimal solution to A, then S = A {1} is an optimalsolution for A = {i A|si fi}.Therefore, after each greedy choice we are left with an optimizationproblem of the same form as the original. Induction on the numberof choices, the gredy strategy produces an optimal solution
http://find/http://goback/http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-8/7/2019 activity1[1]
5/9
The satisfiability problem (SAT)
A boolean variable x can take values 0,1. A litteral is a is aboolean variable x or x. A clause is a disjunction of litterals.An instance of SAT: X = {x1, . . . , xn}, a set of clauses {Ci}
mi=1.
and a boolen formula F in Conjuntive Normal Form (CNF). The
problem consists in obtaining a truth assignment of X:( : X {0, 1}) s.t.
(F) =m
i=1
(Ci) = 1.
Notice: for F = 1, i, (Ci) = 1 x Ci, (x) = 1.
http://find/http://goback/http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-8/7/2019 activity1[1]
6/9
Horn formulae
A SAT instance, where each Ci has at most one positive literal.Example:
(x1x2)(x1x3x4)(x1x2x3x4)(x1)(x1x2x4)(x3)(x1x2x
Recall that clauses with one positive literal can be rewritten asimplications:
(x y z w) (y z w) x
So the previous example can be rewritten as(x1 x2), (x1 x3 x4), (x2 x3 x4 x1), ( x1),(x1 x2 x4), (x3), (x1 x2 x4).
http://find/http://goback/http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-8/7/2019 activity1[1]
7/9
Give boolean formulaes A and B, A B is false iff A = 1 andB = 0 . Therefore, if we have a defined from a clause with nonegations in a Horn formulae, for the implication to be false, allvariables at the left must be 1 and the variable to the right mustbe 0
(x2 x3 x4 x1)
This fact can be used to develop a greedy algorithm for Hornformulae
http://find/http://goback/http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-8/7/2019 activity1[1]
8/9
Linear time Greedy algorithm for Horn formulae
Given a Horn formulae F:
Greedy Horn F
for all i [n] do T(xi) = 0
while there is false implication yy := 1
if all clauses with negatives are 1return F = 1
else F = 0.
http://find/http://goback/http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-8/7/2019 activity1[1]
9/9
Example:
(x1 x2), (x1 x3 x4), (x2 x3 x4 x1), ( x1),(x1 x2 x4), (x3), (x1 x2 x4)Greedy-Horn will make (x1) = (x2) = (x3) = (x4)
then (x1) = 1 because ( x1),then (x2) = 1 because (x1 x2),then (x4) = 1 because (x1 x2 x4),But then (x1 x2 x4) = 1.Therefore, the original formula has no truth assignment.
http://find/http://goback/http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-