ProjektGraph/graph/Display.java
2024-07-01 17:08:11 +02:00

33 lines
1.3 KiB
Java

package graph;
import java.util.Random;
public class Display {
public static void main(String[] args) {
DirectedGraph<VertexMarking, EdgeMarking> myGraph = new DirectedGraph<>();
for (int i = 0; i < 10; i++) {
myGraph.addVertex(new MarkedVertex<>(String.valueOf(i), null, i, i));
}
Random random = new Random();
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)));
}
System.out.println(myGraph.toString());
MarkedVertex<VertexMarking> start = myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size()));
MarkedVertex<VertexMarking> end = myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size()));
System.out.println(start.getName() + " to " + end.getName());
System.out.println(myGraph.getShortestPathDijkstra(start, end));
}
}