finale Version des Vorlesungsskripts - ZIB
finale Version des Vorlesungsskripts - ZIB finale Version des Vorlesungsskripts - ZIB
inp, { input file } outp : text; { output file } BEGIN {MAIN PROGRAM} {====== Input of complete graph =====} reset(inp); rewrite(outp); {- number of nodes -} writeln(outp,’Enter number of nodes:’); read(inp,n); IF (nmax_n) THEN BEGIN writeln(outp,’Number of nodes too large or not positive!’); HALT; END; {- initialize dope vector -} nchoose2 := (n * (n-1)) DIV 2; FOR i:=1 TO nchoose2 DO w[i] := inf; dope[1] := -1; FOR i:=2 TO n DO dope[i] := dope[i-1] + n - i; {- input mode -} writeln(outp,’Enter input mode:’); read(inp,mode); {- edge weights -} CASE mode OF 0 : {* full matrix *} BEGIN FOR i:=1 TO n DO FOR j:=1 TO n DO BEGIN read(inp, c); IF i0) DO BEGIN IF (in) OR (jn) THEN BEGIN writeln(outp,’Input error, node out of range!’); HALT; END; IF i
5 Bäume und Wege THEN w[dope[i]+j] := c ELSE w[dope[j]+i] := c; read(inp, i, j, c); END; END; ELSE: {* invalid mode *} BEGIN writeln(outp,’Invalid input mode!’); HALT; END; END;{OF CASE} {====== Initialization ======} connected := true; outnodes := n-1; weight := 0; FOR i:=1 TO outnodes DO BEGIN in_t[i] := 1; out_t[i] := i+1; dist[i] := w[i]; END; {====== Prim’s Algorithm ======} WHILE (outnodes > 1) AND connected DO BEGIN {- determine entering node -} min := inf; ind := 0; FOR i:=1 TO outnodes DO IF dist[i] < min THEN BEGIN min := dist[i]; ind := i; END; IF ind = 0 THEN connected := false ELSE BEGIN {- augment tree -} weight := weight + min; newnode := out_t[ind]; t1 := in_t[ind]; t2 := out_t[ind]; c := dist[ind]; in_t[ind] := in_t[outnodes]; out_t[ind] := out_t[outnodes]; dist[ind] := dist[outnodes]; in_t[outnodes] := t1; out_t[outnodes] := t2; dist[outnodes] := c; outnodes := outnodes - 1; {- update dist[] and in_t[] -} FOR i:=1 TO outnodes DO BEGIN IF newnode < out_t[i] THEN c := w[dope[newnode]+out_t[i]] ELSE c := w[dope[out_t[i]]+newnode]; IF c < dist[i] THEN BEGIN in_t[i] := newnode; dist[i] := c; END; END; END; END; {- insert the last edge -} 88
- Seite 42 und 43: 3 Diskrete Optimierungsprobleme Die
- Seite 44 und 45: 3.2 Klassische Fragestellungen der
- Seite 46 und 47: (a) (b) 3.2 Klassische Fragestellun
- Seite 48 und 49: 3.3 Graphentheoretische Optimierung
- Seite 50 und 51: 3.3 Graphentheoretische Optimierung
- Seite 52 und 53: 3.3 Graphentheoretische Optimierung
- Seite 54 und 55: 3.3 Graphentheoretische Optimierung
- Seite 56 und 57: • Schaltkreisentwurf • Standort
- Seite 58 und 59: 3.3 Graphentheoretische Optimierung
- Seite 60 und 61: 3.3 Graphentheoretische Optimierung
- Seite 62 und 63: Literaturverzeichnis T. L. Gertzen
- Seite 64 und 65: 4 Komplexitätstheorie und Speicher
- Seite 66 und 67: 4.1 Probleme, Komplexitätsmaße, L
- Seite 68 und 69: 4.2 Die Klassen P und N P, N P-Voll
- Seite 70 und 71: 4.2 Die Klassen P und N P, N P-Voll
- Seite 72 und 73: 4.2 Die Klassen P und N P, N P-Voll
- Seite 74 und 75: 4 4.3 Datenstrukturen zur Speicheru
- Seite 76 und 77: 4.3 Datenstrukturen zur Speicherung
- Seite 78 und 79: 4.3 Datenstrukturen zur Speicherung
- Seite 80: R. E. Tarjan. Data structures and n
- Seite 83 und 84: 5 Bäume und Wege Der Beweis ist et
- Seite 85 und 86: 5 Bäume und Wege (2) =⇒ (3) Ist
- Seite 87 und 88: 5 Bäume und Wege Haben wir einen A
- Seite 89 und 90: 5 Bäume und Wege Falls T \ {ei} zu
- Seite 91: 5 Bäume und Wege /****************
- Seite 95 und 96: 5 Bäume und Wege Wie Beispiel (5.1
- Seite 97 und 98: 5 Bäume und Wege (a) F. Schiller.
- Seite 99 und 100: 5 Bäume und Wege DISTk(u) die Län
- Seite 101 und 102: 5 Bäume und Wege VOR(3) = 2. Wir s
- Seite 103 und 104: 5 Bäume und Wege 4. DO u = 1 TO v
- Seite 105 und 106: 5 Bäume und Wege Sei nun P ein kü
- Seite 107 und 108: 5 Bäume und Wege (b) D enthält ge
- Seite 109 und 110: 5 Bäume und Wege C2 C1 s 4 C3 C4 2
- Seite 111 und 112: 5 Bäume und Wege ders vorgehen: z.
- Seite 113 und 114: 5 Bäume und Wege ist ein System vo
- Seite 115 und 116: 5 Bäume und Wege heißt (allgemein
- Seite 117 und 118: 5 Bäume und Wege Um lästige Trivi
- Seite 119 und 120: Literaturverzeichnis A. Goldberg. P
- Seite 121 und 122: 6 Maximale Flüsse in Netzwerken Al
- Seite 123 und 124: 6 Maximale Flüsse in Netzwerken de
- Seite 125 und 126: 6 Maximale Flüsse in Netzwerken s
- Seite 127 und 128: 6 Maximale Flüsse in Netzwerken W
- Seite 129 und 130: 6 Maximale Flüsse in Netzwerken Da
- Seite 131 und 132: 6 Maximale Flüsse in Netzwerken s
- Seite 133 und 134: Literaturverzeichnis L. R. Ford, Jr
- Seite 135 und 136: 7 Flüsse mit minimalen Kosten Ein
- Seite 137 und 138: 7 Flüsse mit minimalen Kosten Dami
- Seite 139 und 140: 7 Flüsse mit minimalen Kosten Dami
- Seite 141 und 142: 7 Flüsse mit minimalen Kosten 2. K
5 Bäume und Wege<br />
THEN w[dope[i]+j] := c<br />
ELSE w[dope[j]+i] := c;<br />
read(inp, i, j, c);<br />
END;<br />
END;<br />
ELSE: {* invalid mode *}<br />
BEGIN<br />
writeln(outp,’Invalid input mode!’);<br />
HALT;<br />
END;<br />
END;{OF CASE}<br />
{====== Initialization ======}<br />
connected := true;<br />
outno<strong>des</strong> := n-1;<br />
weight := 0;<br />
FOR i:=1 TO outno<strong>des</strong> DO<br />
BEGIN<br />
in_t[i] := 1;<br />
out_t[i] := i+1;<br />
dist[i] := w[i];<br />
END;<br />
{====== Prim’s Algorithm ======}<br />
WHILE (outno<strong>des</strong> > 1) AND connected DO<br />
BEGIN<br />
{- determine entering node -}<br />
min := inf;<br />
ind := 0;<br />
FOR i:=1 TO outno<strong>des</strong> DO<br />
IF dist[i] < min<br />
THEN BEGIN<br />
min := dist[i];<br />
ind := i;<br />
END;<br />
IF ind = 0<br />
THEN connected := false<br />
ELSE BEGIN<br />
{- augment tree -}<br />
weight := weight + min;<br />
newnode := out_t[ind];<br />
t1 := in_t[ind];<br />
t2 := out_t[ind];<br />
c := dist[ind];<br />
in_t[ind] := in_t[outno<strong>des</strong>];<br />
out_t[ind] := out_t[outno<strong>des</strong>];<br />
dist[ind] := dist[outno<strong>des</strong>];<br />
in_t[outno<strong>des</strong>] := t1;<br />
out_t[outno<strong>des</strong>] := t2;<br />
dist[outno<strong>des</strong>] := c;<br />
outno<strong>des</strong> := outno<strong>des</strong> - 1;<br />
{- update dist[] and in_t[] -}<br />
FOR i:=1 TO outno<strong>des</strong> DO<br />
BEGIN<br />
IF newnode < out_t[i]<br />
THEN c := w[dope[newnode]+out_t[i]]<br />
ELSE c := w[dope[out_t[i]]+newnode];<br />
IF c < dist[i]<br />
THEN BEGIN<br />
in_t[i] := newnode;<br />
dist[i] := c;<br />
END;<br />
END;<br />
END;<br />
END;<br />
{- insert the last edge -}<br />
88