Compare commits

..

No commits in common. "1f67dde5c418a4651a78471c3a93f04e450f6887" and "f00057ee6ebae983202fbad37f553947dd093aa7" have entirely different histories.

15 changed files with 95 additions and 300 deletions

24
.idea/workspace.xml generated
View File

@ -5,14 +5,15 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="LegendArea gestaltet"> <list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="LegendArea gestaltet">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurLogElement.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurLogElement.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurTextArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurTextArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/graph/DirectedGraph.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/DirectedGraph.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/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/.idea/workspace.xml" 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/OurApplication/OurParameterArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurParameterArea.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurTextArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurTextArea.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurTextArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurTextArea.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/ExampleGraphs.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/ExampleGraphs.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/MarkedEdge.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/MarkedEdge.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/graph/MarkedVertex.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/graph/MarkedVertex.class" afterDir="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" />
@ -146,15 +147,7 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1720347450647</updated> <updated>1720347450647</updated>
</task> </task>
<task id="LOCAL-00011" summary="Weighting gefixt"> <option name="localTasksCounter" value="11" />
<option name="closed" value="true" />
<created>1720362585915</created>
<option name="number" value="00011" />
<option name="presentableId" value="LOCAL-00011" />
<option name="project" value="LOCAL" />
<updated>1720362585915</updated>
</task>
<option name="localTasksCounter" value="12" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -176,8 +169,7 @@
<MESSAGE value="small fix" /> <MESSAGE value="small fix" />
<MESSAGE value="Beispiele überarbeitet" /> <MESSAGE value="Beispiele überarbeitet" />
<MESSAGE value="LegendArea gestaltet" /> <MESSAGE value="LegendArea gestaltet" />
<MESSAGE value="Weighting gefixt" /> <option name="LAST_COMMIT_MESSAGE" value="LegendArea gestaltet" />
<option name="LAST_COMMIT_MESSAGE" value="Weighting gefixt" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>

View File

@ -61,7 +61,6 @@ public class OurApplication {
JFrame frame = new JFrame("Visualise"); JFrame frame = new JFrame("Visualise");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet); frame.getContentPane().add(applet);

View File

@ -261,8 +261,7 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
if (j.getSource() == nextVertex.getElement() && j.getDestination() == i) { if (j.getSource() == nextVertex.getElement() && j.getDestination() == i) {
// Berechne Distanz zu nächstem Knoten // Berechne Distanz zu nächstem Knoten
EdgeWeightMarking marking = (EdgeWeightMarking) j.getMarking(); dist = distance.get(nextVertex.getElement()) + j.getWeighting();
dist = distance.get(nextVertex.getElement()) + marking.getWeight();
break; break;
} }
} }
@ -362,9 +361,8 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
+ Math.pow((i.getCords()[1] - n2.getCords()[1]), 2)); + Math.pow((i.getCords()[1] - n2.getCords()[1]), 2));
// Berechne Distanz zu nächstem Knoten // Berechne Distanz zu nächstem Knoten
EdgeWeightMarking marking = (EdgeWeightMarking) j.getMarking(); dist = distance.get(nextVertex.getElement()) + j.getWeighting();
dist = distance.get(nextVertex.getElement()) + marking.getWeight(); distToFinish = distance.get(nextVertex.getElement()) + j.getWeighting() + airDist;
distToFinish = distance.get(nextVertex.getElement()) + marking.getWeight() + airDist;
break; break;
} }
} }
@ -395,4 +393,11 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Gibt Distanz zu gefragtem Knoten zurück // Gibt Distanz zu gefragtem Knoten zurück
return distance.get(n2); return distance.get(n2);
} }
// Methode für das Zurücksetzten der Knotenfarben
public void clearScreenGraphColor(){
for(visualizationElements.Vertex screenVertexes : this.getScreenGraph().getVertexes()){
screenVertexes.setColor(Color.BLACK);
}
}
} }

View File

@ -52,8 +52,8 @@ public class ExampleGraphs {
} }
private void addBidirectionalEdge(DirectedGraph<VertexMarking, EdgeMarking> graph, MarkedVertex<VertexMarking> from, MarkedVertex<VertexMarking> to, EdgeWeightMarking weight) { private void addBidirectionalEdge(DirectedGraph<VertexMarking, EdgeMarking> graph, MarkedVertex<VertexMarking> from, MarkedVertex<VertexMarking> to, EdgeWeightMarking weight) {
MarkedEdge<EdgeMarking> forwardEdge = new MarkedEdge<>("edge" + from.getName() + "_" + to.getName(), from, to, weight); MarkedEdge<EdgeMarking> forwardEdge = new MarkedEdge<>("edge" + from.getName() + "_" + to.getName(), from, to, weight, weight.getWeight());
MarkedEdge<EdgeMarking> backwardEdge = new MarkedEdge<>("edge" + to.getName() + "_" + from.getName(), to, from, weight); MarkedEdge<EdgeMarking> backwardEdge = new MarkedEdge<>("edge" + to.getName() + "_" + from.getName(), to, from, weight, weight.getWeight());
graph.addEdge(forwardEdge); graph.addEdge(forwardEdge);
graph.addEdge(backwardEdge); graph.addEdge(backwardEdge);
} }
@ -88,14 +88,14 @@ public class ExampleGraphs {
example2.addVertex(F); example2.addVertex(F);
example2.addVertex(G); example2.addVertex(G);
example2.addEdge(new MarkedEdge<>("AB", A, B, new EdgeWeightMarking(1))); example2.addEdge(new MarkedEdge<>("AB", A, B, new EdgeWeightMarking(1), 1));
example2.addEdge(new MarkedEdge<>("BC", B, C, new EdgeWeightMarking(1))); example2.addEdge(new MarkedEdge<>("BC", B, C, new EdgeWeightMarking(1), 1));
example2.addEdge(new MarkedEdge<>("CD", C, D, new EdgeWeightMarking(10))); example2.addEdge(new MarkedEdge<>("CD", C, D, new EdgeWeightMarking(10), 10));
example2.addEdge(new MarkedEdge<>("DE", D, E, new EdgeWeightMarking(1))); example2.addEdge(new MarkedEdge<>("DE", D, E, new EdgeWeightMarking(1), 1));
example2.addEdge(new MarkedEdge<>("AF", A, F, new EdgeWeightMarking(5))); example2.addEdge(new MarkedEdge<>("AF", A, F, new EdgeWeightMarking(5), 5));
example2.addEdge(new MarkedEdge<>("FG", F, G, new EdgeWeightMarking(5))); example2.addEdge(new MarkedEdge<>("FG", F, G, new EdgeWeightMarking(5), 5));
example2.addEdge(new MarkedEdge<>("GE", G, E, new EdgeWeightMarking(5))); example2.addEdge(new MarkedEdge<>("GE", G, E, new EdgeWeightMarking(5), 5));
return example2; return example2;
} }
@ -160,25 +160,25 @@ public class ExampleGraphs {
example3.addVertex(E3); example3.addVertex(E3);
example3.addVertex(E4); example3.addVertex(E4);
example3.addEdge(new MarkedEdge<>("AB1", A, B1, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("AB1", A, B1, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("AB2", A, B2, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("AB2", A, B2, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("AB3", A, B3, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("AB3", A, B3, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("AB4", A, B4, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("AB4", A, B4, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("B1C1", B1, C1, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("B1C1", B1, C1, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("B2C2", B2, C2, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("B2C2", B2, C2, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("B3C3", B3, C3, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("B3C3", B3, C3, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("B4C4", B4, C4, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("B4C4", B4, C4, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("C1D1", C1, D1, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("C1D1", C1, D1, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("C2D2", C2, D2, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("C2D2", C2, D2, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("C3D3", C3, D3, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("C3D3", C3, D3, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("C4D4", C4, D4, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("C4D4", C4, D4, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("D1E1", D1, E1, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("D1E1", D1, E1, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("D2E2", D2, E2, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("D2E2", D2, E2, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("D3E3", D3, E3, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("D3E3", D3, E3, new EdgeWeightMarking(1), 1));
example3.addEdge(new MarkedEdge<>("D4E4", D4, E4, new EdgeWeightMarking(1))); example3.addEdge(new MarkedEdge<>("D4E4", D4, E4, new EdgeWeightMarking(1), 1));
return example3; return example3;
} }
@ -216,18 +216,18 @@ public class ExampleGraphs {
example4.addVertex(Dresden); example4.addVertex(Dresden);
example4.addVertex(Hannover); example4.addVertex(Hannover);
example4.addEdge(new MarkedEdge<>("Berlin-Hamburg", Berlin, Hamburg, new EdgeWeightMarking(1))); example4.addEdge(new MarkedEdge<>("Berlin-Hamburg", Berlin, Hamburg, new EdgeWeightMarking(1), 1));
example4.addEdge(new MarkedEdge<>("Berlin-München", Berlin, München, new EdgeWeightMarking(2))); example4.addEdge(new MarkedEdge<>("Berlin-München", Berlin, München, new EdgeWeightMarking(2), 1));
example4.addEdge(new MarkedEdge<>("Berlin-Köln", Berlin, Köln, new EdgeWeightMarking(3))); example4.addEdge(new MarkedEdge<>("Berlin-Köln", Berlin, Köln, new EdgeWeightMarking(3), 1));
example4.addEdge(new MarkedEdge<>("Hamburg-Frankfurt", Hamburg, Frankfurt, new EdgeWeightMarking(2))); example4.addEdge(new MarkedEdge<>("Hamburg-Frankfurt", Hamburg, Frankfurt, new EdgeWeightMarking(2), 1));
example4.addEdge(new MarkedEdge<>("Hamburg-Leipzig", Hamburg, Leipzig, new EdgeWeightMarking(3))); example4.addEdge(new MarkedEdge<>("Hamburg-Leipzig", Hamburg, Leipzig, new EdgeWeightMarking(3), 1));
example4.addEdge(new MarkedEdge<>("München-Stuttgart", München, Stuttgart, new EdgeWeightMarking(1))); example4.addEdge(new MarkedEdge<>("München-Stuttgart", München, Stuttgart, new EdgeWeightMarking(1), 1));
example4.addEdge(new MarkedEdge<>("München-Dresden", München, Dresden, new EdgeWeightMarking(2))); example4.addEdge(new MarkedEdge<>("München-Dresden", München, Dresden, new EdgeWeightMarking(2), 1));
example4.addEdge(new MarkedEdge<>("Köln-Hannover", Köln, Hannover, new EdgeWeightMarking(3))); example4.addEdge(new MarkedEdge<>("Köln-Hannover", Köln, Hannover, new EdgeWeightMarking(3), 1));
example4.addEdge(new MarkedEdge<>("Frankfurt-Stuttgart", Frankfurt, Stuttgart, new EdgeWeightMarking(1))); example4.addEdge(new MarkedEdge<>("Frankfurt-Stuttgart", Frankfurt, Stuttgart, new EdgeWeightMarking(1), 1));
example4.addEdge(new MarkedEdge<>("Stuttgart-Leipzig", Stuttgart, Leipzig, new EdgeWeightMarking(2))); example4.addEdge(new MarkedEdge<>("Stuttgart-Leipzig", Stuttgart, Leipzig, new EdgeWeightMarking(2), 1));
example4.addEdge(new MarkedEdge<>("Leipzig-Dresden", Leipzig, Dresden, new EdgeWeightMarking(1))); example4.addEdge(new MarkedEdge<>("Leipzig-Dresden", Leipzig, Dresden, new EdgeWeightMarking(1), 1));
example4.addEdge(new MarkedEdge<>("Dresden-Hannover", Dresden, Hannover, new EdgeWeightMarking(3))); example4.addEdge(new MarkedEdge<>("Dresden-Hannover", Dresden, Hannover, new EdgeWeightMarking(3), 1));
return example4; return example4;
} }

View File

@ -3,7 +3,6 @@ package graph;
import OurApplication.OurLogElement; import OurApplication.OurLogElement;
import logging.LogElementList; import logging.LogElementList;
import java.awt.*;
import java.util.*; import java.util.*;
public abstract class Graph<T extends VertexMarking, U extends EdgeMarking> { public abstract class Graph<T extends VertexMarking, U extends EdgeMarking> {
@ -266,14 +265,6 @@ public abstract class Graph<T extends VertexMarking, U extends EdgeMarking> {
} }
// Methode für das Zurücksetzten der Knotenfarben
public void clearScreenGraphColor(){
for(visualizationElements.Vertex screenVertexes : this.getScreenGraph().getVertexes()){
screenVertexes.setColor(Color.BLACK);
}
}
public abstract int getShortestPathDijkstra(MarkedVertex<T> n1, MarkedVertex<T> n2); public abstract int getShortestPathDijkstra(MarkedVertex<T> n1, MarkedVertex<T> n2);
public abstract int getShortestPathAStar(MarkedVertex<T> n1, MarkedVertex<T> n2); public abstract int getShortestPathAStar(MarkedVertex<T> n1, MarkedVertex<T> n2);

View File

@ -7,6 +7,8 @@ public class MarkedEdge<U extends EdgeMarking> extends Edge{
// ATTRIBUTE // ATTRIBUTE
private U marking; private U marking;
// Für Aufgabe 2
private int weighting;
private visualizationElements.Edge screenEdge; private visualizationElements.Edge screenEdge;
@ -22,11 +24,18 @@ public class MarkedEdge<U extends EdgeMarking> extends Edge{
public MarkedEdge(String s, Vertex n1, Vertex n2, U u) { public MarkedEdge(String s, Vertex n1, Vertex n2, U u) {
super(s, n1, n2); super(s, n1, n2);
this.marking = u; this.marking = u;
EdgeWeightMarking m = (EdgeWeightMarking) this.marking; this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex());
this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), Integer.toString(m.getWeight()), Color.BLACK);
} }
// TODO ACHTUNG DEBUG!!!!
public MarkedEdge(String s, Vertex n1, Vertex n2, U u, int weighting) {
super(s, n1, n2);
this.marking = u;
this.weighting = weighting;
this.screenEdge = new visualizationElements.Edge(n1.getScreenVertex(), n2.getScreenVertex(), Integer.toString(weighting), Color.BLACK);
}
// GET-ER // GET-ER
@ -35,6 +44,12 @@ public class MarkedEdge<U extends EdgeMarking> extends Edge{
} }
// Für Aufgabe 2
public int getWeighting() {
return this.weighting;
}
public visualizationElements.Edge getScreenEdge() { public visualizationElements.Edge getScreenEdge() {
return this.screenEdge; return this.screenEdge;
} }
@ -44,11 +59,14 @@ public class MarkedEdge<U extends EdgeMarking> extends Edge{
public void setMarking(U u) { public void setMarking(U u) {
this.marking = u; this.marking = u;
EdgeWeightMarking m = (EdgeWeightMarking) this.marking;
this.screenEdge.setMarking(Integer.toString(m.getWeight()));
} }
// Für Aufgabe 2
public void setWeighting(int w) {
this.weighting = w;
}
// Ausgabe // Ausgabe
public String toString() { public String toString() {

View File

@ -33,6 +33,7 @@ public class MarkedVertex<T extends VertexMarking> extends Vertex{
} }
// TODO ACHTUNG DEBUG!!!!
public MarkedVertex(int xCord, int yCord, String name, T t, Color color) { public MarkedVertex(int xCord, int yCord, String name, T t, Color color) {
super(name); super(name);
this.marking = t; this.marking = t;

View File

@ -6,10 +6,7 @@ import visualizationElements.Edge;
import visualizationElements.EdgeStyle; import visualizationElements.EdgeStyle;
import visualizationElements.Vertex; import visualizationElements.Vertex;
import java.awt.*;
import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Vector; import java.util.Vector;
public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> extends Graph<T, U> { public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> extends Graph<T, U> {
@ -48,24 +45,6 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
} }
public visualizationElements.Graph getScreenGraphCopy() {
visualizationElements.Graph graphCopy = new visualizationElements.Graph(new Vector<Vertex>(), new Vector<Edge>(), false, 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;
}
// HINZUFÜGEN // HINZUFÜGEN
// Kante hinzufügen // Kante hinzufügen
@ -140,196 +119,10 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
public int getShortestPathDijkstra(MarkedVertex<T> n1, MarkedVertex<T> n2) { public int getShortestPathDijkstra(MarkedVertex<T> n1, MarkedVertex<T> n2) {
return 1;
// Erstellt Hashmap um Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
// Initialisierung, dass kein Knoten besucht wurde
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
for (MarkedVertex<T> i: this.getAllVertexes()) {
distance.put(i, -1);
visited.put(i, false);
} }
// Erstelle Schlange wo die nächsten Verbindungen drin sind
PriorityQueue<WrapperElement<T>> queue = new PriorityQueue<>(new WrapperComparator<T>());
// Distanz zu Startknoten auf 0
// Weg zu Startknoten in die Schlange aufnehmen
distance.put(n1, 0);
queue.add(new WrapperElement<>(n1, 0));
// Variable, die Distanz zwischen aktuellem Knoten und Nachfolger speichert
int dist = 0;
// Zähler für LogList
int step = 0;
// String für den Description Inhalt
String textDescription;
// Färben der Start und Ziel Knoten für Visualisierung + hinzufügen zur LogList
n1.getScreenVertex().setColor(Color.RED);
n2.getScreenVertex().setColor(Color.RED);
textDescription = "Startknoten: " + n1.getScreenVertex().getMarking()
+ ", Endknoten: " + n2.getScreenVertex().getMarking();
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
while (!queue.isEmpty()) {
// Den nächsten Knoten, der am wenigsten kostet, besuchen
WrapperElement<T> nextVertex = queue.poll();
// Knoten als besucht makieren
visited.put(nextVertex.getElement(), true);
// Logging
textDescription = "Visit " + nextVertex.getElement().getName();
System.out.println(textDescription);
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
for (MarkedVertex<T> i: this.getNeighbours(nextVertex.getElement())) {
// Kante finde, die den jetzigen und nächsten Knoten verbindet
for (MarkedEdge<U> j: this.getAllEdges()) {
if (j.getSource() == nextVertex.getElement() && j.getDestination() == i) {
// Berechne Distanz zu nächstem Knoten
EdgeWeightMarking marking = (EdgeWeightMarking) j.getMarking();
dist = distance.get(nextVertex.getElement()) + marking.getWeight();
break;
}
}
// Wenn es schon einen kürzeren Weg zum Knoten gibt, überspringen
if ((distance.get(i) <= dist && distance.get(i) != -1) || visited.get(i)) {
continue;
}
// Aktualisiere Distanz von Start zu nächstem Knoten
distance.put(i, dist);
// Logging
textDescription = "Add " + i.getName() + " with " + dist + " weight to queue.";
System.out.println(textDescription);
i.getScreenVertex().setColor(Color.YELLOW);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf
queue.add(new WrapperElement<>(i, dist));
}
}
//zurücksetzten der Färbungen
this.clearScreenGraphColor();
System.out.println("Done");
// Gibt Distanz zu gefragtem Knoten zurück
return distance.get(n2);
}
public int getShortestPathAStar(MarkedVertex<T> n1, MarkedVertex<T> n2) { public int getShortestPathAStar(MarkedVertex<T> n1, MarkedVertex<T> n2) {
return 2;
// Erstellt Hashmap um Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
// Initialisierung, dass kein Knoten besucht wurde
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
for (MarkedVertex<T> i: this.getAllVertexes()) {
distance.put(i, -1);
visited.put(i, false);
}
// Erstelle Schlange wo die nächsten Verbindungen drin sind
PriorityQueue<WrapperElement<T>> queue = new PriorityQueue<>(new WrapperComparator<T>());
// Distanz zu Startknoten auf 0
// Weg zu Startknoten in die Schlange aufnehmen
distance.put(n1, 0);
queue.add(new WrapperElement<>(n1, 0));
// Variable, die Distanz zwischen aktuellem Knoten und Nachfolger speichert
int dist = 0;
// Variable, die Distanz zwischen dem potenziell nächsten Knoten und dem Zielknoten speichert
int airDist = 0;
// Variable, die Distanz zwischen dem aktuellen Knoten bis zum Endknoten speichert
int distToFinish = 0;
// Zähler für LogList
int step = 0;
// String für den Description Inhalt
String textDescription;
// Färben der Start und Ziel Knoten für Visualisierung + hinzufügen zur LogList
n1.getScreenVertex().setColor(Color.RED);
n2.getScreenVertex().setColor(Color.RED);
textDescription = "Startknoten: " + n1.getScreenVertex().getMarking()
+ ", Endknoten: " + n2.getScreenVertex().getMarking();
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
while (!queue.isEmpty()) {
// Den nächsten Knoten, der am wenigsten kostet, besuchen
WrapperElement<T> nextVertex = queue.poll();
// Knoten als besucht makieren
visited.put(nextVertex.getElement(), true);
// Logging
textDescription = "Visit " + nextVertex.getElement().getName();
System.out.println(textDescription);
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
for (MarkedVertex<T> i: this.getNeighbours(nextVertex.getElement())) {
// Kante finde, die den jetzigen und nächsten Knoten verbindet
for (MarkedEdge<U> j: this.getAllEdges()) {
if (j.getSource() == nextVertex.getElement() && j.getDestination() == i) {
//Berechnung der Heuristik über die Luftdistanz des nächsten Knoten zum Zielknoten
airDist = (int) Math.sqrt(Math.pow((i.getCords()[0] - n2.getCords()[0]), 2)
+ Math.pow((i.getCords()[1] - n2.getCords()[1]), 2));
// Berechne Distanz zu nächstem Knoten
EdgeWeightMarking marking = (EdgeWeightMarking) j.getMarking();
dist = distance.get(nextVertex.getElement()) + marking.getWeight();
distToFinish = distance.get(nextVertex.getElement()) + marking.getWeight() + airDist;
break;
}
}
// Wenn es schon einen kürzeren Weg zum Knoten gibt, überspringen
if ((distance.get(i) <= dist && distance.get(i) != -1) || visited.get(i)) {
continue;
}
// Aktualisiere Distanz von Start zu nächstem Knoten
distance.put(i, dist);
// Logging
textDescription = "Add " + i.getName() + " with " + dist + " weight to queue.";
System.out.println(textDescription);
i.getScreenVertex().setColor(Color.YELLOW);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Nehme nächsten Knoten in die Queue auf
queue.add(new WrapperElement<>(i, distToFinish));
}
}
//zurücksetzten der Färbungen
this.clearScreenGraphColor();
System.out.println("Done");
// Gibt Distanz zu gefragtem Knoten zurück
return distance.get(n2);
} }
} }

View File

@ -6,14 +6,10 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="LegendArea gestaltet"> <list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="LegendArea gestaltet">
<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/OurLogElement.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurLogElement.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/OurApplication/OurLegendArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurLegendArea.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/OurApplication/OurTextArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurTextArea.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$/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/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurLegendArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurLegendArea.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/OurApplication/OurParameterArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurParameterArea.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurTextArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurTextArea.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" />
</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" />
@ -38,17 +34,17 @@
<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">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;Application.Display.executor&quot;: &quot;Run&quot;, "Application.Display.executor": "Run",
&quot;Application.OurApplication.executor&quot;: &quot;Debug&quot;, "Application.OurApplication.executor": "Debug",
&quot;Application.OurLegendArea.executor&quot;: &quot;Run&quot;, "Application.OurLegendArea.executor": "Run",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "main",
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;, "kotlin-language-version-configured": "true",
&quot;last_opened_file_path&quot;: &quot;C:/Git/ProjektGraphMain&quot; "last_opened_file_path": "C:/Git/ProjektGraphMain"
} }
}</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" />
@ -177,7 +173,7 @@
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/OurApplication/OurApplication.java</url> <url>file://$PROJECT_DIR$/OurApplication/OurApplication.java</url>
<line>49</line> <line>49</line>
<option name="timeStamp" value="2" /> <option name="timeStamp" value="1" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>
</breakpoint-manager> </breakpoint-manager>