Stable Version 3.0
This commit is contained in:
parent
0d5ff33a9d
commit
98edc9a28d
23
.idea/workspace.xml
generated
23
.idea/workspace.xml
generated
@ -9,16 +9,11 @@
|
||||
<change beforePath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurAlgorithm.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/OurApplication/OurApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurApplication.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurDrawArea.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/OurApplication/OurHybridWindow.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurHybridWindow.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/OurApplication/OurLogElement.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurLogElement.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/OurApplication/OurParameterArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurParameterArea.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/graph/DirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/DirectedGraph.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/graph/Edge.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/Edge.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/graph/Graph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/Graph.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/graph/MarkedEdge.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/MarkedEdge.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/graph/MarkedVertex.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/MarkedVertex.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/graph/UndirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/UndirectedGraph.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/graph/Vertex.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/Vertex.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -37,16 +32,16 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Application.Display.executor": "Run",
|
||||
"Application.OurApplication.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "Versuch__Christian",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Git/ProjektGraphMain"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"Application.Display.executor": "Run",
|
||||
"Application.OurApplication.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "Versuch__Christian",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Git/ProjektGraphMain"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="C:\Git\ProjektGraph" />
|
||||
|
@ -3,6 +3,7 @@ package OurApplication;
|
||||
import graph.*;
|
||||
import logging.Algorithm;
|
||||
import logging.LogElementList;
|
||||
import visualizationElements.Vertex;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
@ -16,7 +17,9 @@ import java.util.Vector;
|
||||
* DHBW Stuttgart/Campus Horb AI2008<br>
|
||||
* <br>
|
||||
*/
|
||||
public class OurAlgorithm extends Algorithm{
|
||||
public class OurAlgorithm extends Algorithm {
|
||||
|
||||
private graph.Graph<VertexMarking, EdgeMarking> currentGraph;
|
||||
|
||||
public OurAlgorithm() {
|
||||
super();
|
||||
@ -36,14 +39,23 @@ public class OurAlgorithm extends Algorithm{
|
||||
* Adds integer number starting with 0 up to the maximum value.
|
||||
* @return a LogElementList containing the algorithm processing single steps
|
||||
*/
|
||||
public LogElementList<OurLogElement> run() {
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
MarkedVertex<VertexMarking> start = this.currentGraph.getAllVertexes().get(random.nextInt(this.currentGraph.getAllVertexes().size()));
|
||||
MarkedVertex<VertexMarking> end = this.currentGraph.getAllVertexes().get(random.nextInt(this.currentGraph.getAllVertexes().size()));
|
||||
System.out.println(start.getName() + " to " + end.getName());
|
||||
|
||||
this.currentGraph.getShortestPathDijkstra(start, end);
|
||||
|
||||
return this.currentGraph.getLogList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public LogElementList<OurLogElement> run(){
|
||||
LogElementList<OurLogElement> logList = new LogElementList<OurLogElement>();
|
||||
|
||||
// Hier müssen die Loggingelemente von Dikstra ankommen.
|
||||
return logList;
|
||||
public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) {
|
||||
this.currentGraph = graph;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
package OurApplication;
|
||||
|
||||
import graph.*;
|
||||
import logging.LogElementList;
|
||||
import visualisation.HybridWindow;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This application provides an example for using logging and visualization packages.
|
||||
@ -56,6 +59,29 @@ public class OurApplication {
|
||||
frame.setVisible(true);
|
||||
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
DirectedGraph<VertexMarking, EdgeMarking> myGraph = new DirectedGraph<>();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
myGraph.addVertex(new MarkedVertex<>(random.nextInt(1, 10)*40, random.nextInt(1, 10)*40, Integer.toString(i), null, Color.BLACK));
|
||||
}
|
||||
|
||||
for (MarkedVertex<VertexMarking> i: myGraph.getAllVertexes()) {
|
||||
myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10)));
|
||||
}
|
||||
/*
|
||||
for (MarkedVertex<VertexMarking> i: myGraph.getAllVertexes()) {
|
||||
myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10)));
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
System.out.println(myGraph.toString());
|
||||
|
||||
drawArea.setCurrentGraph(myGraph);
|
||||
algorithm.setCurrentGraph(myGraph);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package OurApplication;
|
||||
|
||||
import graph.*;
|
||||
import graph.Graph;
|
||||
import logging.LogElementList;
|
||||
import visualisation.DrawArea;
|
||||
import visualizationElements.*;
|
||||
import visualizationElements.Graph;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
@ -21,6 +21,8 @@ public class OurDrawArea extends DrawArea{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private graph.Graph<VertexMarking, EdgeMarking> currentGraph;
|
||||
|
||||
|
||||
/**
|
||||
* Standard constructor.
|
||||
@ -38,39 +40,37 @@ public class OurDrawArea extends DrawArea{
|
||||
super(logList, drawAreaName);
|
||||
}
|
||||
|
||||
|
||||
public void setCurrentGraph(Graph<VertexMarking, EdgeMarking> graph) {
|
||||
this.currentGraph = graph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a visualization element.
|
||||
*/
|
||||
|
||||
public void draw(Graphics g) {
|
||||
|
||||
Random random = new Random();
|
||||
this.currentGraph.getScreenGraph().draw(g);
|
||||
|
||||
DirectedGraph<VertexMarking, EdgeMarking> myGraph = new DirectedGraph<>();
|
||||
OurLogElement logElement = (OurLogElement) logList.get();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
myGraph.addVertex(new MarkedVertex<>(random.nextInt(1, 10)*35, random.nextInt(1, 10)*35, "", null, Color.BLACK));
|
||||
}
|
||||
if (logElement.getVertex() != null) {
|
||||
if (logElement.getVertex().getColor() == Color.BLACK) {
|
||||
logElement.getVertex().setColor(Color.YELLOW);
|
||||
} else if (logElement.getVertex().getColor() == Color.YELLOW) {
|
||||
logElement.getVertex().setColor(Color.BLUE);
|
||||
}
|
||||
} else {
|
||||
if (logElement.getEdge().getColor() == Color.BLACK) {
|
||||
logElement.getEdge().setColor(Color.YELLOW);
|
||||
} else if (logElement.getEdge().getColor() == Color.YELLOW) {
|
||||
logElement.getEdge().setColor(Color.BLUE);
|
||||
}
|
||||
}
|
||||
|
||||
for (MarkedVertex<VertexMarking> i: myGraph.getAllVertexes()) {
|
||||
myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10)));
|
||||
}
|
||||
|
||||
for (MarkedVertex<VertexMarking> i: myGraph.getAllVertexes()) {
|
||||
myGraph.addEdge(new MarkedEdge<>("a", i, myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size())), null, random.nextInt(1, 10)));
|
||||
}
|
||||
|
||||
System.out.println(myGraph.toString());
|
||||
|
||||
MarkedVertex<VertexMarking> start = myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size()));
|
||||
MarkedVertex<VertexMarking> end = myGraph.getAllVertexes().get(random.nextInt(myGraph.getAllVertexes().size()));
|
||||
System.out.println(start.getName() + " to " + end.getName());
|
||||
|
||||
System.out.println(myGraph.getShortestPathDijkstra(start, end));
|
||||
|
||||
myGraph.getScreenGraph().draw(g);
|
||||
|
||||
// OurLogElement logElement = (OurLogElement) logList.get();
|
||||
logElement.getVertex().draw(g);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import graph.DirectedGraph;
|
||||
import graph.EdgeMarking;
|
||||
import graph.VertexMarking;
|
||||
import logging.LogElement;
|
||||
import visualizationElements.Edge;
|
||||
import visualizationElements.Vertex;
|
||||
|
||||
/**
|
||||
* This class provides an example for using logging.LogElement.
|
||||
@ -18,7 +20,8 @@ public class OurLogElement extends LogElement{
|
||||
|
||||
/** The log elements sum up value. */
|
||||
protected long value;
|
||||
protected DirectedGraph<VertexMarking, EdgeMarking> ourGraph;
|
||||
protected Vertex vertex;
|
||||
protected Edge edge;
|
||||
|
||||
/**
|
||||
* Standard constructor.
|
||||
@ -26,7 +29,7 @@ public class OurLogElement extends LogElement{
|
||||
*/
|
||||
public OurLogElement() {
|
||||
super();
|
||||
value=0;
|
||||
this.value = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,11 +39,19 @@ public class OurLogElement extends LogElement{
|
||||
* @param description the log element's step description
|
||||
* @param value the log element's sum up value
|
||||
*/
|
||||
public OurLogElement(int step, String description, long value, DirectedGraph<VertexMarking, EdgeMarking> ourGraph){
|
||||
public OurLogElement(int step, String description, long value, Vertex v){
|
||||
this.step = step;
|
||||
this.description = description;
|
||||
this.value = value;
|
||||
this.ourGraph = ourGraph;
|
||||
this.vertex = v;
|
||||
}
|
||||
|
||||
|
||||
public OurLogElement(int step, String description, long value, Edge e){
|
||||
this.step = step;
|
||||
this.description = description;
|
||||
this.value = value;
|
||||
this.edge = e;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,12 +59,16 @@ public class OurLogElement extends LogElement{
|
||||
* @return the log element's sum up value
|
||||
*/
|
||||
public long getValue(){
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
|
||||
public DirectedGraph<VertexMarking, EdgeMarking> getGraph(){
|
||||
return this.ourGraph;
|
||||
public Edge getEdge() {
|
||||
return this.edge;
|
||||
}
|
||||
|
||||
|
||||
public Vertex getVertex() {
|
||||
return this.vertex;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
package graph;
|
||||
|
||||
import OurApplication.OurAlgorithm;
|
||||
import OurApplication.OurLogElement;
|
||||
import logging.LogElementList;
|
||||
import visualizationElements.Edge;
|
||||
import visualizationElements.EdgeStyle;
|
||||
import visualizationElements.Vertex;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.PriorityQueue;
|
||||
@ -14,18 +18,22 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
|
||||
// ATTRIBUTE
|
||||
|
||||
private visualizationElements.Graph screenGraph;
|
||||
private LogElementList<OurLogElement> logList;
|
||||
|
||||
|
||||
// KONSTRUKTOREN
|
||||
|
||||
public DirectedGraph() {
|
||||
super();
|
||||
this.screenGraph = new visualizationElements.Graph(new Vector<Vertex>(), new Vector<Edge>(), true, EdgeStyle.Direct);
|
||||
this.logList = new LogElementList<OurLogElement>();
|
||||
}
|
||||
|
||||
|
||||
public DirectedGraph(String s) {
|
||||
super(s);
|
||||
this.screenGraph = new visualizationElements.Graph(new Vector<Vertex>(), new Vector<Edge>(), true, EdgeStyle.Direct);
|
||||
this.logList = new LogElementList<OurLogElement>();
|
||||
}
|
||||
|
||||
|
||||
@ -36,6 +44,11 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
|
||||
}
|
||||
|
||||
|
||||
public LogElementList<OurLogElement> getLogList() {
|
||||
return this.logList;
|
||||
}
|
||||
|
||||
|
||||
// HINZUFÜGEN
|
||||
|
||||
// Kante hinzufügen
|
||||
@ -197,6 +210,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
|
||||
|
||||
// Variable, die Distanz zwischen aktuellem Knoten und Nachfolger speichert
|
||||
int dist = 0;
|
||||
// Zähler für LogList
|
||||
int step = 0;
|
||||
visualizationElements.Graph display;
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
// Den nächsten Knoten, der am wenigsten kostet, besuchen
|
||||
@ -206,12 +222,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
|
||||
visited.put(nextVertex.getElement(), true);
|
||||
|
||||
|
||||
|
||||
// Logging
|
||||
System.out.println("Visit " + nextVertex.getElement().getName());
|
||||
|
||||
|
||||
|
||||
this.logList.add(new OurLogElement(step, "Step: " + step, 0, nextVertex.getElement().getScreenVertex()));
|
||||
|
||||
|
||||
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
|
||||
@ -235,21 +248,16 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> 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.");
|
||||
|
||||
|
||||
|
||||
|
||||
this.logList.add(new OurLogElement(step, "Step: " + step, 0, nextVertex.getElement().getScreenVertex()));
|
||||
|
||||
// Nehme nächsten Knoten in die Queue auf
|
||||
queue.add(new WrapperElement<>(i, dist));
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Done");
|
||||
// Gibt Distanz zu gefragtem Knoten zurück
|
||||
return distance.get(n2);
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package graph;
|
||||
|
||||
import OurApplication.OurLogElement;
|
||||
import logging.LogElementList;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class Graph<T extends VertexMarking, U extends EdgeMarking> {
|
||||
@ -42,6 +45,12 @@ public abstract class Graph<T extends VertexMarking, U extends EdgeMarking> {
|
||||
}
|
||||
|
||||
|
||||
public abstract visualizationElements.Graph getScreenGraph();
|
||||
|
||||
|
||||
public abstract LogElementList<OurLogElement> getLogList();
|
||||
|
||||
|
||||
// SET-ER
|
||||
|
||||
public void setName(String s) {
|
||||
@ -255,4 +264,7 @@ public abstract class Graph<T extends VertexMarking, U extends EdgeMarking> {
|
||||
throw new NameDoesNotExistException("One of the Vertexes might not exist");
|
||||
}
|
||||
|
||||
|
||||
public abstract int getShortestPathDijkstra(MarkedVertex<T> n1, MarkedVertex<T> n2);
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package graph;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class MarkedEdge<U extends EdgeMarking> extends Edge{
|
||||
|
||||
// ATTRIBUTE
|
||||
@ -31,7 +33,7 @@ public class MarkedEdge<U extends EdgeMarking> extends Edge{
|
||||
super(s, n1, n2);
|
||||
this.marking = u;
|
||||
this.weighting = w;
|
||||
this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), "u.toString()");
|
||||
this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), "u.toString()", Color.BLACK);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package graph;
|
||||
|
||||
import OurApplication.OurLogElement;
|
||||
import logging.LogElementList;
|
||||
import visualizationElements.Edge;
|
||||
import visualizationElements.EdgeStyle;
|
||||
import visualizationElements.Vertex;
|
||||
@ -12,6 +14,7 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
|
||||
// ATTRIBUTE
|
||||
|
||||
private visualizationElements.Graph screenGraph;
|
||||
private LogElementList<OurLogElement> logList;
|
||||
|
||||
|
||||
// KONSTRUKTOREN
|
||||
@ -19,12 +22,14 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
|
||||
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<>();
|
||||
}
|
||||
|
||||
|
||||
@ -35,6 +40,11 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
|
||||
}
|
||||
|
||||
|
||||
public LogElementList<OurLogElement> getLogList() {
|
||||
return this.logList;
|
||||
}
|
||||
|
||||
|
||||
// HINZUFÜGEN
|
||||
|
||||
// Kante hinzufügen
|
||||
@ -107,4 +117,9 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
|
||||
return neighbours;
|
||||
}
|
||||
|
||||
|
||||
public int getShortestPathDijkstra(MarkedVertex<T> n1, MarkedVertex<T> n2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user