Endgültiger Weg wird angezeigt
This commit is contained in:
parent
1f67dde5c4
commit
ecf2bb8656
46
.idea/workspace.xml
generated
46
.idea/workspace.xml
generated
@ -5,13 +5,18 @@
|
|||||||
</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$/out/production/ProjektGraph/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/.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$/out/production/ProjektGraph/OurApplication/OurTextArea.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ProjektGraph/OurApplication/OurTextArea.class" 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/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/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" />
|
<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" />
|
||||||
@ -37,17 +42,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[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"Application.Display.executor": "Run",
|
"Application.Display.executor": "Run",
|
||||||
"Application.OurApplication.executor": "Debug",
|
"Application.OurApplication.executor": "Run",
|
||||||
"Application.OurLegendArea.executor": "Run",
|
"Application.OurLegendArea.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
"kotlin-language-version-configured": "true",
|
"kotlin-language-version-configured": "true",
|
||||||
"last_opened_file_path": "C:/Git/ProjektGraphMain"
|
"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" />
|
||||||
@ -179,15 +184,4 @@
|
|||||||
<MESSAGE value="Weighting gefixt" />
|
<MESSAGE value="Weighting gefixt" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Weighting gefixt" />
|
<option name="LAST_COMMIT_MESSAGE" value="Weighting gefixt" />
|
||||||
</component>
|
</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>
|
</project>
|
@ -6,6 +6,7 @@ import logging.LogElementList;
|
|||||||
import visualizationElements.Vertex;
|
import visualizationElements.Vertex;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
@ -44,12 +45,29 @@ public class OurAlgorithm extends Algorithm {
|
|||||||
this.setCurrentGraph(currentParameterArea.getSelectedGraph());
|
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();
|
Random random = new Random();
|
||||||
|
|
||||||
MarkedVertex<VertexMarking> start = this.currentGraph.getAllVertexes().get(random.nextInt(this.currentGraph.getAllVertexes().size()));
|
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()));
|
MarkedVertex<VertexMarking> end = this.currentGraph.getAllVertexes().get(random.nextInt(this.currentGraph.getAllVertexes().size()));
|
||||||
System.out.println(start.getName() + " to " + end.getName());
|
System.out.println(start.getName() + " to " + end.getName());
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
this.currentGraph.getShortestPathDijkstra(start, end);
|
this.currentGraph.getShortestPathDijkstra(start, end);
|
||||||
|
|
||||||
return this.currentGraph.getLogList();
|
return this.currentGraph.getLogList();
|
||||||
|
@ -3,8 +3,11 @@ package OurApplication;
|
|||||||
import graph.*;
|
import graph.*;
|
||||||
import logging.LogElementList;
|
import logging.LogElementList;
|
||||||
import visualisation.HybridWindow;
|
import visualisation.HybridWindow;
|
||||||
|
import visualizationElements.Vertex;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,9 +59,7 @@ public class OurApplication {
|
|||||||
OurTextArea textArea = new OurTextArea(logList);
|
OurTextArea textArea = new OurTextArea(logList);
|
||||||
OurAlgorithm algorithm = new OurAlgorithm(parameterArea);
|
OurAlgorithm algorithm = new OurAlgorithm(parameterArea);
|
||||||
OurLegendArea legendArea = new OurLegendArea();
|
OurLegendArea legendArea = new OurLegendArea();
|
||||||
HybridWindow<OurDrawArea, OurTextArea, OurParameterArea, OurAlgorithm, OurLogElement, OurLegendArea> applet = new HybridWindow<OurDrawArea, OurTextArea, OurParameterArea, OurAlgorithm, OurLogElement, OurLegendArea>(drawArea, textArea, parameterArea, algorithm, logList, legendArea);
|
HybridWindow<OurDrawArea, OurTextArea, OurParameterArea, OurAlgorithm, OurLogElement, OurLegendArea> applet = new HybridWindow<>(drawArea, textArea, parameterArea, algorithm, logList, legendArea);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -68,27 +69,9 @@ public class OurApplication {
|
|||||||
frame.pack();
|
frame.pack();
|
||||||
applet.init();
|
applet.init();
|
||||||
applet.start();
|
applet.start();
|
||||||
frame.setSize(800,600);
|
frame.setSize(1000,800);
|
||||||
frame.setVisible(true);
|
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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,12 @@ package OurApplication;
|
|||||||
import logging.LogElementList;
|
import logging.LogElementList;
|
||||||
import visualisation.DrawArea;
|
import visualisation.DrawArea;
|
||||||
import visualizationElements.Edge;
|
import visualizationElements.Edge;
|
||||||
|
import visualizationElements.Vertex;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,6 +60,14 @@ public class OurLegendArea extends LegendArea{
|
|||||||
g.drawOval(10, y, 20, 20); // Zeichnet den Rand des Kreises
|
g.drawOval(10, y, 20, 20); // Zeichnet den Rand des Kreises
|
||||||
g.drawString("Erreichbare Knoten", 40, y + 15); // Zeichnet die Beschreibung neben dem Kreis
|
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)
|
// Zeichnet die schwarze Linie (Kanten Markierung)
|
||||||
y += 40; // Nach unten verschieben für das nächste Element
|
y += 40; // Nach unten verschieben für das nächste Element
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
|
@ -26,6 +26,7 @@ public class OurParameterArea extends ParameterArea{
|
|||||||
private JRadioButton button2;
|
private JRadioButton button2;
|
||||||
private JRadioButton button3;
|
private JRadioButton button3;
|
||||||
private JRadioButton button4;
|
private JRadioButton button4;
|
||||||
|
private JRadioButton button5;
|
||||||
|
|
||||||
private ExampleGraphs temp;
|
private ExampleGraphs temp;
|
||||||
private int selectedExample;
|
private int selectedExample;
|
||||||
@ -53,6 +54,8 @@ public class OurParameterArea extends ParameterArea{
|
|||||||
button2 = new JRadioButton("Beispiel 2");
|
button2 = new JRadioButton("Beispiel 2");
|
||||||
button3 = new JRadioButton("Beispiel 3");
|
button3 = new JRadioButton("Beispiel 3");
|
||||||
button4 = new JRadioButton("Beispiel 4");
|
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 erstellen und Buttons hinzufügen, um die gegenseitige Ausschließung zu gewährleisten
|
||||||
ButtonGroup group = new ButtonGroup();
|
ButtonGroup group = new ButtonGroup();
|
||||||
@ -60,6 +63,7 @@ public class OurParameterArea extends ParameterArea{
|
|||||||
group.add(button2);
|
group.add(button2);
|
||||||
group.add(button3);
|
group.add(button3);
|
||||||
group.add(button4);
|
group.add(button4);
|
||||||
|
group.add(button5);
|
||||||
|
|
||||||
// ActionListener hinzufügen
|
// ActionListener hinzufügen
|
||||||
button1.addActionListener(new ActionListener() {
|
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
|
// Buttons zum Panel hinzufügen
|
||||||
add(button1);
|
add(button1);
|
||||||
add(button2);
|
add(button2);
|
||||||
add(button3);
|
add(button3);
|
||||||
add(button4);
|
add(button4);
|
||||||
|
add(button5);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectedGraph<VertexMarking, EdgeMarking> getSelectedGraph() {
|
public DirectedGraph<VertexMarking, EdgeMarking> getSelectedGraph() {
|
||||||
@ -106,6 +118,8 @@ public class OurParameterArea extends ParameterArea{
|
|||||||
return temp.example3();
|
return temp.example3();
|
||||||
case 4:
|
case 4:
|
||||||
return temp.example4();
|
return temp.example4();
|
||||||
|
case 5:
|
||||||
|
return new DirectedGraph<>();
|
||||||
case 1:
|
case 1:
|
||||||
default:
|
default:
|
||||||
return temp.example1();
|
return temp.example1();
|
||||||
|
@ -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 Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
|
||||||
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
|
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
|
||||||
|
// Erstelle Hashmap um Vorgängerknoten zu tracken
|
||||||
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
|
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
|
||||||
// Initialisierung, dass kein Knoten besucht wurde
|
// Initialisierung, dass kein Knoten besucht wurde
|
||||||
|
// Initialisierung aller Vorgänger auf null
|
||||||
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
|
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
|
||||||
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
|
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
|
||||||
|
HashMap<MarkedVertex<T>, MarkedVertex<T>> predecessors = new HashMap<>();
|
||||||
for (MarkedVertex<T> i: this.getAllVertexes()) {
|
for (MarkedVertex<T> i: this.getAllVertexes()) {
|
||||||
distance.put(i, -1);
|
distance.put(i, -1);
|
||||||
visited.put(i, false);
|
visited.put(i, false);
|
||||||
|
predecessors.put(i, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erstelle Schlange wo die nächsten Verbindungen drin sind
|
// 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();
|
+ ", Endknoten: " + n2.getScreenVertex().getMarking();
|
||||||
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
|
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
|
||||||
|
|
||||||
|
|
||||||
while (!queue.isEmpty()) {
|
while (!queue.isEmpty()) {
|
||||||
// Den nächsten Knoten, der am wenigsten kostet, besuchen
|
// Den nächsten Knoten, der am wenigsten kostet, besuchen
|
||||||
WrapperElement<T> nextVertex = queue.poll();
|
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()));
|
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
|
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
|
||||||
for (MarkedVertex<T> i: this.getSuccessors(nextVertex.getElement())) {
|
for (MarkedVertex<T> i: this.getSuccessors(nextVertex.getElement())) {
|
||||||
|
|
||||||
@ -272,6 +296,9 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vorgänger aktualisieren
|
||||||
|
predecessors.put(i, nextVertex.getElement());
|
||||||
|
|
||||||
// Aktualisiere Distanz von Start zu nächstem Knoten
|
// Aktualisiere Distanz von Start zu nächstem Knoten
|
||||||
distance.put(i, dist);
|
distance.put(i, dist);
|
||||||
|
|
||||||
@ -289,6 +316,16 @@ public class DirectedGraph<T extends VertexMarking, U extends EdgeMarking> exten
|
|||||||
//zurücksetzten der Färbungen
|
//zurücksetzten der Färbungen
|
||||||
this.clearScreenGraphColor();
|
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");
|
System.out.println("Done");
|
||||||
// Gibt Distanz zu gefragtem Knoten zurück
|
// Gibt Distanz zu gefragtem Knoten zurück
|
||||||
return distance.get(n2);
|
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 Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
|
||||||
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
|
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
|
||||||
|
// Erstelle Hashmap um Vorgängerknoten zu tracken
|
||||||
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
|
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
|
||||||
// Initialisierung, dass kein Knoten besucht wurde
|
// Initialisierung, dass kein Knoten besucht wurde
|
||||||
|
// Initialisierung aller Vorgänger auf null
|
||||||
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
|
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
|
||||||
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
|
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
|
||||||
|
HashMap<MarkedVertex<T>, MarkedVertex<T>> predecessors = new HashMap<>();
|
||||||
for (MarkedVertex<T> i: this.getAllVertexes()) {
|
for (MarkedVertex<T> i: this.getAllVertexes()) {
|
||||||
distance.put(i, -1);
|
distance.put(i, -1);
|
||||||
visited.put(i, false);
|
visited.put(i, false);
|
||||||
|
predecessors.put(i, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erstelle Schlange wo die nächsten Verbindungen drin sind
|
// 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);
|
nextVertex.getElement().getScreenVertex().setColor(Color.BLUE);
|
||||||
this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy()));
|
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
|
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
|
||||||
for (MarkedVertex<T> i: this.getSuccessors(nextVertex.getElement())) {
|
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
|
//zurücksetzten der Färbungen
|
||||||
this.clearScreenGraphColor();
|
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");
|
System.out.println("Done");
|
||||||
// Gibt Distanz zu gefragtem Knoten zurück
|
// Gibt Distanz zu gefragtem Knoten zurück
|
||||||
return distance.get(n2);
|
return distance.get(n2);
|
||||||
|
@ -31,6 +31,11 @@ public class ExampleGraphs {
|
|||||||
for (int row = 0; row < size; row++) {
|
for (int row = 0; row < size; row++) {
|
||||||
for (int col = 0; col < size; col++) {
|
for (int col = 0; col < size; col++) {
|
||||||
String name = String.valueOf((char) ('A' + row * 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);
|
vertices[row][col] = new MarkedVertex<>(50 + col * 100, 50 + row * 100, name, null, null);
|
||||||
example1.addVertex(vertices[row][col]);
|
example1.addVertex(vertices[row][col]);
|
||||||
}
|
}
|
||||||
@ -72,11 +77,11 @@ public class ExampleGraphs {
|
|||||||
* Endknoten: E
|
* 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 B = new MarkedVertex<>(250, 50, "B", null, null);
|
||||||
MarkedVertex C = new MarkedVertex<>(400, 100, "C", null, null);
|
MarkedVertex C = new MarkedVertex<>(400, 100, "C", null, null);
|
||||||
MarkedVertex D = new MarkedVertex<>(550, 50, "D", 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 F = new MarkedVertex<>(250, 200, "F", null, null);
|
||||||
MarkedVertex G = new MarkedVertex<>(550, 200, "G", null, null);
|
MarkedVertex G = new MarkedVertex<>(550, 200, "G", null, null);
|
||||||
|
|
||||||
@ -116,7 +121,7 @@ public class ExampleGraphs {
|
|||||||
DirectedGraph<VertexMarking, EdgeMarking> example3 = new DirectedGraph<>();
|
DirectedGraph<VertexMarking, EdgeMarking> example3 = new DirectedGraph<>();
|
||||||
|
|
||||||
// Startpunkt A in der Mitte der Y-Koordinate
|
// 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
|
// Erster Weg
|
||||||
MarkedVertex B1 = new MarkedVertex<>(200, 100, "B1", null, null);
|
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 B4 = new MarkedVertex<>(200, 400, "B4", null, null);
|
||||||
MarkedVertex C4 = new MarkedVertex<>(300, 400, "C4", null, null);
|
MarkedVertex C4 = new MarkedVertex<>(300, 400, "C4", null, null);
|
||||||
MarkedVertex D4 = new MarkedVertex<>(400, 400, "D4", 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(A);
|
||||||
example3.addVertex(B1);
|
example3.addVertex(B1);
|
||||||
@ -185,49 +190,57 @@ public class ExampleGraphs {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public DirectedGraph<VertexMarking, EdgeMarking> example4() {
|
public static DirectedGraph<VertexMarking, EdgeMarking> example4() {
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Beispiel 4 zeigt einen gerichteten Graphen mit deutschen Städten als Knoten und
|
* Erstellt einen Beispielgraphen (Beispiel 4), der sich ideal für die Demonstration der Funktionsweise
|
||||||
* zufällig gewichteten Kanten.
|
* des Dijkstra- und A*-Algorithmus eignet. Der Graph enthält eine Vielzahl von Knoten, die durch
|
||||||
|
* gewichtete Kanten verbunden sind. Dies ermöglicht es, den kürzesten Weg von einem Startknoten zu einem
|
||||||
|
* Zielknoten effizient zu berechnen und die Unterschiede zwischen den beiden Algorithmen in der
|
||||||
|
* Pfadfindung zu veranschaulichen.
|
||||||
|
*
|
||||||
|
* Startknoten: A
|
||||||
|
* Zielknoten: H
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DirectedGraph<VertexMarking, EdgeMarking> example4 = new DirectedGraph<>();
|
DirectedGraph<VertexMarking, EdgeMarking> example4 = new DirectedGraph<>();
|
||||||
|
|
||||||
// Städte als Knoten
|
// Erstellung der Knoten mit Koordinaten
|
||||||
MarkedVertex Berlin = new MarkedVertex<>(100, 100, "Berlin", null, null);
|
MarkedVertex<VertexMarking> A = new MarkedVertex<>(50, 250, "Start", null, null);
|
||||||
MarkedVertex Hamburg = new MarkedVertex<>(200, 100, "Hamburg", null, null);
|
MarkedVertex<VertexMarking> B = new MarkedVertex<>(150, 150, "B", null, null);
|
||||||
MarkedVertex München = new MarkedVertex<>(300, 100, "München", null, null);
|
MarkedVertex<VertexMarking> C = new MarkedVertex<>(150, 350, "C", null, null);
|
||||||
MarkedVertex Köln = new MarkedVertex<>(100, 200, "Köln", null, null);
|
MarkedVertex<VertexMarking> D = new MarkedVertex<>(250, 100, "D", null, null);
|
||||||
MarkedVertex Frankfurt = new MarkedVertex<>(200, 200, "Frankfurt", null, null);
|
MarkedVertex<VertexMarking> E = new MarkedVertex<>(250, 250, "E", null, null);
|
||||||
MarkedVertex Stuttgart = new MarkedVertex<>(300, 200, "Stuttgart", null, null);
|
MarkedVertex<VertexMarking> F = new MarkedVertex<>(350, 200, "F", null, null);
|
||||||
MarkedVertex Leipzig = new MarkedVertex<>(100, 300, "Leipzig", null, null);
|
MarkedVertex<VertexMarking> G = new MarkedVertex<>(450, 300, "G", null, null);
|
||||||
MarkedVertex Dresden = new MarkedVertex<>(200, 300, "Dresden", null, null);
|
MarkedVertex<VertexMarking> H = new MarkedVertex<>(450, 100, "Ende", null, null);
|
||||||
MarkedVertex Hannover = new MarkedVertex<>(300, 300, "Hannover", null, null);
|
|
||||||
|
|
||||||
// Kanten mit zufälligen Gewichtungen
|
|
||||||
example4.addVertex(Berlin);
|
|
||||||
example4.addVertex(Hamburg);
|
|
||||||
example4.addVertex(München);
|
|
||||||
example4.addVertex(Köln);
|
|
||||||
example4.addVertex(Frankfurt);
|
|
||||||
example4.addVertex(Stuttgart);
|
|
||||||
example4.addVertex(Leipzig);
|
|
||||||
example4.addVertex(Dresden);
|
|
||||||
example4.addVertex(Hannover);
|
|
||||||
|
|
||||||
example4.addEdge(new MarkedEdge<>("Berlin-Hamburg", Berlin, Hamburg, new EdgeWeightMarking(1)));
|
// Hinzufügen der Knoten zum Graphen
|
||||||
example4.addEdge(new MarkedEdge<>("Berlin-München", Berlin, München, new EdgeWeightMarking(2)));
|
example4.addVertex(A);
|
||||||
example4.addEdge(new MarkedEdge<>("Berlin-Köln", Berlin, Köln, new EdgeWeightMarking(3)));
|
example4.addVertex(B);
|
||||||
example4.addEdge(new MarkedEdge<>("Hamburg-Frankfurt", Hamburg, Frankfurt, new EdgeWeightMarking(2)));
|
example4.addVertex(C);
|
||||||
example4.addEdge(new MarkedEdge<>("Hamburg-Leipzig", Hamburg, Leipzig, new EdgeWeightMarking(3)));
|
example4.addVertex(D);
|
||||||
example4.addEdge(new MarkedEdge<>("München-Stuttgart", München, Stuttgart, new EdgeWeightMarking(1)));
|
example4.addVertex(E);
|
||||||
example4.addEdge(new MarkedEdge<>("München-Dresden", München, Dresden, new EdgeWeightMarking(2)));
|
example4.addVertex(F);
|
||||||
example4.addEdge(new MarkedEdge<>("Köln-Hannover", Köln, Hannover, new EdgeWeightMarking(3)));
|
example4.addVertex(G);
|
||||||
example4.addEdge(new MarkedEdge<>("Frankfurt-Stuttgart", Frankfurt, Stuttgart, new EdgeWeightMarking(1)));
|
example4.addVertex(H);
|
||||||
example4.addEdge(new MarkedEdge<>("Stuttgart-Leipzig", Stuttgart, Leipzig, new EdgeWeightMarking(2)));
|
|
||||||
example4.addEdge(new MarkedEdge<>("Leipzig-Dresden", Leipzig, Dresden, new EdgeWeightMarking(1)));
|
// Erstellung der Kanten mit Gewichtungen
|
||||||
example4.addEdge(new MarkedEdge<>("Dresden-Hannover", Dresden, Hannover, new EdgeWeightMarking(3)));
|
example4.addEdge(new MarkedEdge<>("AB", A, B, new EdgeWeightMarking(4)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("AC", A, C, new EdgeWeightMarking(2)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("BC", B, C, new EdgeWeightMarking(5)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("BD", B, D, new EdgeWeightMarking(10)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("CD", C, D, new EdgeWeightMarking(3)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("CE", C, E, new EdgeWeightMarking(7)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("DE", D, E, new EdgeWeightMarking(2)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("DF", D, F, new EdgeWeightMarking(2)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("EF", E, F, new EdgeWeightMarking(5)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("EG", E, G, new EdgeWeightMarking(10)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("FG", F, G, new EdgeWeightMarking(3)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("FH", F, H, new EdgeWeightMarking(6)));
|
||||||
|
example4.addEdge(new MarkedEdge<>("GH", G, H, new EdgeWeightMarking(1)));
|
||||||
|
|
||||||
return example4;
|
return example4;
|
||||||
}
|
}
|
||||||
|
@ -141,16 +141,19 @@ 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) {
|
||||||
|
|
||||||
|
|
||||||
// Erstellt Hashmap um Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
|
// Erstellt Hashmap um Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
|
||||||
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
|
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
|
||||||
|
// Erstelle Hashmap um Vorgängerknoten zu tracken
|
||||||
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
|
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
|
||||||
// Initialisierung, dass kein Knoten besucht wurde
|
// Initialisierung, dass kein Knoten besucht wurde
|
||||||
|
// Initialisierung aller Vorgänger auf null
|
||||||
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
|
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
|
||||||
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
|
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
|
||||||
|
HashMap<MarkedVertex<T>, MarkedVertex<T>> predecessors = new HashMap<>();
|
||||||
for (MarkedVertex<T> i: this.getAllVertexes()) {
|
for (MarkedVertex<T> i: this.getAllVertexes()) {
|
||||||
distance.put(i, -1);
|
distance.put(i, -1);
|
||||||
visited.put(i, false);
|
visited.put(i, false);
|
||||||
|
predecessors.put(i, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erstelle Schlange wo die nächsten Verbindungen drin sind
|
// 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()));
|
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
|
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
|
||||||
for (MarkedVertex<T> i: this.getNeighbours(nextVertex.getElement())) {
|
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
|
//zurücksetzten der Färbungen
|
||||||
this.clearScreenGraphColor();
|
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");
|
System.out.println("Done");
|
||||||
// Gibt Distanz zu gefragtem Knoten zurück
|
// Gibt Distanz zu gefragtem Knoten zurück
|
||||||
return distance.get(n2);
|
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 Distanz von Startnoten zu jedem Knoten auf dem Graph zu tracken
|
||||||
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
|
// Erstellt Hashmap um zu tracken welche Knoten schon besucht wurden
|
||||||
|
// Erstelle Hashmap um Vorgängerknoten zu tracken
|
||||||
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
|
// Initialisierung aller Distanzen auf UNENDLICH (= -1)
|
||||||
// Initialisierung, dass kein Knoten besucht wurde
|
// Initialisierung, dass kein Knoten besucht wurde
|
||||||
|
// Initialisierung aller Vorgänger auf null
|
||||||
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
|
HashMap<MarkedVertex<T>, Integer> distance = new HashMap<>();
|
||||||
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
|
HashMap<MarkedVertex<T>, Boolean> visited = new HashMap<>();
|
||||||
|
HashMap<MarkedVertex<T>, MarkedVertex<T>> predecessors = new HashMap<>();
|
||||||
for (MarkedVertex<T> i: this.getAllVertexes()) {
|
for (MarkedVertex<T> i: this.getAllVertexes()) {
|
||||||
distance.put(i, -1);
|
distance.put(i, -1);
|
||||||
visited.put(i, false);
|
visited.put(i, false);
|
||||||
|
predecessors.put(i, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erstelle Schlange wo die nächsten Verbindungen drin sind
|
// 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()));
|
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
|
// Gehe von diesem Knoten aus alle erreichbaren Knoten durch
|
||||||
for (MarkedVertex<T> i: this.getNeighbours(nextVertex.getElement())) {
|
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
|
//zurücksetzten der Färbungen
|
||||||
this.clearScreenGraphColor();
|
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");
|
System.out.println("Done");
|
||||||
// Gibt Distanz zu gefragtem Knoten zurück
|
// Gibt Distanz zu gefragtem Knoten zurück
|
||||||
return distance.get(n2);
|
return distance.get(n2);
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user