De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

Shortest path with negative arc-costs allowed. Dijkstra?

Verwante presentaties


Presentatie over: "Shortest path with negative arc-costs allowed. Dijkstra?"— Transcript van de presentatie:

1 Shortest path with negative arc-costs allowed. Dijkstra?
" i>1: d[ i]:= ; S:= Æ Repeat u:=arg min {d[ i]| i Î N\S}, S:=S È {u} N\S: d[ i],d[u]+c[ u,i]} until S=N 1 2 3 4 5 6 7 8 9 14 13 16 12 -5 0,1 5,1 13,4 11,1 10,2 17,1 M,0 18,4 26,4 11 25,4 17 15 No! Better now Bellman-Ford:

2 Search(s: node); input A(i)’s of a (di)graph (N,A) [1]; node-labels pr(i)N; integer k(=0); output for j in component of s an s-j path begin  iN: pr(i):=0; pr(s):=s; LIST:=<s>; while LIST   do remove the first node from LIST, say i; k:=k+1; /* just counting the number of list-removals/scannings for all (i,j)A(i) with pr(j)=0 do pr(j):=i; put j on LIST; end; iN: pr(i)=0; compNr:=0; for all sN with pr(s)=0 do compNr:=compNr+1, Search(s) ; [1] if (N,A) is undirected then for any edge (i,j): (i,j)  A(i) and (j,i) A(j)

3 output topological numbering s.t. nr(i)<nr(j) for (i,j)
reNumbering input A(i)’s of acyclic digraph (N,A); node-labels nr(i), indgr(i)Z; integer k(=0); output topological numbering s.t. nr(i)<nr(j) for (i,j) begin  iN: nr(i):=0; indgr(i):=|inA(I)|; LIST:=<s: with indegree(s)=0>; while LIST   do remove a node from LIST, say i; k:=k+1; nr(i):=k; /* here is a purpose withNr(k):=i for all (i,j)A(i) do indgr(j):=indgr(j)-1; if indgr(j)=0 then put j on LIST; end; DPshortestpaths s:=withNr[1]; d(s):=0; for k:=2 to n do i:=withNr[k], (j,i) inA(i) : if d(j)+c(j,i) < d(i) then d(i):= d(j)+c(j,i) ; k:=0; reNumbering; if k=n then write('graph is acyclic');

4 Search(s: node) input A(i)’s of a (di)graph G=(N,A); labels pr(i)N{0}; output for j in component of s an s-j path begin  iN: pr(i):=0; pr(s):=s; LIST:=<s>; while LIST   do remove a node from LIST, say i; for all (i,j)A(i) with pr(j)=0 do pr(j):=i; put j on LIST; end;

5 BreadthFirst(s: node); /* scan first nodes first: fifo list management
input A(i)’s of a (di)graph G=(N,A); labels pr(i)N{0}, d(i) Z0; output for j in component of s an arc-minimal s-j path with d(j) arcs begin  iN: pr(i):=0, d(i):= ; pr(s):=s; LIST:=<s>; d(s):=0; while LIST   do remove the first node from LIST, say i; for all (i,j)A(i) with d(j)= do pr(j):=i, d(j):=d(i)+1; put j last on LIST; end;

6 Dijkstra(s: node); /* scan 'best' nodes first
input A(i)’s of a (di)graph G=(N,A); labels pr(i)N{0}, d(i) Z0; output for j in component of s a minimal-cost s-j path of cost d(j) begin  iN: pr(i):=0, d(i):= ; pr(s):=s; LIST:=<s>; d(s):=0; while LIST   do remove the best node from LIST, say i with minimal d(i); for all (i,j)A(i) with d(j)>d(i)+c(i,j) do pr(j):=i, d(j):=d(i)+c(i,j) put j on LIST (if not yet in) end;

7 Complexiteitstheorie: YES\NO recognition problems
TSP>=k Instance: netwerk (N,E,c) met c:EZ+ ; getal k Question: Is er een tour met lengte < k? Stel algoritme A lost op: yes-no versies TSP<=k in complexiteit tA(n) er is algoritme B voor TSPopt in complexiteit tB(n)= log(nC) · tA(n) algoritme B */ past bisectie toe met A U:=nC; */ C=max {cij| (i,j) in E} L:=0; */ U is boven- en L is ondergrens op z* Repeat k:=(U+L)/2; if algoritme A op TSP<=k returns YES then U:=k else L:=k ; /* opnieuw geldt: U is boven- en L is ondergrens op z* en het interval [L,U] is gehalveerd ! Until |U-L|< 1;

8 Voorbeelden YES\NO recognition problems
Graph-Connectedness Instance: graph G=(V, E) Question: Is G connected? Satisfiability (informeel) Instance: Boolean expression Question: Kan deze expressie de waarde ‘true’ aannemen (is it satisfiable) Langste Pad Instance: netwerk (N,E,c) met c:EZ+ ; s,t N; getal k Question: Is er een s-t pad P met lengte > k? ILP LP Instance: (c,A,b) resp. n-vector, mxn matrix en m-vector; getal k Question: Is max{cx| xRn met Ax<=b} > k? Zn Graph-Isomorfisme (informeel) Instance: graphs G1=(V1, E1) en G2=(V1, E1) Question: Zijn G1 en G2 hetzelfde?

9 Graph-Connectedness Instance: graph G=(V, E) Question: Is G connected? MST Instance: graph G=(V, E,c); number k; Question: Is there a tree T spanning V of total weight <=k? Steiner tree Instance: graph G=(V, E,c); subset of nodes K; number k; Question: Is there a tree spanning K of length <=k? UFL Instance: clients i=1,…,m with unit demand, facilities j=1,…n with one-time fixed charge opening costs fj; costs cij for delivering the unit of i from j; number k; Question: Can we satisfy all demands at a total cost <=k?

10 DEFINITIONS the time complexity (function) tA of algorithm A for problem P is tA(n)= max {#operaties of A on instance I | over IP with |I|=n} P is polynomial solvable - notation P - if  algorithm A with tA(n) of O(nq) for some qZ+ P is non-deterministically polynomial solvable -notation P- if all I P with answer YES have a ‘-certificate’, checkable in polytime EXAMPLES    (if P is polynomial solvable then P is in ) TSP: Instance: network (N,E,c) with number kR Question:  tour of length <=k? a -certificate is a set of n edges; polytime checkable: tour of length <= k coTSP ?! Instance: netwerk (N,E,c) with number kR Question: Are all tours of length > k? no -certificate?!

11 Instance: netwerk (N,E,c) met c:EZ+ ; getal k
TSP Instance: netwerk (N,E,c) met c:EZ+ ; getal k Question: Is er een tour met lengte < k? ShortestPath Instance: netwerk (N,E,c) met c:EZ+ ; s,t  N ; getal k Question: Is er een s-t path van lengte < k? TSP>=k Instance: netwerk (N,E,c) met c:EZ+ ; getal k Question: Is er een tour met lengte < k? 1 2 3 4 5 6 7 8 9 14 13 16 12 11 10 15

12 Transformatie-afbeelding van ITSP naar I':=(I)Kortste Pad -
1) Neem (N',E')=(N,E) met extra kopie n' van n ( dezelfde kanten als n); 2) c' verlaagt alle kantkosten met M 3) s=n en t=n'' 4 -M +c -M 2 ij 4) k'=-nM+k +16 9'' 7 9 1 5 Kortste 9 - 9'' pad bevat n -M +3 kanten - als mogelijk - 3 8 voor lengte - nM + tourlengte 6 I heeft TSP tour <= 63 desda I' heeft kortste 9-9'' pad <= -9M+63

13 probleem P1 is reduceerbaar tot P2 als  afbeelding :P1  P2 zo dat:
I yes-instantie van P1  (I) yes-instantie van P2 als ook:  polytime-algoritme, zeg A, met inputs IP1 en outputs (I)P2 dan P1 is 'polynomial‑reducable' tot P2 , notatie: P1  P2 Theorem Cook (1971): SAT is -compleet, i.e.: each problem P of  is polynomial reducable to SAT Corollary If SAT can be solved by some polynomial algorithm A, then all problems P are polynomial solvable (=) Proof: IP P(I)SAT AP O(| |r) alg. A O(| |q) yes/no algoritme in O(|I|qr) time voor I in P: doe eerst AP /* geeft I' in SAT van size O(| |r) doe dan A


Download ppt "Shortest path with negative arc-costs allowed. Dijkstra?"

Verwante presentaties


Ads door Google