Heuristics: Minimal Spanning Tree 3: Unterschied zwischen den Versionen

Aus Operations-Research-Wiki
Wechseln zu: Navigation, Suche
[unmarkierte Version][unmarkierte Version]
(Example)
(Kruskal)
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 59: Zeile 59:
  
 
Basis of the Kruskal algorithm is a coherent, undirected and loop free graph
 
Basis of the Kruskal algorithm is a coherent, undirected and loop free graph
<nowiki> Graph G=[</nowiki>V,E,c] with n accounts and m edges.
+
<nowiki> G=[</nowiki>V,E,c] with n accounts and m edges.
  
 
===Process===
 
===Process===
  
  
1: Sort and number up all edges ki of G in the row k1, k2,..., km with monotonic increasing importance c(ki), so that c(k1)&lt;= c(k2)&lt;=...&lt;=c(km).
+
1: Sort and number up all edges ki of the graph in the row k1, k2,..., km with monotonic increasing importance c(ki), so that c(k1)&lt;= c(k2)&lt;=...&lt;=c(km).
  
 
2: Repeat for all j, with j=1,...,m:
 
2: Repeat for all j, with j=1,...,m:
Zeile 73: Zeile 73:
 
3: Stop the process when E equals exactly n-1 edges.  
 
3: Stop the process when E equals exactly n-1 edges.  
  
<nowiki>The result of this process is the minimal spanning tree T= [V.E] </nowiki>
+
<nowiki>The result of this process is the minimal spanning tree. </nowiki>
  
 
===Example===
 
===Example===
Zeile 89: Zeile 89:
 
[[image:Kruskal1.jpg]]
 
[[image:Kruskal1.jpg]]
  
Step 2: Count of edges '''1 < n'''
+
Step 2: Count of edges '''1 < n - 1'''
  
 
[[image:Kruskal2.jpg]]
 
[[image:Kruskal2.jpg]]
  
Step 3: Count of edges '''2 < n'''
+
Step 3: Count of edges '''2 < n - 1'''
  
 
[[image:Kruskal3.jpg]]
 
[[image:Kruskal3.jpg]]
  
Step 4:Count of edges '''3 < n'''
+
Step 4:Count of edges '''3 < n - 1'''
  
 
[[image:Kruskal4.jpg]]
 
[[image:Kruskal4.jpg]]
  
Step 5: Count of edges '''4 < n'''
+
Step 5: Count of edges '''4 < n - 1'''
  
 
[[image:Kruskal5.jpg]]
 
[[image:Kruskal5.jpg]]
  
Step 6: Count of edges '''5 < n'''
+
Step 6: Count of edges '''5 < n - 1'''
  
 
[[image:Kruskal6.jpg]]
 
[[image:Kruskal6.jpg]]
  
Step 7: Count of edges '''6 < n'''
+
Step 7: Count of edges '''6 < n - 1'''
  
 
[[image:Kruskal7.jpg]]
 
[[image:Kruskal7.jpg]]
Zeile 121: Zeile 121:
 
[[image:Kruskal9.jpg]]
 
[[image:Kruskal9.jpg]]
  
Step 10: Count of edges '''7 = n-1'''. The optimal solution is reached.
+
Step 10: Count of edges '''7 = n - 1'''. The optimal solution is reached.
  
 
[[image:Kruskal10.jpg]]
 
[[image:Kruskal10.jpg]]

Aktuelle Version vom 1. Juli 2013, 13:34 Uhr

Minimal Spanning Tree

General Information

The goal of Minimal Spanning Trees is to link all nodes directly or indirectly to minimize the length of all edges. This also implies the minimization of the costs. A direct link signifies the existence of an edge between two nodes. In contrast, an indirect link signifies the existence of a path, which links two nodes over another or more nodes. To find the optimal solution nodes have to get linked directly step by step.

Prim

The Prim is an algorithm that always leads to the optimal solution and therefore the Prim is one opportunity of creating a minimal spanning tree.

Process

1. Choose a random node and link it to the nearest other node. In this case nearest means the node with the shortest distance or the lowest costs etc.

2. Next, choose the unlinked node, which is the closest to the already linked ones.

3. Repeat Step 2 until all nodes are linked.

Note: If there are multiple options with the shortest distance choose the link randomly.

Example

Initial Problem:

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 1: Choose randomly node "2" and connect it to the closest node "1".

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 2: Choose the unlinked node, which is closest to the already linked nodes. In this case there are two options. Either node "5" or node "3". Choose randomly one of those options (here: node "5").

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 3: Repeat this with the next unlinked node, which is closes to the already linked nodes (here: node "3").

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 4: Repeat this with the next unlinked node, which is closes to the already linked nodes (here: node "6").

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 5: Repeat this with the next unlinked node, which is closes to the already linked nodes (here: node "7").

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 6: Repeat this with the next unlinked node, which is closes to the already linked nodes (here: node "2").

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 7: Repeat this with the next unlinked node, which is closes to the already linked nodes (here: node "8").

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

All nodes are linked. There is no cycle. The solution is optimal.

Kruskal

Basis of the Kruskal algorithm is a coherent, undirected and loop free graph G=[V,E,c] with n accounts and m edges.

Process

1: Sort and number up all edges ki of the graph in the row k1, k2,..., km with monotonic increasing importance c(ki), so that c(k1)<= c(k2)<=...<=c(km).

2: Repeat for all j, with j=1,...,m:

Choose the edge kj and check if the result of including kj in the graph is a circle. If no circle occurs, set E:=E'U{kj}.

3: Stop the process when E equals exactly n-1 edges.

The result of this process is the minimal spanning tree.

Example

Initial Problem: Count of nodes n = 8

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Sort the edges:

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 1:

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 2: Count of edges 1 < n - 1

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 3: Count of edges 2 < n - 1

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 4:Count of edges 3 < n - 1

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 5: Count of edges 4 < n - 1

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 6: Count of edges 5 < n - 1

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 7: Count of edges 6 < n - 1

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 8: Adding edge k7 leads to a cycle, therefore k7 is not added.

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 9: Adding edge k8 leads to a cycle, therefore k8 is not added.

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Step 10: Count of edges 7 = n - 1. The optimal solution is reached.

Fehler beim Erstellen des Vorschaubildes: Die Miniaturansicht konnte nicht am vorgesehenen Ort gespeichert werden

Sources

http://en.wikipedia.org/wiki/Minimum_spanning_tree

http://delphiforfun.org/programs/Math_Topics/MinimalSpanningTrees.htm

http://compprog.wordpress.com/2007/11/09/minimal-spanning-trees-prims-algorithm/