Beispiel1 hinzugefügt

This commit is contained in:
Sean Reich 2024-07-05 15:08:33 +02:00
parent 04d5175ab0
commit e07edf8b2b
6 changed files with 86 additions and 8 deletions

View File

@ -6,7 +6,7 @@
<component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Stable Version with finished visualisation">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/DirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/DirectedGraph.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurApplication.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@ -63,20 +63,23 @@ public class OurApplication {
DirectedGraph<VertexMarking, EdgeMarking> myGraph = new DirectedGraph<>();
for (int i = 0; i < 10; i++) {
/*for (int i = 0; i < 10; i++) {
myGraph.addVertex(new MarkedVertex<>(random.nextInt(1, 10)*40, random.nextInt(1, 10)*40, Integer.toString(i), null, Color.BLACK));
}
for (MarkedVertex<VertexMarking> i: myGraph.getAllVertexes()) {
myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10)));
}
/*
for (MarkedVertex<VertexMarking> i: myGraph.getAllVertexes()) {
myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10)));
}
*/
ExampleGraphs temp = new ExampleGraphs();
myGraph = temp.example1();
System.out.println(myGraph.toString());
drawArea.setCurrentGraph(myGraph.getScreenGraph());

67
graph/ExampleGraphs.java Normal file
View File

@ -0,0 +1,67 @@
package graph;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class ExampleGraphs {
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
* entgegengesetzten Ecken
*
* Ziel:
* Zeigen wie A* direkter sucht als Dikstra
*/
/*
*-*-*-*-*
| | | | |
*-*-*-*-*
| | | | |
*-*-*-*-*
| | | | |
*-*-*-*-*
| | | | |
* *-*-*-*
*/
DirectedGraph<VertexMarking, EdgeMarking> example1 = new DirectedGraph<>();
int size = 5;
MarkedVertex[][] vertices = new MarkedVertex[size][size];
// Knoten erstellen und zum Graph hinzufügen
for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) {
String name = String.valueOf((char) ('A' + row * size + col));
vertices[row][col] = new MarkedVertex<>(50 + col * 100, 50 + row * 100, name, null, null);
example1.addVertex(vertices[row][col]);
}
}
// Kanten horizontal und vertikal verbinden
for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) {
if (col < size - 1) {
addBidirectionalEdge(example1, vertices[row][col], vertices[row][col + 1], 1);
}
if (row < size - 1) {
addBidirectionalEdge(example1, vertices[row][col], vertices[row + 1][col], 1);
}
}
}
return example1;
}
private void addBidirectionalEdge(DirectedGraph<VertexMarking, EdgeMarking> graph, MarkedVertex from, MarkedVertex to, int weight) {
MarkedEdge forwardEdge = new MarkedEdge<>("edge" + from.getName() + "_" + to.getName(), from, to, null, weight);
MarkedEdge backwardEdge = new MarkedEdge<>("edge" + to.getName() + "_" + from.getName(), to, from, null, weight);
graph.addEdge(forwardEdge);
graph.addEdge(backwardEdge);
}
}

View File

@ -4,10 +4,9 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Adding AStar Algorithm">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Stable Version with finished visualisation">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/Display.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/graph/DirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/DirectedGraph.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -87,7 +86,15 @@
<option name="project" value="LOCAL" />
<updated>1720042374225</updated>
</task>
<option name="localTasksCounter" value="5" />
<task id="LOCAL-00005" summary="Stable Version with finished visualisation">
<option name="closed" value="true" />
<created>1720120737939</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1720120737940</updated>
</task>
<option name="localTasksCounter" value="6" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -104,6 +111,7 @@
<component name="VcsManagerConfiguration">
<MESSAGE value="Stable Version 3.0" />
<MESSAGE value="Adding AStar Algorithm" />
<option name="LAST_COMMIT_MESSAGE" value="Adding AStar Algorithm" />
<MESSAGE value="Stable Version with finished visualisation" />
<option name="LAST_COMMIT_MESSAGE" value="Stable Version with finished visualisation" />
</component>
</project>