129 lines
3.3 KiB
Java
129 lines
3.3 KiB
Java
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<T extends VertexMarking, U extends EdgeMarking> extends Graph<T, U> {
|
|
|
|
// ATTRIBUTE
|
|
|
|
private visualizationElements.Graph screenGraph;
|
|
private LogElementList<OurLogElement> logList;
|
|
|
|
|
|
// KONSTRUKTOREN
|
|
|
|
public UndirectedGraph() {
|
|
super();
|
|
this.screenGraph = new visualizationElements.Graph(new Vector<Vertex>(), new Vector<Edge>(), false, EdgeStyle.Direct);
|
|
this.logList = new LogElementList<>();
|
|
}
|
|
|
|
|
|
public UndirectedGraph(String s) {
|
|
super(s);
|
|
this.screenGraph = new visualizationElements.Graph(new Vector<Vertex>(), new Vector<Edge>(), false, EdgeStyle.Direct);
|
|
this.logList = new LogElementList<>();
|
|
}
|
|
|
|
|
|
// GET-ER
|
|
|
|
public visualizationElements.Graph getScreenGraph() {
|
|
return this.screenGraph;
|
|
}
|
|
|
|
|
|
public LogElementList<OurLogElement> getLogList() {
|
|
return this.logList;
|
|
}
|
|
|
|
|
|
// HINZUFÜGEN
|
|
|
|
// Kante hinzufügen
|
|
public void addEdge(MarkedEdge<U> e) {
|
|
super.addEdge(e);
|
|
this.screenGraph.getEdges().add(e.getScreenEdge());
|
|
}
|
|
|
|
|
|
// Knoten hinzufügen
|
|
public void addVertex(MarkedVertex<T> n) {
|
|
super.addVertex(n);
|
|
this.screenGraph.getVertexes().add(n.getScreenVertex());
|
|
}
|
|
|
|
|
|
// LÖSCHEN
|
|
|
|
// Kante löschen
|
|
public void removeEdge(MarkedEdge<U> e) {
|
|
super.removeEdge(e);
|
|
this.screenGraph.getEdges().remove(e.getScreenEdge());
|
|
}
|
|
|
|
|
|
// Knoten löschen
|
|
public void removeVertex(MarkedVertex<T> n) {
|
|
super.removeVertex(n);
|
|
this.screenGraph.getVertexes().remove(n.getScreenVertex());
|
|
}
|
|
|
|
|
|
// KNOTEN EIGENSCHAFTEN
|
|
|
|
// Prüfung des Grades eines Knotens
|
|
public int degree(MarkedVertex<T> n) {
|
|
int degree = 0;
|
|
for (MarkedEdge<U> 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<T> 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<MarkedVertex<T>> getNeighbours(MarkedVertex<T> n) {
|
|
Vector<MarkedVertex<T>> neighbours = new Vector<>();
|
|
for (MarkedEdge<U> i: this.getAllEdges()) {
|
|
if (i.getSource() == n && !neighbours.contains(i.getDestination())) {
|
|
neighbours.add((MarkedVertex<T>) i.getDestination());
|
|
} else if (i.getDestination() == n && !neighbours.contains(i.getSource())) {
|
|
neighbours.add((MarkedVertex<T>) i.getSource());
|
|
}
|
|
}
|
|
return neighbours;
|
|
}
|
|
|
|
|
|
public int getShortestPathDijkstra(MarkedVertex<T> n1, MarkedVertex<T> n2) {
|
|
return 1;
|
|
}
|
|
public int getShortestPathAStar(MarkedVertex<T> n1, MarkedVertex<T> n2) {
|
|
return 2;
|
|
}
|
|
|
|
}
|