35 lines
1.4 KiB
Java
35 lines
1.4 KiB
Java
package graph;
|
|
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class Display {
|
|
|
|
public static void main(String[] args) {
|
|
DirectedGraph<VertexMarking, EdgeMarking> myGraph = new DirectedGraph<>();
|
|
|
|
Random random = new Random();
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
myGraph.addVertex(new MarkedVertex<>(random.nextInt(i, 350), random.nextInt(i, 350), String.valueOf(i) + " :", Color.BLACK , null));
|
|
}
|
|
|
|
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));
|
|
|
|
}
|
|
}
|