Beispiel 4 neu
This commit is contained in:
parent
1f67dde5c4
commit
e020e34d94
@ -185,49 +185,56 @@ public class ExampleGraphs {
|
||||
|
||||
|
||||
|
||||
public DirectedGraph<VertexMarking, EdgeMarking> example4() {
|
||||
public static DirectedGraph<VertexMarking, EdgeMarking> example4() {
|
||||
|
||||
/*
|
||||
* Beispiel 4 zeigt einen gerichteten Graphen mit deutschen Städten als Knoten und
|
||||
* zufällig gewichteten Kanten.
|
||||
/**
|
||||
* Erstellt einen Beispielgraphen (Beispiel 4), der sich ideal für die Demonstration der Funktionsweise
|
||||
* des Dijkstra- und A*-Algorithmus eignet. Der Graph enthält eine Vielzahl von Knoten, die durch
|
||||
* gewichtete Kanten verbunden sind. Dies ermöglicht es, den kürzesten Weg von einem Startknoten zu einem
|
||||
* Zielknoten effizient zu berechnen und die Unterschiede zwischen den beiden Algorithmen in der
|
||||
* Pfadfindung zu veranschaulichen.
|
||||
*
|
||||
* Startknoten: A
|
||||
* Zielknoten: H
|
||||
*
|
||||
*/
|
||||
|
||||
DirectedGraph<VertexMarking, EdgeMarking> example4 = new DirectedGraph<>();
|
||||
|
||||
// Städte als Knoten
|
||||
MarkedVertex Berlin = new MarkedVertex<>(100, 100, "Berlin", null, null);
|
||||
MarkedVertex Hamburg = new MarkedVertex<>(200, 100, "Hamburg", null, null);
|
||||
MarkedVertex München = new MarkedVertex<>(300, 100, "München", null, null);
|
||||
MarkedVertex Köln = new MarkedVertex<>(100, 200, "Köln", null, null);
|
||||
MarkedVertex Frankfurt = new MarkedVertex<>(200, 200, "Frankfurt", null, null);
|
||||
MarkedVertex Stuttgart = new MarkedVertex<>(300, 200, "Stuttgart", null, null);
|
||||
MarkedVertex Leipzig = new MarkedVertex<>(100, 300, "Leipzig", null, null);
|
||||
MarkedVertex Dresden = new MarkedVertex<>(200, 300, "Dresden", null, null);
|
||||
MarkedVertex Hannover = new MarkedVertex<>(300, 300, "Hannover", null, null);
|
||||
// Erstellung der Knoten mit Koordinaten
|
||||
MarkedVertex<VertexMarking> A = new MarkedVertex<>(50, 250, "A", null, null);
|
||||
MarkedVertex<VertexMarking> B = new MarkedVertex<>(150, 150, "B", null, null);
|
||||
MarkedVertex<VertexMarking> C = new MarkedVertex<>(150, 350, "C", null, null);
|
||||
MarkedVertex<VertexMarking> D = new MarkedVertex<>(250, 100, "D", null, null);
|
||||
MarkedVertex<VertexMarking> E = new MarkedVertex<>(250, 250, "E", null, null);
|
||||
MarkedVertex<VertexMarking> F = new MarkedVertex<>(350, 200, "F", null, null);
|
||||
MarkedVertex<VertexMarking> G = new MarkedVertex<>(450, 300, "G", null, null);
|
||||
MarkedVertex<VertexMarking> H = new MarkedVertex<>(450, 100, "H", null, null);
|
||||
|
||||
// Kanten mit zufälligen Gewichtungen
|
||||
example4.addVertex(Berlin);
|
||||
example4.addVertex(Hamburg);
|
||||
example4.addVertex(München);
|
||||
example4.addVertex(Köln);
|
||||
example4.addVertex(Frankfurt);
|
||||
example4.addVertex(Stuttgart);
|
||||
example4.addVertex(Leipzig);
|
||||
example4.addVertex(Dresden);
|
||||
example4.addVertex(Hannover);
|
||||
// Hinzufügen der Knoten zum Graphen
|
||||
example4.addVertex(A);
|
||||
example4.addVertex(B);
|
||||
example4.addVertex(C);
|
||||
example4.addVertex(D);
|
||||
example4.addVertex(E);
|
||||
example4.addVertex(F);
|
||||
example4.addVertex(G);
|
||||
example4.addVertex(H);
|
||||
|
||||
example4.addEdge(new MarkedEdge<>("Berlin-Hamburg", Berlin, Hamburg, new EdgeWeightMarking(1)));
|
||||
example4.addEdge(new MarkedEdge<>("Berlin-München", Berlin, München, new EdgeWeightMarking(2)));
|
||||
example4.addEdge(new MarkedEdge<>("Berlin-Köln", Berlin, Köln, new EdgeWeightMarking(3)));
|
||||
example4.addEdge(new MarkedEdge<>("Hamburg-Frankfurt", Hamburg, Frankfurt, new EdgeWeightMarking(2)));
|
||||
example4.addEdge(new MarkedEdge<>("Hamburg-Leipzig", Hamburg, Leipzig, new EdgeWeightMarking(3)));
|
||||
example4.addEdge(new MarkedEdge<>("München-Stuttgart", München, Stuttgart, new EdgeWeightMarking(1)));
|
||||
example4.addEdge(new MarkedEdge<>("München-Dresden", München, Dresden, new EdgeWeightMarking(2)));
|
||||
example4.addEdge(new MarkedEdge<>("Köln-Hannover", Köln, Hannover, new EdgeWeightMarking(3)));
|
||||
example4.addEdge(new MarkedEdge<>("Frankfurt-Stuttgart", Frankfurt, Stuttgart, new EdgeWeightMarking(1)));
|
||||
example4.addEdge(new MarkedEdge<>("Stuttgart-Leipzig", Stuttgart, Leipzig, new EdgeWeightMarking(2)));
|
||||
example4.addEdge(new MarkedEdge<>("Leipzig-Dresden", Leipzig, Dresden, new EdgeWeightMarking(1)));
|
||||
example4.addEdge(new MarkedEdge<>("Dresden-Hannover", Dresden, Hannover, new EdgeWeightMarking(3)));
|
||||
// Erstellung der Kanten mit Gewichtungen
|
||||
example4.addEdge(new MarkedEdge<>("AB", A, B, new EdgeWeightMarking(4)));
|
||||
example4.addEdge(new MarkedEdge<>("AC", A, C, new EdgeWeightMarking(2)));
|
||||
example4.addEdge(new MarkedEdge<>("BC", B, C, new EdgeWeightMarking(5)));
|
||||
example4.addEdge(new MarkedEdge<>("BD", B, D, new EdgeWeightMarking(10)));
|
||||
example4.addEdge(new MarkedEdge<>("CD", C, D, new EdgeWeightMarking(3)));
|
||||
example4.addEdge(new MarkedEdge<>("CE", C, E, new EdgeWeightMarking(7)));
|
||||
example4.addEdge(new MarkedEdge<>("DE", D, E, new EdgeWeightMarking(2)));
|
||||
example4.addEdge(new MarkedEdge<>("DF", D, F, new EdgeWeightMarking(2)));
|
||||
example4.addEdge(new MarkedEdge<>("EF", E, F, new EdgeWeightMarking(5)));
|
||||
example4.addEdge(new MarkedEdge<>("EG", E, G, new EdgeWeightMarking(10)));
|
||||
example4.addEdge(new MarkedEdge<>("FG", F, G, new EdgeWeightMarking(3)));
|
||||
example4.addEdge(new MarkedEdge<>("FH", F, H, new EdgeWeightMarking(6)));
|
||||
example4.addEdge(new MarkedEdge<>("GH", G, H, new EdgeWeightMarking(1)));
|
||||
|
||||
return example4;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user