Dateien nach "graph" hochladen
This commit is contained in:
parent
d70ce4a163
commit
7f43735871
34
graph/MarkedEdge.java
Normal file
34
graph/MarkedEdge.java
Normal file
@ -0,0 +1,34 @@
|
||||
package graph;
|
||||
|
||||
public class MarkedEdge<U extends EdgeMarking> extends Edge {
|
||||
private U marking;
|
||||
|
||||
public MarkedEdge() {
|
||||
super();
|
||||
this.screenEdge = new visualizationElements.Edge(null, null);
|
||||
}
|
||||
|
||||
private visualizationElements.Edge screenEdge;
|
||||
|
||||
public MarkedEdge(String s, Vertex n1, Vertex n2, U u) {
|
||||
super(s, n1, n2);
|
||||
this.marking = u;
|
||||
this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), "u.toString()");
|
||||
}
|
||||
|
||||
public U getMarking() {
|
||||
return marking;
|
||||
}
|
||||
|
||||
public void setMarking(U u) {
|
||||
this.marking = u;
|
||||
}
|
||||
public visualizationElements.Edge getScreenEdge() {return this.screenEdge;}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MarkedEdge{" + "name='" + getName() + '\'' + ", source=" + getSource() + ", destination=" + getDestination() + ", marking=" + marking + '}';
|
||||
}
|
||||
|
||||
}
|
71
graph/MarkedVertex.java
Normal file
71
graph/MarkedVertex.java
Normal file
@ -0,0 +1,71 @@
|
||||
package graph;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class MarkedVertex<T extends VertexMarking> extends Vertex {
|
||||
private T marking;
|
||||
|
||||
private int x;
|
||||
|
||||
private int y;
|
||||
|
||||
private Color color;
|
||||
|
||||
private visualizationElements.Vertex screenVertex;
|
||||
|
||||
public MarkedVertex() {
|
||||
super();
|
||||
this.screenVertex = new visualizationElements.Vertex(0,0);
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
}
|
||||
|
||||
public MarkedVertex(String s, T t, int x, int y, Color color) {
|
||||
super(s);
|
||||
this.marking = t;
|
||||
this.screenVertex = new visualizationElements.Vertex(x,y, s, color);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.color = color;
|
||||
}
|
||||
// Getter und Setter für x und y
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public visualizationElements.Vertex getScreenVertex() {return this.screenVertex;}
|
||||
|
||||
public int[] getCords() {return new int[] {this.x, this.y};}
|
||||
|
||||
public T getMarking() {
|
||||
return marking;
|
||||
}
|
||||
|
||||
public void setMarking(T t) {
|
||||
this.marking = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MarkedVertex{" + "name='" + getName() + '\'' + ", marking=" + marking + '}';
|
||||
}
|
||||
}
|
4
graph/Marking.java
Normal file
4
graph/Marking.java
Normal file
@ -0,0 +1,4 @@
|
||||
package graph;
|
||||
|
||||
public abstract class Marking {
|
||||
}
|
84
graph/UndirectedGraph.java
Normal file
84
graph/UndirectedGraph.java
Normal file
@ -0,0 +1,84 @@
|
||||
package graph;
|
||||
|
||||
import logging.LogElement;
|
||||
import logging.LogElementList;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> extends Graph<T, U> {
|
||||
|
||||
public UndirectedGraph() {}
|
||||
|
||||
public UndirectedGraph(String s) {
|
||||
super(s);
|
||||
}
|
||||
LogElementList<LogElement> logList = new LogElementList<>(); // Erzeugen einer LogElementList für die Protokollierung
|
||||
private visualizationElements.Graph visualizedGraph;
|
||||
|
||||
public int degree(MarkedVertex<T> n) {
|
||||
int degree = 0;
|
||||
for (MarkedEdge<U> edge : getAllEdges()) {
|
||||
if (edge.getSource().equals(n) || edge.getDestination().equals(n)) {
|
||||
degree++;
|
||||
}
|
||||
}
|
||||
return degree;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int degree(String s) {
|
||||
for (MarkedVertex<T> vertex : getAllVertexes()) {
|
||||
if (vertex.getName().equals(s)) {
|
||||
return degree(vertex);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public visualizationElements.Graph getVisualizedGraph() {
|
||||
return this.visualizedGraph;
|
||||
}
|
||||
|
||||
public LogElementList<LogElement> getLogList(){
|
||||
return this.logList;
|
||||
}
|
||||
|
||||
public Vector<MarkedVertex<T>> getNeighbours(MarkedVertex<T> n) {
|
||||
Vector<MarkedVertex<T>> neighbours = new Vector<>();
|
||||
for (MarkedEdge<U> edge : getAllEdges()) {
|
||||
if (edge.getSource().equals(n)) {
|
||||
neighbours.add((MarkedVertex<T>) edge.getDestination());
|
||||
} else if (edge.getDestination().equals(n)) {
|
||||
neighbours.add((MarkedVertex<T>) edge.getSource());
|
||||
}
|
||||
}
|
||||
return neighbours;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areAdjacent(MarkedVertex<T> n1, MarkedVertex<T> n2) {
|
||||
for (MarkedEdge<U> edge : getAllEdges()) {
|
||||
if ((edge.getSource().equals(n1) && edge.getDestination().equals(n2)) ||
|
||||
(edge.getSource().equals(n2) && edge.getDestination().equals(n1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areAdjacent(String s1, String s2) {
|
||||
for (MarkedEdge<U> edge : getAllEdges()) {
|
||||
if ((edge.getSource().getName().equals(s1) && edge.getDestination().getName().equals(s2)) ||
|
||||
(edge.getSource().getName().equals(s2) && edge.getDestination().getName().equals(s1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UndirectedGraph{} " + super.toString();
|
||||
}
|
||||
}
|
22
graph/Vertex.java
Normal file
22
graph/Vertex.java
Normal file
@ -0,0 +1,22 @@
|
||||
package graph;
|
||||
|
||||
public abstract class Vertex {
|
||||
private String name;
|
||||
|
||||
public Vertex() {}
|
||||
|
||||
public Vertex(String s) {
|
||||
this.name = s;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String s) {
|
||||
this.name = s;
|
||||
}
|
||||
|
||||
|
||||
public abstract visualizationElements.Vertex getScreenVertex();
|
||||
}
|
Loading…
Reference in New Issue
Block a user