Beispiele überarbeitet

This commit is contained in:
Sean Reich 2024-07-07 02:24:27 +02:00
parent 3c74497254
commit 3629584d14
3 changed files with 155 additions and 82 deletions

7
.idea/workspace.xml generated
View File

@ -5,9 +5,10 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="small fix"> <list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="small fix">
<change afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/EdgeWeightMarking.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/ExampleGraphs.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/OurApplication/OurApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurApplication.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/VertexWeightMarking.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/graph/ExampleGraphs.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/ExampleGraphs.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/ExampleGraphs.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/ExampleGraphs.class" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@ -6,27 +6,20 @@ import java.util.List;
public class ExampleGraphs { public class ExampleGraphs {
public DirectedGraph<VertexMarking, EdgeMarking> example1 (){ public DirectedGraph<VertexMarking, EdgeMarking> example1() {
/* /*
* Beispiel 1 ist ein "Gitter" an Knoten und Kanten. Dabei hat jede Kante die selbe Gewichtung und Start und Endknoten sind in * Beispiel 1 zeigt ein Gitter aus Knoten und Kanten, bei dem jeder Knoten mit
* entgegengesetzten Ecken * seinen horizontal und vertikal benachbarten Knoten verbunden ist. Alle Kanten
* haben die gleiche Gewichtung. Der Startknoten befindet sich in einer Ecke
* des Gitters und der Zielknoten in der gegenüberliegenden Ecke.
* *
* Ziel: * Ziel:
* Zeigen wie A* direkter sucht als Dikstra * Demonstrieren, wie der A*-Algorithmus durch gezieltere Suche effizienter ist
*/ * als der Dijkstra-Algorithmus in einem strukturierten Gittergraphen.
*
* Startknoten: A
/* * Endknoten: Y
*-*-*-*-*
| | | | |
*-*-*-*-*
| | | | |
*-*-*-*-*
| | | | |
*-*-*-*-*
| | | | |
* *-*-*-*
*/ */
DirectedGraph<VertexMarking, EdgeMarking> example1 = new DirectedGraph<>(); DirectedGraph<VertexMarking, EdgeMarking> example1 = new DirectedGraph<>();
@ -68,13 +61,24 @@ public class ExampleGraphs {
public DirectedGraph<VertexMarking, EdgeMarking> example2() { public DirectedGraph<VertexMarking, EdgeMarking> example2() {
DirectedGraph<VertexMarking, EdgeMarking> example2 = new DirectedGraph<>(); DirectedGraph<VertexMarking, EdgeMarking> example2 = new DirectedGraph<>();
MarkedVertex A = new MarkedVertex<>(50, 50, "A", null, null);
MarkedVertex B = new MarkedVertex<>(150, 50, "B", null, null); /*
MarkedVertex C = new MarkedVertex<>(250, 50, "C", null, null); * Beispiel 2 zeigt zwei Wege von einem Startknoten zu einem Zielknoten mit unterschiedlichen Eigenschaften:
MarkedVertex D = new MarkedVertex<>(50, 150, "D", null, null); * Ein Weg (oben) hat wenige Knoten mit Kanten geringer Gewichtung, außer der letzten Kante, die hohe Gewichtung hat.
MarkedVertex E = new MarkedVertex<>(150, 150, "E", null, null); * Der andere Weg (unten) hat mehr Knoten mit höherer Gewichtung der Kanten. Der Algorithmus sollte zuerst den oberen
MarkedVertex F = new MarkedVertex<>(250, 150, "F", null, null); * Weg erkunden, bis er die hohe Gewichtung der letzten Kante des unteren Wegs berücksichtigt.
MarkedVertex G = new MarkedVertex<>(150, 250, "G", null, null); *
* Startknoten: A
* Endknoten: E
*/
MarkedVertex A = new MarkedVertex<>(100, 100, "A", null, null);
MarkedVertex B = new MarkedVertex<>(250, 50, "B", null, null);
MarkedVertex C = new MarkedVertex<>(400, 100, "C", null, null);
MarkedVertex D = new MarkedVertex<>(550, 50, "D", null, null);
MarkedVertex E = new MarkedVertex<>(700, 100, "E", null, null);
MarkedVertex F = new MarkedVertex<>(250, 200, "F", null, null);
MarkedVertex G = new MarkedVertex<>(550, 200, "G", null, null);
example2.addVertex(A); example2.addVertex(A);
example2.addVertex(B); example2.addVertex(B);
@ -84,81 +88,149 @@ public class ExampleGraphs {
example2.addVertex(F); example2.addVertex(F);
example2.addVertex(G); example2.addVertex(G);
example2.addEdge(new MarkedEdge<>("AB", A, B, null, 2)); example2.addEdge(new MarkedEdge<>("AB", A, B, new EdgeWeightMarking(1), 1));
example2.addEdge(new MarkedEdge<>("AC", A, C, null, 4)); example2.addEdge(new MarkedEdge<>("BC", B, C, new EdgeWeightMarking(1), 1));
example2.addEdge(new MarkedEdge<>("BD", B, D, null, 5)); example2.addEdge(new MarkedEdge<>("CD", C, D, new EdgeWeightMarking(10), 10));
example2.addEdge(new MarkedEdge<>("BE", B, E, null, 3)); example2.addEdge(new MarkedEdge<>("DE", D, E, new EdgeWeightMarking(1), 1));
example2.addEdge(new MarkedEdge<>("CE", C, E, null, 1));
example2.addEdge(new MarkedEdge<>("DF", D, F, null, 2)); example2.addEdge(new MarkedEdge<>("AF", A, F, new EdgeWeightMarking(5), 5));
example2.addEdge(new MarkedEdge<>("EF", E, F, null, 2)); example2.addEdge(new MarkedEdge<>("FG", F, G, new EdgeWeightMarking(5), 5));
example2.addEdge(new MarkedEdge<>("EG", E, G, null, 4)); example2.addEdge(new MarkedEdge<>("GE", G, E, new EdgeWeightMarking(5), 5));
example2.addEdge(new MarkedEdge<>("FG", F, G, null, 3));
return example2; return example2;
} }
public DirectedGraph<VertexMarking, EdgeMarking> example3() { public DirectedGraph<VertexMarking, EdgeMarking> example3() {
/*
* Beispiel 3 zeigt ein Labyrinth mit vier horizontalen Wegen, die jeweils aus vier Knoten bestehen.
* Jeder Weg führt zum Endpunkt E1, E2, E3 bzw. E4. Ziel ist es zu zeigen, dass die Algorithmen auch
* potenziell falsche Wege erkunden können, bevor sie den richtigen Endpunkt erreichen.
*
* Startknoten: A
* Endknoten: E2
*/
DirectedGraph<VertexMarking, EdgeMarking> example3 = new DirectedGraph<>(); DirectedGraph<VertexMarking, EdgeMarking> example3 = new DirectedGraph<>();
MarkedVertex A = new MarkedVertex<>(50, 50, "A", null, null); // Startpunkt A in der Mitte der Y-Koordinate
MarkedVertex B = new MarkedVertex<>(150, 50, "B", null, null); MarkedVertex A = new MarkedVertex<>(100, 250, "A", null, null);
MarkedVertex C = new MarkedVertex<>(250, 50, "C", null, null);
MarkedVertex D = new MarkedVertex<>(50, 150, "D", null, null); // Erster Weg
MarkedVertex E = new MarkedVertex<>(150, 150, "E", null, null); MarkedVertex B1 = new MarkedVertex<>(200, 100, "B1", null, null);
MarkedVertex C1 = new MarkedVertex<>(300, 100, "C1", null, null);
MarkedVertex D1 = new MarkedVertex<>(400, 100, "D1", null, null);
MarkedVertex E1 = new MarkedVertex<>(500, 100, "E1", null, null); // Endpunkt des ersten Weges
// Zweiter Weg
MarkedVertex B2 = new MarkedVertex<>(200, 200, "B2", null, null);
MarkedVertex C2 = new MarkedVertex<>(300, 200, "C2", null, null);
MarkedVertex D2 = new MarkedVertex<>(400, 200, "D2", null, null);
MarkedVertex E2 = new MarkedVertex<>(500, 200, "E2", null, null); // Endpunkt des zweiten Weges
// Dritter Weg
MarkedVertex B3 = new MarkedVertex<>(200, 300, "B3", null, null);
MarkedVertex C3 = new MarkedVertex<>(300, 300, "C3", null, null);
MarkedVertex D3 = new MarkedVertex<>(400, 300, "D3", null, null);
MarkedVertex E3 = new MarkedVertex<>(500, 300, "E3", null, null); // Endpunkt des dritten Weges
// Vierter Weg
MarkedVertex B4 = new MarkedVertex<>(200, 400, "B4", null, null);
MarkedVertex C4 = new MarkedVertex<>(300, 400, "C4", null, null);
MarkedVertex D4 = new MarkedVertex<>(400, 400, "D4", null, null);
MarkedVertex E4 = new MarkedVertex<>(500, 400, "E4", null, null); // Endpunkt des vierten Weges
example3.addVertex(A); example3.addVertex(A);
example3.addVertex(B); example3.addVertex(B1);
example3.addVertex(C); example3.addVertex(C1);
example3.addVertex(D); example3.addVertex(D1);
example3.addVertex(E); example3.addVertex(B2);
example3.addVertex(C2);
example3.addVertex(D2);
example3.addVertex(B3);
example3.addVertex(C3);
example3.addVertex(D3);
example3.addVertex(B4);
example3.addVertex(C4);
example3.addVertex(D4);
example3.addVertex(E1);
example3.addVertex(E2);
example3.addVertex(E3);
example3.addVertex(E4);
example3.addEdge(new MarkedEdge<>("AB", A, B, null, 1)); example3.addEdge(new MarkedEdge<>("AB1", A, B1, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("AC", A, C, null, 1)); example3.addEdge(new MarkedEdge<>("AB2", A, B2, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("BD", B, D, null, 1)); example3.addEdge(new MarkedEdge<>("AB3", A, B3, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("BE", B, E, null, 2)); example3.addEdge(new MarkedEdge<>("AB4", A, B4, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("CD", C, D, null, 1));
example3.addEdge(new MarkedEdge<>("CE", C, E, null, 2)); example3.addEdge(new MarkedEdge<>("B1C1", B1, C1, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("DE", D, E, null, 1)); example3.addEdge(new MarkedEdge<>("B2C2", B2, C2, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("B3C3", B3, C3, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("B4C4", B4, C4, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("C1D1", C1, D1, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("C2D2", C2, D2, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("C3D3", C3, D3, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("C4D4", C4, D4, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("D1E1", D1, E1, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("D2E2", D2, E2, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("D3E3", D3, E3, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("D4E4", D4, E4, new EdgeWeightMarking(1), 1));
return example3; return example3;
} }
public DirectedGraph<VertexMarking, EdgeMarking> example4() { public DirectedGraph<VertexMarking, EdgeMarking> example4() {
/*
* Beispiel 4 zeigt einen gerichteten Graphen mit deutschen Städten als Knoten und
* zufällig gewichteten Kanten.
*/
DirectedGraph<VertexMarking, EdgeMarking> example4 = new DirectedGraph<>(); DirectedGraph<VertexMarking, EdgeMarking> example4 = new DirectedGraph<>();
MarkedVertex A = new MarkedVertex<>(50, 50, "A", null, null); // Städte als Knoten
MarkedVertex B = new MarkedVertex<>(150, 50, "B", null, null); MarkedVertex Berlin = new MarkedVertex<>(100, 100, "Berlin", null, null);
MarkedVertex C = new MarkedVertex<>(250, 50, "C", null, null); MarkedVertex Hamburg = new MarkedVertex<>(200, 100, "Hamburg", null, null);
MarkedVertex D = new MarkedVertex<>(50, 150, "D", null, null); MarkedVertex München = new MarkedVertex<>(300, 100, "München", null, null);
MarkedVertex E = new MarkedVertex<>(150, 150, "E", null, null); MarkedVertex Köln = new MarkedVertex<>(100, 200, "Köln", null, null);
MarkedVertex F = new MarkedVertex<>(250, 150, "F", null, null); MarkedVertex Frankfurt = new MarkedVertex<>(200, 200, "Frankfurt", null, null);
MarkedVertex G = new MarkedVertex<>(50, 250, "G", null, null); MarkedVertex Stuttgart = new MarkedVertex<>(300, 200, "Stuttgart", null, null);
MarkedVertex H = new MarkedVertex<>(150, 250, "H", null, null); MarkedVertex Leipzig = new MarkedVertex<>(100, 300, "Leipzig", null, null);
MarkedVertex I = new MarkedVertex<>(250, 250, "I", null, null); MarkedVertex Dresden = new MarkedVertex<>(200, 300, "Dresden", null, null);
MarkedVertex Hannover = new MarkedVertex<>(300, 300, "Hannover", null, null);
example4.addVertex(A); // Kanten mit zufälligen Gewichtungen
example4.addVertex(B); example4.addVertex(Berlin);
example4.addVertex(C); example4.addVertex(Hamburg);
example4.addVertex(D); example4.addVertex(München);
example4.addVertex(E); example4.addVertex(Köln);
example4.addVertex(F); example4.addVertex(Frankfurt);
example4.addVertex(G); example4.addVertex(Stuttgart);
example4.addVertex(H); example4.addVertex(Leipzig);
example4.addVertex(I); example4.addVertex(Dresden);
example4.addVertex(Hannover);
example4.addEdge(new MarkedEdge<>("AB", A, B, null, 2)); example4.addEdge(new MarkedEdge<>("Berlin-Hamburg", Berlin, Hamburg, new EdgeWeightMarking(1), 1));
example4.addEdge(new MarkedEdge<>("AC", A, C, null, 4)); example4.addEdge(new MarkedEdge<>("Berlin-München", Berlin, München, new EdgeWeightMarking(2), 1));
example4.addEdge(new MarkedEdge<>("BD", B, D, null, 3)); example4.addEdge(new MarkedEdge<>("Berlin-Köln", Berlin, Köln, new EdgeWeightMarking(3), 1));
example4.addEdge(new MarkedEdge<>("BE", B, E, null, 2)); example4.addEdge(new MarkedEdge<>("Hamburg-Frankfurt", Hamburg, Frankfurt, new EdgeWeightMarking(2), 1));
example4.addEdge(new MarkedEdge<>("CF", C, F, null, 2)); example4.addEdge(new MarkedEdge<>("Hamburg-Leipzig", Hamburg, Leipzig, new EdgeWeightMarking(3), 1));
example4.addEdge(new MarkedEdge<>("DG", D, G, null, 2)); example4.addEdge(new MarkedEdge<>("München-Stuttgart", München, Stuttgart, new EdgeWeightMarking(1), 1));
example4.addEdge(new MarkedEdge<>("EH", E, H, null, 3)); example4.addEdge(new MarkedEdge<>("München-Dresden", München, Dresden, new EdgeWeightMarking(2), 1));
example4.addEdge(new MarkedEdge<>("FI", F, I, null, 4)); example4.addEdge(new MarkedEdge<>("Köln-Hannover", Köln, Hannover, new EdgeWeightMarking(3), 1));
example4.addEdge(new MarkedEdge<>("GH", G, H, null, 1)); example4.addEdge(new MarkedEdge<>("Frankfurt-Stuttgart", Frankfurt, Stuttgart, new EdgeWeightMarking(1), 1));
example4.addEdge(new MarkedEdge<>("HI", H, I, null, 1)); example4.addEdge(new MarkedEdge<>("Stuttgart-Leipzig", Stuttgart, Leipzig, new EdgeWeightMarking(2), 1));
example4.addEdge(new MarkedEdge<>("GI", G, I, null, 3)); example4.addEdge(new MarkedEdge<>("Leipzig-Dresden", Leipzig, Dresden, new EdgeWeightMarking(1), 1));
example4.addEdge(new MarkedEdge<>("Dresden-Hannover", Dresden, Hannover, new EdgeWeightMarking(3), 1));
return example4; return example4;
} }
} }