Compare commits

...

2 Commits

Author SHA1 Message Date
cmerkens
1313402f07 Merge branch 'main' of https://gitea.hb.dhbw-stuttgart.de/i23024/ProjektGraph
# Conflicts:
#	OurApplication/OurAlgorithm.java
#	OurApplication/OurApplication.java
#	graph/ExampleGraphs.java
#	out/production/ProjektGraph/OurApplication/OurAlgorithm.class
#	out/production/ProjektGraph/OurApplication/OurApplication.class
#	out/production/ProjektGraph/OurApplication/OurParameterArea.class
#	out/production/ProjektGraph/graph/ExampleGraphs.class
2024-07-07 20:43:35 +02:00
cmerkens
ecf2bb8656 Endgültiger Weg wird angezeigt 2024-07-07 20:34:38 +02:00
17 changed files with 216 additions and 53 deletions

View File

@ -5,13 +5,18 @@
</component>
<component name="ChangeListManager">
<list default="true" id="70f8ea87-9ffc-471a-8059-ebbfc323adcc" name="Changes" comment="LegendArea gestaltet">
<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/OurTextArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurTextArea.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<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/OurLegendArea.java" beforeDir="false" afterPath="$PROJECT_DIR$/OurApplication/OurLegendArea.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/ExampleGraphs.java" beforeDir="false" afterPath="$PROJECT_DIR$/graph/ExampleGraphs.java" afterDir="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/OurApplication/OurParameterArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurParameterArea.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>
<option name="SHOW_DIALOG" value="false" />
@ -37,17 +42,17 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Application.Display.executor&quot;: &quot;Run&quot;,
&quot;Application.OurApplication.executor&quot;: &quot;Debug&quot;,
&quot;Application.OurLegendArea.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Git/ProjektGraphMain&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Application.Display.executor": "Run",
"Application.OurApplication.executor": "Run",
"Application.OurLegendArea.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "main",
"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" />
@ -179,15 +184,4 @@
<MESSAGE value="Weighting gefixt" />
<option name="LAST_COMMIT_MESSAGE" value="Weighting gefixt" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/OurApplication/OurApplication.java</url>
<line>49</line>
<option name="timeStamp" value="2" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>

View File

@ -6,6 +6,7 @@ import logging.LogElementList;
import visualizationElements.Vertex;
import java.awt.*;
import java.util.Objects;
import java.util.Random;
import java.util.Vector;
@ -47,12 +48,28 @@ public class OurAlgorithm extends Algorithm {
this.setCurrentGraph(currentParameterArea.getSelectedGraph());
MarkedVertex<VertexMarking> start = null;
for (MarkedVertex<VertexMarking> i: this.currentGraph.getAllVertexes()) {
if (Objects.equals(i.getName(), "Start")) {
start = i;
}
}
MarkedVertex<VertexMarking> end = null;
for (MarkedVertex<VertexMarking> i: this.currentGraph.getAllVertexes()) {
if (Objects.equals(i.getName(), "Ende")) {
end = i;
}
}
/*
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());
*/
if(this.methodButtons.getSelectedMethod()){
this.currentGraph.getShortestPathDijkstra(start, end);
}else{
@ -66,5 +83,6 @@ public class OurAlgorithm extends Algorithm {
public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) {
this.currentGraph = graph;
}
}

View File

@ -3,8 +3,11 @@ package OurApplication;
import graph.*;
import logging.LogElementList;
import visualisation.HybridWindow;
import visualizationElements.Vertex;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;
/**
@ -69,27 +72,9 @@ public class OurApplication {
frame.pack();
applet.init();
applet.start();
frame.setSize(800,600);
frame.setSize(1000,800);
frame.setVisible(true);
/*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)));
}
*/
}
}

View File

@ -3,8 +3,12 @@ package OurApplication;
import logging.LogElementList;
import visualisation.DrawArea;
import visualizationElements.Edge;
import visualizationElements.Vertex;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**

View File

@ -60,6 +60,14 @@ public class OurLegendArea extends LegendArea{
g.drawOval(10, y, 20, 20); // Zeichnet den Rand des Kreises
g.drawString("Erreichbare Knoten", 40, y + 15); // Zeichnet die Beschreibung neben dem Kreis
// Zeichnet den grünen Knoten (Fertiger Weg)
y += 40; // Nach unten verschieben für das nächste Element
g.setColor(Color.green);
g.fillOval(10, y, 20, 20); // Zeichnet einen kleinen Kreis (Knoten) mit der Farbe des Elements
g.setColor(Color.BLACK);
g.drawOval(10, y, 20, 20); // Zeichnet den Rand des Kreises
g.drawString("Fertiger Weg", 40, y + 15); // Zeichnet die Beschreibung neben dem Kreis
// Zeichnet die schwarze Linie (Kanten Markierung)
y += 40; // Nach unten verschieben für das nächste Element
g.setColor(Color.BLACK);

View File

@ -26,6 +26,7 @@ public class OurParameterArea extends ParameterArea{
private JRadioButton button2;
private JRadioButton button3;
private JRadioButton button4;
private JRadioButton button5;
private ExampleGraphs temp;
private int selectedExample;
@ -53,6 +54,8 @@ public class OurParameterArea extends ParameterArea{
button2 = new JRadioButton("Beispiel 2");
button3 = new JRadioButton("Beispiel 3");
button4 = new JRadioButton("Beispiel 4");
button5 = new JRadioButton("Eigener Graph");
// ButtonGroup erstellen und Buttons hinzufügen, um die gegenseitige Ausschließung zu gewährleisten
ButtonGroup group = new ButtonGroup();
@ -60,6 +63,7 @@ public class OurParameterArea extends ParameterArea{
group.add(button2);
group.add(button3);
group.add(button4);
group.add(button5);
// ActionListener hinzufügen
button1.addActionListener(new ActionListener() {
@ -90,11 +94,19 @@ public class OurParameterArea extends ParameterArea{
}
});
button5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectedExample = 5;
}
});
// Buttons zum Panel hinzufügen
add(button1);
add(button2);
add(button3);
add(button4);
add(button5);
}
public DirectedGraph<VertexMarking, EdgeMarking> getSelectedGraph() {
@ -106,6 +118,8 @@ public class OurParameterArea extends ParameterArea{
return temp.example3();
case 4:
return temp.example4();
case 5:
return new DirectedGraph<>();
case 1:
default:
return temp.example1();

View File

@ -207,13 +207,17 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Erstellt Hashmap um Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
// Erstelle Hashmap um Vorgängerknoten zu tracken
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
// Initialisierung, dass kein Knoten besucht wurde
// Initialisierung aller Vorgänger auf null
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
HashMap<MarkedVertex<T>, MarkedVertex<T>> predecessors = new HashMap<>();
for (MarkedVertex<T> i: this.getAllVertexes()) {
distance.put(i, -1);
visited.put(i, false);
predecessors.put(i, null);
}
// Erstelle Schlange wo die nächsten Verbindungen drin sind
@ -238,6 +242,7 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
+ ", 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();
@ -253,6 +258,25 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Wenn Weg gefunden, brich ab
if (nextVertex.getElement() == n2) {
MarkedVertex<T> colorroute = n2;
while (colorroute != null) {
textDescription = colorroute.getName();
System.out.println(textDescription);
colorroute.getScreenVertex().setColor(Color.green);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
colorroute = predecessors.get(colorroute);
}
//zurücksetzten der Färbungen
this.clearScreenGraphColor();
return distance.get(n2);
}
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
for (MarkedVertex<T> i: this.getSuccessors(nextVertex.getElement())) {
@ -272,6 +296,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
continue;
}
// Vorgänger aktualisieren
predecessors.put(i, nextVertex.getElement());
// Aktualisiere Distanz von Start zu nächstem Knoten
distance.put(i, dist);
@ -289,6 +316,16 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
//zurücksetzten der Färbungen
this.clearScreenGraphColor();
MarkedVertex<T> colorroute = n2;
while (colorroute != null) {
textDescription = colorroute.getName();
System.out.println(textDescription);
colorroute.getScreenVertex().setColor(Color.green);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
colorroute = predecessors.get(colorroute);
}
System.out.println("Done");
// Gibt Distanz zu gefragtem Knoten zurück
return distance.get(n2);
@ -300,13 +337,17 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
// Erstellt Hashmap um Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
// Erstelle Hashmap um Vorgängerknoten zu tracken
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
// Initialisierung, dass kein Knoten besucht wurde
// Initialisierung aller Vorgänger auf null
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
HashMap<MarkedVertex<T>, MarkedVertex<T>> predecessors = new HashMap<>();
for (MarkedVertex<T> i: this.getAllVertexes()) {
distance.put(i, -1);
visited.put(i, false);
predecessors.put(i, null);
}
// Erstelle Schlange wo die nächsten Verbindungen drin sind
@ -349,6 +390,24 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Wenn Weg gefunden, brich ab
if (nextVertex.getElement() == n2) {
MarkedVertex<T> colorroute = n2;
while (colorroute != null) {
textDescription = colorroute.getName();
System.out.println(textDescription);
colorroute.getScreenVertex().setColor(Color.green);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
colorroute = predecessors.get(colorroute);
}
//zurücksetzten der Färbungen
this.clearScreenGraphColor();
return distance.get(n2);
}
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
for (MarkedVertex<T> i: this.getSuccessors(nextVertex.getElement())) {
@ -391,6 +450,16 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
//zurücksetzten der Färbungen
this.clearScreenGraphColor();
MarkedVertex<T> colorroute = n2;
while (colorroute != null) {
textDescription = colorroute.getName();
System.out.println(textDescription);
colorroute.getScreenVertex().setColor(Color.green);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
colorroute = predecessors.get(colorroute);
}
System.out.println("Done");
// Gibt Distanz zu gefragtem Knoten zurück
return distance.get(n2);

View File

@ -31,6 +31,11 @@ public class ExampleGraphs {
for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) {
String name = String.valueOf((char) ('A' + row * size + col));
if (name.equals("A")) {
name = "Start";
} else if (name.equals("Y")) {
name = "Ende";
}
vertices[row][col] = new MarkedVertex<>(50 + col * 100, 50 + row * 100, name, null, null);
example1.addVertex(vertices[row][col]);
}
@ -72,11 +77,11 @@ public class ExampleGraphs {
* Endknoten: E
*/
MarkedVertex A = new MarkedVertex<>(100, 100, "A", null, null);
MarkedVertex A = new MarkedVertex<>(100, 100, "Start", null, null);
MarkedVertex B = new MarkedVertex<>(250, 50, "B", null, null);
MarkedVertex C = new MarkedVertex<>(400, 100, "C", null, null);
MarkedVertex D = new MarkedVertex<>(550, 50, "D", null, null);
MarkedVertex E = new MarkedVertex<>(700, 100, "E", null, null);
MarkedVertex E = new MarkedVertex<>(700, 100, "Ende", null, null);
MarkedVertex F = new MarkedVertex<>(250, 200, "F", null, null);
MarkedVertex G = new MarkedVertex<>(550, 200, "G", null, null);
@ -116,7 +121,7 @@ public class ExampleGraphs {
DirectedGraph<VertexMarking, EdgeMarking> example3 = new DirectedGraph<>();
// Startpunkt A in der Mitte der Y-Koordinate
MarkedVertex A = new MarkedVertex<>(100, 250, "A", null, null);
MarkedVertex A = new MarkedVertex<>(100, 250, "Start", null, null);
// Erster Weg
MarkedVertex B1 = new MarkedVertex<>(200, 100, "B1", null, null);
@ -140,7 +145,7 @@ public class ExampleGraphs {
MarkedVertex B4 = new MarkedVertex<>(200, 400, "B4", null, null);
MarkedVertex C4 = new MarkedVertex<>(300, 400, "C4", null, null);
MarkedVertex D4 = new MarkedVertex<>(400, 400, "D4", null, null);
MarkedVertex E4 = new MarkedVertex<>(500, 400, "E4", null, null); // Endpunkt des vierten Weges
MarkedVertex E4 = new MarkedVertex<>(500, 400, "Ende", null, null); // Endpunkt des vierten Weges
example3.addVertex(A);
example3.addVertex(B1);
@ -185,7 +190,7 @@ public class ExampleGraphs {
public static DirectedGraph<VertexMarking, EdgeMarking> example4() {
public DirectedGraph<VertexMarking, EdgeMarking> example4() {
/**
* Erstellt einen Beispielgraphen (Beispiel 4), der sich ideal für die Demonstration der Funktionsweise
@ -202,14 +207,15 @@ public class ExampleGraphs {
DirectedGraph<VertexMarking, EdgeMarking> example4 = new DirectedGraph<>();
// Erstellung der Knoten mit Koordinaten
MarkedVertex<VertexMarking> A = new MarkedVertex<>(50, 250, "A", null, null);
MarkedVertex<VertexMarking> A = new MarkedVertex<>(50, 250, "Start", null, null);
MarkedVertex<VertexMarking> B = new MarkedVertex<>(150, 150, "B", null, null);
MarkedVertex<VertexMarking> C = new MarkedVertex<>(150, 350, "C", null, null);
MarkedVertex<VertexMarking> D = new MarkedVertex<>(250, 100, "D", null, null);
MarkedVertex<VertexMarking> E = new MarkedVertex<>(250, 250, "E", null, null);
MarkedVertex<VertexMarking> F = new MarkedVertex<>(350, 200, "F", null, null);
MarkedVertex<VertexMarking> G = new MarkedVertex<>(450, 300, "G", null, null);
MarkedVertex<VertexMarking> H = new MarkedVertex<>(450, 100, "H", null, null);
MarkedVertex<VertexMarking> H = new MarkedVertex<>(450, 100, "Ende", null, null);
// Hinzufügen der Knoten zum Graphen
example4.addVertex(A);

View File

@ -141,16 +141,19 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
public int getShortestPathDijkstra(MarkedVertex<T> n1, MarkedVertex<T> n2) {
// Erstellt Hashmap um Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
// Erstelle Hashmap um Vorgängerknoten zu tracken
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
// Initialisierung, dass kein Knoten besucht wurde
// Initialisierung aller Vorgänger auf null
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
HashMap<MarkedVertex<T>, MarkedVertex<T>> predecessors = new HashMap<>();
for (MarkedVertex<T> i: this.getAllVertexes()) {
distance.put(i, -1);
visited.put(i, false);
predecessors.put(i, null);
}
// Erstelle Schlange wo die nächsten Verbindungen drin sind
@ -190,6 +193,25 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Wenn Weg gefunden, brich ab
if (nextVertex.getElement() == n2) {
MarkedVertex<T> colorroute = n2;
while (colorroute != null) {
textDescription = colorroute.getName();
System.out.println(textDescription);
colorroute.getScreenVertex().setColor(Color.green);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
colorroute = predecessors.get(colorroute);
}
//zurücksetzten der Färbungen
this.clearScreenGraphColor();
return distance.get(n2);
}
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
for (MarkedVertex<T> i: this.getNeighbours(nextVertex.getElement())) {
@ -226,6 +248,16 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
//zurücksetzten der Färbungen
this.clearScreenGraphColor();
MarkedVertex<T> colorroute = n2;
while (colorroute != null) {
textDescription = colorroute.getName();
System.out.println(textDescription);
colorroute.getScreenVertex().setColor(Color.green);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
colorroute = predecessors.get(colorroute);
}
System.out.println("Done");
// Gibt Distanz zu gefragtem Knoten zurück
return distance.get(n2);
@ -236,13 +268,17 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
// Erstellt Hashmap um Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
// Erstelle Hashmap um Vorgängerknoten zu tracken
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
// Initialisierung, dass kein Knoten besucht wurde
// Initialisierung aller Vorgänger auf null
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
HashMap<MarkedVertex<T>, MarkedVertex<T>> predecessors = new HashMap<>();
for (MarkedVertex<T> i: this.getAllVertexes()) {
distance.put(i, -1);
visited.put(i, false);
predecessors.put(i, null);
}
// Erstelle Schlange wo die nächsten Verbindungen drin sind
@ -286,6 +322,25 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
// Wenn Weg gefunden, brich ab
if (nextVertex.getElement() == n2) {
MarkedVertex<T> colorroute = n2;
while (colorroute != null) {
textDescription = colorroute.getName();
System.out.println(textDescription);
colorroute.getScreenVertex().setColor(Color.green);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
colorroute = predecessors.get(colorroute);
}
//zurücksetzten der Färbungen
this.clearScreenGraphColor();
return distance.get(n2);
}
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
for (MarkedVertex<T> i: this.getNeighbours(nextVertex.getElement())) {
@ -327,6 +382,16 @@ public class UndirectedGraph<T extends VertexMarking, U extends EdgeMarking> ext
//zurücksetzten der Färbungen
this.clearScreenGraphColor();
MarkedVertex<T> colorroute = n2;
while (colorroute != null) {
textDescription = colorroute.getName();
System.out.println(textDescription);
colorroute.getScreenVertex().setColor(Color.green);
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
colorroute = predecessors.get(colorroute);
}
System.out.println("Done");
// Gibt Distanz zu gefragtem Knoten zurück
return distance.get(n2);