package graph; import OurApplication.OurLogElement; import logging.LogElementList; import visualizationElements.Edge; import visualizationElements.EdgeStyle; import visualizationElements.Vertex; import java.util.Objects; import java.util.Vector; public class UndirectedGraph extends Graph { // ATTRIBUTE private visualizationElements.Graph screenGraph; private LogElementList logList; // KONSTRUKTOREN public UndirectedGraph() { super(); this.screenGraph = new visualizationElements.Graph(new Vector(), new Vector(), false, EdgeStyle.Direct); this.logList = new LogElementList<>(); } public UndirectedGraph(String s) { super(s); this.screenGraph = new visualizationElements.Graph(new Vector(), new Vector(), false, EdgeStyle.Direct); this.logList = new LogElementList<>(); } // GET-ER public visualizationElements.Graph getScreenGraph() { return this.screenGraph; } public LogElementList getLogList() { return this.logList; } // HINZUFÜGEN // Kante hinzufügen public void addEdge(MarkedEdge e) { super.addEdge(e); this.screenGraph.getEdges().add(e.getScreenEdge()); } // Knoten hinzufügen public void addVertex(MarkedVertex n) { super.addVertex(n); this.screenGraph.getVertexes().add(n.getScreenVertex()); } // LÖSCHEN // Kante löschen public void removeEdge(MarkedEdge e) { super.removeEdge(e); this.screenGraph.getEdges().remove(e.getScreenEdge()); } // Knoten löschen public void removeVertex(MarkedVertex n) { super.removeVertex(n); this.screenGraph.getVertexes().remove(n.getScreenVertex()); } // KNOTEN EIGENSCHAFTEN // Prüfung des Grades eines Knotens public int degree(MarkedVertex n) { int degree = 0; for (MarkedEdge i: this.getAllEdges()) { if (i.getSource() == n) { degree += 1; } if (i.getDestination() == n) { degree += 1; } } return degree; } public int degree(String s) throws NameDoesNotExistException{ for (MarkedVertex i: this.getAllVertexes()) { if (Objects.equals(i.getName(), s)) { return degree(i); } } throw new NameDoesNotExistException("One of the Vertexes might not exist"); } // Prüfung, welche Knoten Nachbarn sind public Vector> getNeighbours(MarkedVertex n) { Vector> neighbours = new Vector<>(); for (MarkedEdge i: this.getAllEdges()) { if (i.getSource() == n && !neighbours.contains(i.getDestination())) { neighbours.add((MarkedVertex) i.getDestination()); } else if (i.getDestination() == n && !neighbours.contains(i.getSource())) { neighbours.add((MarkedVertex) i.getSource()); } } return neighbours; } public int getShortestPathDijkstra(MarkedVertex n1, MarkedVertex n2) { return 1; } public int getShortestPathAStar(MarkedVertex n1, MarkedVertex n2) { return 2; } }