diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 89bd139..e2001f0 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,791 +5,20 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - { - "keyToString": { - "Application.Display.executor": "Run", - "RunOnceActivity.ShowReadmeOnStart": "true", - "git-widget-placeholder": "Versuch__Christian", - "kotlin-language-version-configured": "true", - "last_opened_file_path": "C:/Git/ProjektGraph" + +}]]> + @@ -836,4 +67,15 @@ + + + \ No newline at end of file diff --git a/OurApplication/OurAlgorithm.java b/OurApplication/OurAlgorithm.java index 4129b06..9fc3f31 100644 --- a/OurApplication/OurAlgorithm.java +++ b/OurApplication/OurAlgorithm.java @@ -39,71 +39,11 @@ public class OurAlgorithm extends Algorithm{ - public LogElementList run(){ - LogElementListlogList = new LogElementList(); - - /* - for(int x=1;x<=10;x++){ - Random random = new Random(); - DirectedGraph myGraph = new DirectedGraph<>(); - for (int i = 0; i < 10; i++) { - myGraph.addVertex(new MarkedVertex<>(String.valueOf(i), null, random.nextInt(i, 350), random.nextInt(i, 350))); - } - - for (MarkedVertex i: myGraph.getAllVertexes()) { - myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10))); - } - - for (MarkedVertex i: myGraph.getAllVertexes()) { - myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10))); - } - - try{ - logList.add(new OurLogElement(x, "Value", x, myGraph)); - } - catch(OutOfMemoryError e){ - - System.err.println("Out of memory"); - } - } - */ - - Random random = new Random(); - DirectedGraph myGraph = new DirectedGraph<>(); - 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 i: myGraph.getAllVertexes()) { - myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10))); - } - - for (MarkedVertex i: myGraph.getAllVertexes()) { - myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10))); - } - - MarkedVertex start = myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())); - MarkedVertex end = myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())); - - Vector> items = new Vector<>(); - items = myGraph.DikstraVisualization(start, end); - - for(DirectedGraph i : items){ - logList.add(new OurLogElement(1, "Value", 1, i)); - } + public LogElementList run(){ + LogElementList logList = new LogElementList(); + // Hier müssen die Loggingelemente von Dikstra ankommen. return logList; } - - - //Erstelle eines zufälligen Graphen - //Auf den graphen Diktra aufrufen --> liefert Vektor mit Steps - //for each über die Steps und fügen sie zur Loglist hinzu - //return die Log list - - - - } diff --git a/OurApplication/OurApplication.java b/OurApplication/OurApplication.java index c2ff36f..1b49b49 100644 --- a/OurApplication/OurApplication.java +++ b/OurApplication/OurApplication.java @@ -37,17 +37,16 @@ public class OurApplication { */ public static void main(String[]args){ - - LogElementListlogList=new LogElementList(); - OurParameterArea parameterArea=new OurParameterArea(); - OurDrawArea drawArea=new OurDrawArea(logList,"GraphVisualization"); - OurTextArea textArea=new OurTextArea(logList); - OurAlgorithm algorithm=new OurAlgorithm(parameterArea); - OurLegendArea legendArea=new OurLegendArea(); - HybridWindow applet=new HybridWindow(drawArea,textArea,parameterArea,algorithm,logList,legendArea); + LogElementListlogList = new LogElementList(); + OurParameterArea parameterArea = new OurParameterArea(); + OurDrawArea drawArea = new OurDrawArea(logList,"GraphVisualization"); + OurTextArea textArea = new OurTextArea(logList); + OurAlgorithm algorithm = new OurAlgorithm(parameterArea); + OurLegendArea legendArea = new OurLegendArea(); + HybridWindow applet = new HybridWindow(drawArea, textArea, parameterArea, algorithm, logList, legendArea); - JFrame frame=new JFrame("Visualise"); + JFrame frame = new JFrame("Visualise"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(applet); frame.pack(); @@ -55,6 +54,8 @@ public class OurApplication { applet.start(); frame.setSize(800,600); frame.setVisible(true); + + } } diff --git a/OurApplication/OurDrawArea.java b/OurApplication/OurDrawArea.java index d0202d0..e3e2580 100644 --- a/OurApplication/OurDrawArea.java +++ b/OurApplication/OurDrawArea.java @@ -4,8 +4,10 @@ import graph.*; import logging.LogElementList; import visualisation.DrawArea; import visualizationElements.*; +import visualizationElements.Graph; import java.awt.*; +import java.util.Random; import java.util.Vector; /** @@ -40,53 +42,35 @@ public class OurDrawArea extends DrawArea{ * Draws a visualization element. */ - public void draw(Graphics g){ + public void draw(Graphics g) { - OurLogElement logElement=(OurLogElement)logList.get(); - drawGraph(logElement.getGraph(), g); + Random random = new Random(); - } + DirectedGraph myGraph = new DirectedGraph<>(); - private void drawGraph(DirectedGraph ourGraph, Graphics g) { - String convertedMarking; + for (int i = 0; i < 10; i++) { + myGraph.addVertex(new MarkedVertex<>(random.nextInt(1, 10)*35, random.nextInt(1, 10)*35, "", null, Color.BLACK)); + } - /*Vector vertexes = new Vector(); + for (MarkedVertex i: myGraph.getAllVertexes()) { + myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10))); + } - for(MarkedVertex i : ourGraph.getAllVertexes()){ - if(i.getMarking() != null){ - convertedMarking = i.getMarking().toString(); - }else{ - convertedMarking = ""; - } - vertexes.add(new Vertex(i.getXCoordinate(), i.getYCoordinate(), convertedMarking, Color.GRAY)); - } + for (MarkedVertex i: myGraph.getAllVertexes()) { + myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10))); + } - Vector edges = new Vector(); + System.out.println(myGraph.toString()); - for(MarkedEdge i : ourGraph.getAllEdges()){ - edges.add(new Edge(vertexes.get(0), vertexes.get(5), "i.getMarking()", Color.BLACK)); - } + MarkedVertex start = myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())); + MarkedVertex end = myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())); + System.out.println(start.getName() + " to " + end.getName()); - Graph graph = new Graph(vertexes, edges, true, EdgeStyle.Direct); + System.out.println(myGraph.getShortestPathDijkstra(start, end)); - graph.draw(g);*/ + myGraph.getScreenGraph().draw(g); - Vector vertexes = new Vector(); - - for(MarkedVertex i : ourGraph.getAllVertexes()){ - - vertexes.add(new Vertex(i.getXCoordinate(), i.getYCoordinate(), i.getName()+i.getDistance(), i.getColor())); - } - - Vector edges = new Vector(); - - for(MarkedEdge i : ourGraph.getAllEdges()){ - edges.add(new Edge(i.getSource(), i.getDestination(), "i.getMarking()", Color.BLACK)); - } - - Graph graph = new Graph(vertexes, edges, true, EdgeStyle.Direct); - - graph.draw(g); + // OurLogElement logElement = (OurLogElement) logList.get(); } } diff --git a/OurApplication/OurHybridWindow.java b/OurApplication/OurHybridWindow.java index 05c5759..caee326 100644 --- a/OurApplication/OurHybridWindow.java +++ b/OurApplication/OurHybridWindow.java @@ -23,11 +23,11 @@ public class OurHybridWindow extends HybridWindow{ */ public OurHybridWindow() { super(); - logList=new LogElementList(); - parameterArea=new OurParameterArea(); - drawArea=new OurDrawArea(logList,"visualization"); - textArea=new OurTextArea(logList); - legendArea=new OurLegendArea(); - algorithm=new OurAlgorithm((OurParameterArea)parameterArea); + logList = new LogElementList(); + parameterArea = new OurParameterArea(); + drawArea = new OurDrawArea(logList,"visualization"); + textArea = new OurTextArea(logList); + legendArea = new OurLegendArea(); + algorithm = new OurAlgorithm((OurParameterArea) parameterArea); } } diff --git a/OurApplication/OurLogElement.java b/OurApplication/OurLogElement.java index 1e17bb7..e2bdf06 100644 --- a/OurApplication/OurLogElement.java +++ b/OurApplication/OurLogElement.java @@ -37,9 +37,9 @@ public class OurLogElement extends LogElement{ * @param value the log element's sum up value */ public OurLogElement(int step, String description, long value, DirectedGraph ourGraph){ - this.step=step; - this.description=description; - this.value=value; + this.step = step; + this.description = description; + this.value = value; this.ourGraph = ourGraph; } @@ -50,6 +50,8 @@ public class OurLogElement extends LogElement{ public long getValue(){ return value; } + + public DirectedGraph getGraph(){ return this.ourGraph; } diff --git a/OurApplication/OurParameterArea.java b/OurApplication/OurParameterArea.java index 7c4a4a3..faba790 100644 --- a/OurApplication/OurParameterArea.java +++ b/OurApplication/OurParameterArea.java @@ -25,8 +25,7 @@ public class OurParameterArea extends ParameterArea{ public OurParameterArea() { super(); setBorder(BorderFactory.createTitledBorder("ParameterArea")); + + // Hier Elemente adden } - - - } diff --git a/graph/DirectedGraph.java b/graph/DirectedGraph.java index 9c0a6e0..14b7675 100644 --- a/graph/DirectedGraph.java +++ b/graph/DirectedGraph.java @@ -1,5 +1,9 @@ package graph; +import visualizationElements.Edge; +import visualizationElements.EdgeStyle; +import visualizationElements.Vertex; + import java.util.HashMap; import java.util.Objects; import java.util.PriorityQueue; @@ -7,15 +11,60 @@ import java.util.Vector; public class DirectedGraph extends Graph { + // ATTRIBUTE + + private visualizationElements.Graph screenGraph; + // KONSTRUKTOREN public DirectedGraph() { super(); + this.screenGraph = new visualizationElements.Graph(new Vector(), new Vector(), true, EdgeStyle.Direct); } public DirectedGraph(String s) { super(s); + this.screenGraph = new visualizationElements.Graph(new Vector(), new Vector(), true, EdgeStyle.Direct); + } + + + // GET-ER + + public visualizationElements.Graph getScreenGraph() { + return this.screenGraph; + } + + + // 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()); } @@ -156,8 +205,15 @@ public class DirectedGraph exten // Knoten als besucht makieren visited.put(nextVertex.getElement(), true); + + + // Logging System.out.println("Visit " + nextVertex.getElement().getName()); + + + + // Gehe von diesem Knoten aus alle erreichbaren Knoten durch for (MarkedVertex i: this.getSuccessors(nextVertex.getElement())) { @@ -179,8 +235,16 @@ public class DirectedGraph exten // Aktualisiere Distanz von Start zu nächstem Knoten distance.put(i, dist); + + + + // Logging System.out.println("Add " + i.getName() + " with " + dist + " weight to queue."); + + + + // Nehme nächsten Knoten in die Queue auf queue.add(new WrapperElement<>(i, dist)); } diff --git a/graph/Edge.java b/graph/Edge.java index b9117c7..1678d0c 100644 --- a/graph/Edge.java +++ b/graph/Edge.java @@ -42,6 +42,9 @@ public abstract class Edge { } + public abstract visualizationElements.Edge getScreenEdge(); + + // SET-ER public void setName(String s) { diff --git a/graph/Graph.java b/graph/Graph.java index 4e27005..ad4e084 100644 --- a/graph/Graph.java +++ b/graph/Graph.java @@ -89,7 +89,7 @@ public abstract class Graph { public void removeEdge(String s) throws NameDoesNotExistException{ for (MarkedEdge i: this.edges) { if (Objects.equals(i.getName(), s)) { - removeEdge(i); + this.removeEdge(i); return; } } @@ -111,7 +111,7 @@ public abstract class Graph { public void removeVertex(String s) throws NameDoesNotExistException{ for (MarkedVertex i: this.vertexes) { if (Objects.equals(i.getName(), s)) { - removeVertex(i); + this.removeVertex(i); return; } } diff --git a/graph/MarkedEdge.java b/graph/MarkedEdge.java index dfe3795..f3bf656 100644 --- a/graph/MarkedEdge.java +++ b/graph/MarkedEdge.java @@ -8,24 +8,30 @@ public class MarkedEdge extends Edge{ // Für Aufgabe 2 private int weighting; + private visualizationElements.Edge screenEdge; + // KONSTRUKTOREN public MarkedEdge() { super(); + this.screenEdge = new visualizationElements.Edge(null, null); } 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()); } + // TODO ACHTUNG DEBUG!!!! public MarkedEdge(String s, Vertex n1, Vertex n2, U u, int w) { super(s, n1, n2); this.marking = u; this.weighting = w; + this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), "u.toString()"); } @@ -42,6 +48,11 @@ public class MarkedEdge extends Edge{ } + public visualizationElements.Edge getScreenEdge() { + return this.screenEdge; + } + + // SET-ER public void setMarking(U u) { diff --git a/graph/MarkedVertex.java b/graph/MarkedVertex.java index 73081bb..8447acf 100644 --- a/graph/MarkedVertex.java +++ b/graph/MarkedVertex.java @@ -1,22 +1,45 @@ package graph; +import java.awt.*; + public class MarkedVertex extends Vertex{ // ATTRIBUTE private T marking; + private int xCord; + private int yCord; + + private visualizationElements.Vertex screenVertex; + // KONSTRUKTOREN public MarkedVertex() { super(); + this.screenVertex = new visualizationElements.Vertex(0, 0); + this.xCord = 0; + this.yCord = 0; } public MarkedVertex(String s, T t) { super(s); this.marking = t; + this.screenVertex = new visualizationElements.Vertex(0, 0, t.toString()); + this.xCord = 0; + this.yCord = 0; + } + + + // TODO ACHTUNG DEBUG!!!! + public MarkedVertex(int xCord, int yCord, String s, T t, Color color) { + super(s); + this.marking = t; + this.screenVertex = new visualizationElements.Vertex(xCord, yCord, "t.toString()", color); + this.xCord = xCord; + this.yCord = yCord; } @@ -27,6 +50,16 @@ public class MarkedVertex extends Vertex{ } + public visualizationElements.Vertex getScreenVertex() { + return this.screenVertex; + } + + + public int[] getCords() { + return new int[]{this.xCord, this.yCord}; + } + + // SET-ER public void setMarking(T t) { @@ -34,6 +67,14 @@ public class MarkedVertex extends Vertex{ } + public void setCords(int[] cords) { + this.xCord = cords[0]; + this.yCord = cords[1]; + this.screenVertex.setXpos(cords[0]); + this.screenVertex.setYpos(cords[1]); + } + + // Ausgabe public String toString() { return "MarkedVertex " + this.getName(); diff --git a/graph/UndirectedGraph.java b/graph/UndirectedGraph.java index d7874f1..ddf2f34 100644 --- a/graph/UndirectedGraph.java +++ b/graph/UndirectedGraph.java @@ -1,19 +1,69 @@ package graph; +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; + + // KONSTRUKTOREN public UndirectedGraph() { super(); + this.screenGraph = new visualizationElements.Graph(new Vector(), new Vector(), false, EdgeStyle.Direct); } public UndirectedGraph(String s) { super(s); + this.screenGraph = new visualizationElements.Graph(new Vector(), new Vector(), false, EdgeStyle.Direct); + } + + + // GET-ER + + public visualizationElements.Graph getScreenGraph() { + return this.screenGraph; + } + + + // 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()); } diff --git a/graph/Vertex.java b/graph/Vertex.java index cdf7654..1b828ed 100644 --- a/graph/Vertex.java +++ b/graph/Vertex.java @@ -26,6 +26,8 @@ public abstract class Vertex { } + public abstract visualizationElements.Vertex getScreenVertex(); + // SET-ER