72 lines
2.8 KiB
Java
72 lines
2.8 KiB
Java
package graph;
|
|
|
|
import static java.awt.Color.black;
|
|
|
|
public class Anwendung {
|
|
public static void main(String[] args) {
|
|
// Erstellen eines gerichteten Graphen
|
|
DirectedGraph<VertexMarking, EdgeMarking> graph = new DirectedGraph<>();
|
|
|
|
// Erstellen und Hinzufügen von Knoten
|
|
MarkedVertex<VertexMarking> vertexA = new MarkedVertex<>("A", new VertexMarking() {
|
|
}, 10, 10, black);
|
|
MarkedVertex<VertexMarking> vertexB = new MarkedVertex<>("B", new VertexMarking() {
|
|
}, 10, 100, black);
|
|
MarkedVertex<VertexMarking> vertexC = new MarkedVertex<>("C", new VertexMarking() {
|
|
}, 100, 10, black);
|
|
MarkedVertex<VertexMarking> vertexD = new MarkedVertex<>("D", new VertexMarking() {
|
|
}, 600, 100, black);
|
|
MarkedVertex<VertexMarking> vertexE = new MarkedVertex<>("E", new VertexMarking() {
|
|
}, 100, 60, black);
|
|
MarkedVertex<VertexMarking> vertexF = new MarkedVertex<>("F", new VertexMarking() {
|
|
}, 160, 100, black);
|
|
MarkedVertex<VertexMarking> vertexG = new MarkedVertex<>("G", new VertexMarking() {
|
|
}, 100, 160, black);
|
|
|
|
|
|
graph.addVertex(vertexA);
|
|
graph.addVertex(vertexB);
|
|
graph.addVertex(vertexC);
|
|
graph.addVertex(vertexD);
|
|
graph.addVertex(vertexE);
|
|
graph.addVertex(vertexF);
|
|
graph.addVertex(vertexG);
|
|
|
|
// Erstellen und Hinzufügen von Kanten
|
|
graph.addEdge(new MarkedEdge<>("Edge1", vertexA, vertexB, new EdgeMarking() {
|
|
}));
|
|
graph.addEdge(new MarkedEdge<>("Edge2", vertexB, vertexC, new EdgeMarking() {
|
|
}));
|
|
graph.addEdge(new MarkedEdge<>("Edge3", vertexC, vertexD, new EdgeMarking() {
|
|
}));
|
|
|
|
graph.addEdge(new MarkedEdge<>("Edge7", vertexC, vertexE, new EdgeMarking() {
|
|
}));
|
|
|
|
graph.addEdge(new MarkedEdge<>("Edge4", vertexD, vertexE, new EdgeMarking() {
|
|
}));
|
|
|
|
graph.addEdge(new MarkedEdge<>("Edge8", vertexD, vertexG, new EdgeMarking() {
|
|
}));
|
|
graph.addEdge(new MarkedEdge<>("Edge5", vertexE, vertexF, new EdgeMarking() {
|
|
}));
|
|
|
|
graph.addEdge(new MarkedEdge<>("Edge6", vertexF, vertexG, new EdgeMarking() {
|
|
}));
|
|
|
|
//System.out.println(graph.areStrongAdjacent("A", "B"));
|
|
//System.out.println(graph.numberOfEdges());
|
|
System.out.println("Vorgänger von A");
|
|
System.out.println(graph.getPredecessors(vertexA));
|
|
System.out.println("Vorgänger von D");
|
|
System.out.println(graph.getPredecessors(vertexD));
|
|
System.out.println("Vorgänger von D");
|
|
System.out.println(graph.getSuccessors(vertexC));
|
|
|
|
|
|
System.out.println(graph.topSort(vertexA));
|
|
System.out.println("");
|
|
|
|
}
|
|
}
|