Stable Version with finished visualisation

This commit is contained in:
i23007 2024-07-04 21:18:57 +02:00
parent 58ed89d78c
commit bed270e7d2
12 changed files with 124 additions and 78 deletions

53
.idea/workspace.xml generated
View File

@ -6,13 +6,17 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Adding AStar Algorithm"> <list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Adding AStar Algorithm">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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/OurLogElement.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurLogElement.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/DirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/DirectedGraph.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/Display.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/graph/UndirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/UndirectedGraph.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurAlgorithm.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurAlgorithm.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurApplication.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurApplication.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurDrawArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurDrawArea.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurLogElement.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurLogElement.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/DirectedGraph.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/DirectedGraph.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/DirectedGraph.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/DirectedGraph.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/Graph.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/Graph.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/Display.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/UndirectedGraph.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/UndirectedGraph.class" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -32,16 +36,16 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"Application.Display.executor": "Run", &quot;Application.Display.executor&quot;: &quot;Run&quot;,
"Application.OurApplication.executor": "Run", &quot;Application.OurApplication.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"git-widget-placeholder": "main", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"kotlin-language-version-configured": "true", &quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
"last_opened_file_path": "C:/Git/ProjektGraphMain" &quot;last_opened_file_path&quot;: &quot;C:/Git/ProjektGraphMain&quot;
} }
}]]></component> }</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="C:\Git\ProjektGraph" /> <recent name="C:\Git\ProjektGraph" />
@ -84,7 +88,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1720036227325</updated> <updated>1720036227325</updated>
</task> </task>
<option name="localTasksCounter" value="4" /> <task id="LOCAL-00004" summary="Adding AStar Algorithm">
<option name="closed" value="true" />
<created>1720042374225</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1720042374225</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -103,4 +115,15 @@
<MESSAGE value="Adding AStar Algorithm" /> <MESSAGE value="Adding AStar Algorithm" />
<option name="LAST_COMMIT_MESSAGE" value="Adding AStar Algorithm" /> <option name="LAST_COMMIT_MESSAGE" value="Adding AStar Algorithm" />
</component> </component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/OurApplication/OurDrawArea.java</url>
<line>53</line>
<option name="timeStamp" value="3" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project> </project>

View File

@ -79,7 +79,7 @@ public class OurApplication {
System.out.println(myGraph.toString()); System.out.println(myGraph.toString());
drawArea.setCurrentGraph(myGraph); drawArea.setCurrentGraph(myGraph.getScreenGraph());
algorithm.setCurrentGraph(myGraph); algorithm.setCurrentGraph(myGraph);
} }

View File

@ -21,7 +21,7 @@ public class OurDrawArea extends DrawArea{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private graph.Graph<VertexMarking, EdgeMarking> currentGraph; private visualizationElements.Graph currentGraph;
/** /**
@ -41,7 +41,7 @@ public class OurDrawArea extends DrawArea{
} }
public void setCurrentGraph(Graph<VertexMarking, EdgeMarking> graph) { public void setCurrentGraph(visualizationElements.Graph graph) {
this.currentGraph = graph; this.currentGraph = graph;
} }
@ -51,25 +51,8 @@ public class OurDrawArea extends DrawArea{
public void draw(Graphics g) { public void draw(Graphics g) {
this.currentGraph.getScreenGraph().draw(g);
OurLogElement logElement = (OurLogElement) logList.get(); OurLogElement logElement = (OurLogElement) logList.get();
logElement.getGraph().draw(g);
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);
}
}
logElement.getVertex().draw(g);
} }

View File

@ -22,6 +22,7 @@ public class OurLogElement extends LogElement{
protected long value; protected long value;
protected Vertex vertex; protected Vertex vertex;
protected Edge edge; protected Edge edge;
protected visualizationElements.Graph ourGraph;
/** /**
* Standard constructor. * Standard constructor.
@ -47,12 +48,20 @@ public class OurLogElement extends LogElement{
} }
public OurLogElement(int step, String description, long value, Edge e){ public OurLogElement(int step, String description, long value, Edge e){
this.step = step; this.step = step;
this.description = description; this.description = description;
this.value = value; this.value = value;
this.edge = e; this.edge = e;
} }
public OurLogElement(int step, String description, long value, visualizationElements.Graph ourGraph ){
this.step = step;
this.description = description;
this.value = value;
this.ourGraph = ourGraph;
}
/** /**
* Returns the log element's sum up value. * Returns the log element's sum up value.
@ -71,4 +80,9 @@ public class OurLogElement extends LogElement{
public Vertex getVertex() { public Vertex getVertex() {
return this.vertex; return this.vertex;
} }
public visualizationElements.Graph getGraph() {
return this.ourGraph;
}
} }

View File

@ -8,6 +8,7 @@ import visualizationElements.EdgeStyle;
import visualizationElements.Vertex; import visualizationElements.Vertex;
import java.awt.*; import java.awt.*;
import java.io.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import java.util.PriorityQueue; import java.util.PriorityQueue;
@ -43,6 +44,23 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
return this.screenGraph; return this.screenGraph;
} }
public visualizationElements.Graph getScreenGraphCopy() {
visualizationElements.Graph graphCopy = new visualizationElements.Graph(new Vector<Vertex>(), new Vector<Edge>(), true, EdgeStyle.Direct);
Vector<visualizationElements.Vertex> copiedVertexes = new Vector<>();
Vector<visualizationElements.Edge> copiedEdges = new Vector<>();
for (visualizationElements.Vertex vertexCopy : this.screenGraph.getVertexes()) {
visualizationElements.Vertex newCopiedVertex = new visualizationElements.Vertex(vertexCopy.getXpos(), vertexCopy.getYpos(), vertexCopy.getMarking(), vertexCopy.getColor());
copiedVertexes.add(newCopiedVertex);
graphCopy.setVertexes(copiedVertexes);
}
for (visualizationElements.Edge edgeCopy : this.screenGraph.getEdges()) {
visualizationElements.Edge newCopiedEdge = new visualizationElements.Edge(edgeCopy.getSource(), edgeCopy.getDestination(), edgeCopy.getMarking(), edgeCopy.getColor());
copiedEdges.add(newCopiedEdge);
graphCopy.setEdges(copiedEdges);
}
return graphCopy;
}
public LogElementList<OurLogElement> getLogList() { public LogElementList<OurLogElement> getLogList() {
return this.logList; return this.logList;
@ -212,7 +230,6 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
int dist = 0; int dist = 0;
// Zähler für LogList // Zähler für LogList
int step = 0; int step = 0;
visualizationElements.Graph display;
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
// Den nächsten Knoten, der am wenigsten kostet, besuchen // Den nächsten Knoten, der am wenigsten kostet, besuchen
@ -224,7 +241,8 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Logging // Logging
System.out.println("Visit " + nextVertex.getElement().getName()); System.out.println("Visit " + nextVertex.getElement().getName());
this.logList.add(new OurLogElement(step, "Step: " + step, 0, nextVertex.getElement().getScreenVertex())); nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
this.logList.add(new OurLogElement(step, "Step: " + step, 0, this.getScreenGraphCopy()));
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch // Gehe von diesem Knoten aus alle erreichbaren Knoten durch
@ -250,7 +268,8 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Logging // Logging
System.out.println("Add " + i.getName() + " with " + dist + " weight to queue."); System.out.println("Add " + i.getName() + " with " + dist + " weight to queue.");
this.logList.add(new OurLogElement(step, "Step: " + step, 0, nextVertex.getElement().getScreenVertex())); nextVertex.getElement().getScreenVertex().setColor(Color.YELLOW);
this.logList.add(new OurLogElement(step, "Step: " + step, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf // Nehme nächsten Knoten in die Queue auf
queue.add(new WrapperElement<>(i, dist)); queue.add(new WrapperElement<>(i, dist));
@ -288,7 +307,6 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
int airDist = 0; int airDist = 0;
// Zähler für LogList // Zähler für LogList
int step = 0; int step = 0;
visualizationElements.Graph display;
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
// Den nächsten Knoten, der am wenigsten kostet, besuchen // Den nächsten Knoten, der am wenigsten kostet, besuchen
@ -300,7 +318,8 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Logging // Logging
System.out.println("Visit " + nextVertex.getElement().getName()); System.out.println("Visit " + nextVertex.getElement().getName());
this.logList.add(new OurLogElement(step, "Step: " + step, 0, nextVertex.getElement().getScreenVertex())); nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
this.logList.add(new OurLogElement(step, "Step: " + step, 0, this.getScreenGraphCopy()));
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch // Gehe von diesem Knoten aus alle erreichbaren Knoten durch
@ -330,7 +349,8 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Logging // Logging
System.out.println("Add " + i.getName() + " with " + dist + " weight to queue."); System.out.println("Add " + i.getName() + " with " + dist + " weight to queue.");
this.logList.add(new OurLogElement(step, "Step: " + step, 0, nextVertex.getElement().getScreenVertex())); nextVertex.getElement().getScreenVertex().setColor(Color.YELLOW);
this.logList.add(new OurLogElement(step, "Step: " + step, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf // Nehme nächsten Knoten in die Queue auf
queue.add(new WrapperElement<>(i, dist)); queue.add(new WrapperElement<>(i, dist));

View File

@ -1,32 +0,0 @@
package graph;
import java.util.Random;
public class Display {
public static void main(String[] args) {
DirectedGraph<VertexMarking, EdgeMarking> myGraph = new DirectedGraph<>();
for (int i = 0; i < 10; i++) {
myGraph.addVertex(new MarkedVertex<>(String.valueOf(i), null));
}
Random random = new Random();
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));
}
}

View File

@ -4,11 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment=""> <list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="Adding AStar Algorithm">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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/OurDrawArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurDrawArea.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/Display.java" beforeDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -17,6 +16,7 @@
</component> </component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="RESET_MODE" value="HARD" />
</component> </component>
<component name="ProjectColorInfo">{ <component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 2 &quot;associatedIndex&quot;: 2
@ -32,7 +32,7 @@
&quot;Application.Display.executor&quot;: &quot;Run&quot;, &quot;Application.Display.executor&quot;: &quot;Run&quot;,
&quot;Application.OurApplication.executor&quot;: &quot;Run&quot;, &quot;Application.OurApplication.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;Versuch__Christian&quot;, &quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;, &quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Git/ProjektGraphMain&quot; &quot;last_opened_file_path&quot;: &quot;C:/Git/ProjektGraphMain&quot;
} }
@ -55,6 +55,39 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1718547365327</updated> <updated>1718547365327</updated>
</task> </task>
<task id="LOCAL-00001" summary="Stable Version 3.0">
<option name="closed" value="true" />
<created>1720028543313</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1720028543313</updated>
</task>
<task id="LOCAL-00002" summary="Adding AStar Algorithm">
<option name="closed" value="true" />
<created>1720036191925</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1720036191926</updated>
</task>
<task id="LOCAL-00003" summary="Adding AStar Algorithm">
<option name="closed" value="true" />
<created>1720036227325</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1720036227325</updated>
</task>
<task id="LOCAL-00004" summary="Adding AStar Algorithm">
<option name="closed" value="true" />
<created>1720042374225</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1720042374225</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -68,4 +101,9 @@
</map> </map>
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Stable Version 3.0" />
<MESSAGE value="Adding AStar Algorithm" />
<option name="LAST_COMMIT_MESSAGE" value="Adding AStar Algorithm" />
</component>
</project> </project>