23.06.2013 Aufrufe

finale Version des Vorlesungsskripts - ZIB

finale Version des Vorlesungsskripts - ZIB

finale Version des Vorlesungsskripts - ZIB

MEHR ANZEIGEN
WENIGER ANZEIGEN

Erfolgreiche ePaper selbst erstellen

Machen Sie aus Ihren PDF Publikationen ein blätterbares Flipbook mit unserer einzigartigen Google optimierten e-Paper Software.

5 Bäume und Wege<br />

/**************************************************************************<br />

* *<br />

* Prim’s Algorithm to Determine a Minimum Spanning Tree *<br />

* in a Complete Graph With n No<strong>des</strong> *<br />

* *<br />

* (G. Reinelt) *<br />

* *<br />

*------------------------------------------------------------------------*<br />

* *<br />

* Input: *<br />

* *<br />

* There are four ways to input the edge weights of the complete *<br />

* graph K_n. In any case we assume that first two numbers are given: *<br />

* *<br />

* n = number of no<strong>des</strong> *<br />

* mode = input mode *<br />

* *<br />

* Mode specifies the input mode for the edge weights. All edge weights *<br />

* have to be integers. *<br />

* *<br />

* Mode=0 : The full matrix of edge weights is given. The entries are *<br />

* stored row by row. The lower diagonal and the diagonal *<br />

* entries are ignored. *<br />

* *<br />

* Mode=1 : The matrix of edge weights is given as upper triangular *<br />

* matrix. The entries are stored row by row. *<br />

* *<br />

* Mode=2 : The matrix of edge weights is given as lower triangular *<br />

* matrix. The entries are stored row by row. *<br />

* *<br />

* Mode=3 : The edge weights are given in an edge list of the *<br />

* form: 1st endnode, 2nd endnode, edge weight. Edges which *<br />

* are not present are assumed to have ’infinite’ weight. *<br />

* The input is ended if the first endnode is less than 1. *<br />

* *<br />

**************************************************************************/<br />

CONST max_n = 100; { maximum number of no<strong>des</strong> }<br />

max_n2 = 4950; { max_n choose 2 = number of edges of K_n}<br />

{ to process larger graphs only max_n and<br />

max-n2 have to be changed }<br />

inf = maxint; { infinity }<br />

TYPE arrn2 = ARRAY[1..max_n2] OF integer;<br />

arrn = ARRAY[1..max_n] OF integer;<br />

VAR i, j,<br />

mode, { input mode of weights:<br />

0 : full matrix<br />

1 : upper triangular matrix<br />

2 : lower triangular matrix<br />

3 : edge list }<br />

min, { minimum distance }<br />

ind, { index of entering edge }<br />

newnode, { entering tree node }<br />

t1, t2, { entering tree edge }<br />

outno<strong>des</strong>, { number of no<strong>des</strong> not in tree }<br />

c,<br />

weight, { weight of tree }<br />

nchoose2,<br />

n : integer; { number of no<strong>des</strong> }<br />

w : arrn2; { vector of weights }<br />

dope, { dope vector for index calculations }<br />

dist, { shortest distances to non-tree no<strong>des</strong> }<br />

in_t, { in-tree node of shortest edge }<br />

out_t : arrn; { out-tree node of shortest edge }<br />

{ minimum tree is also stored in in_t & out_t}<br />

connected : boolean; { true input graph is connected? }<br />

86

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!