Stable Version 3.0

This commit is contained in:
cmerkens 2024-07-05 15:14:53 +02:00
commit 017bbe9307
4 changed files with 72 additions and 2 deletions

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);
}
}