Compare commits
No commits in common. "1313402f078def31a988f9d6fbf7343527dfc413" and "b5730e1b183e670c3c591d404ee7b791de54cde1" have entirely different histories.
1313402f07
...
b5730e1b18
46
.idea/workspace.xml
generated
46
.idea/workspace.xml
generated
@ -5,18 +5,13 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<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/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/.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$/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" />
|
||||
@ -42,17 +37,17 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<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 name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"Application.Display.executor": "Run",
|
||||
"Application.OurApplication.executor": "Debug",
|
||||
"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" />
|
||||
@ -184,4 +179,15 @@
|
||||
<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>
|
@ -6,7 +6,6 @@ import logging.LogElementList;
|
||||
import visualizationElements.Vertex;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
@ -48,28 +47,12 @@ 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{
|
||||
@ -83,6 +66,5 @@ public class OurAlgorithm extends Algorithm {
|
||||
public void setCurrentGraph(graph.Graph<VertexMarking, EdgeMarking> graph) {
|
||||
this.currentGraph = graph;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,8 @@ 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;
|
||||
|
||||
/**
|
||||
@ -72,9 +69,27 @@ public class OurApplication {
|
||||
frame.pack();
|
||||
applet.init();
|
||||
applet.start();
|
||||
frame.setSize(1000,800);
|
||||
frame.setSize(800,600);
|
||||
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,12 +3,8 @@ 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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -60,14 +60,6 @@ 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);
|
||||
|
@ -26,7 +26,6 @@ public class OurParameterArea extends ParameterArea{
|
||||
private JRadioButton button2;
|
||||
private JRadioButton button3;
|
||||
private JRadioButton button4;
|
||||
private JRadioButton button5;
|
||||
|
||||
private ExampleGraphs temp;
|
||||
private int selectedExample;
|
||||
@ -54,8 +53,6 @@ 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();
|
||||
@ -63,7 +60,6 @@ public class OurParameterArea extends ParameterArea{
|
||||
group.add(button2);
|
||||
group.add(button3);
|
||||
group.add(button4);
|
||||
group.add(button5);
|
||||
|
||||
// ActionListener hinzufügen
|
||||
button1.addActionListener(new ActionListener() {
|
||||
@ -94,19 +90,11 @@ 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() {
|
||||
@ -118,8 +106,6 @@ public class OurParameterArea extends ParameterArea{
|
||||
return temp.example3();
|
||||
case 4:
|
||||
return temp.example4();
|
||||
case 5:
|
||||
return new DirectedGraph<>();
|
||||
case 1:
|
||||
default:
|
||||
return temp.example1();
|
||||
|
@ -207,17 +207,13 @@ 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
|
||||
@ -242,7 +238,6 @@ 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();
|
||||
@ -258,25 +253,6 @@ 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())) {
|
||||
|
||||
@ -296,9 +272,6 @@ 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);
|
||||
|
||||
@ -316,16 +289,6 @@ 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);
|
||||
@ -337,17 +300,13 @@ 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
|
||||
@ -390,24 +349,6 @@ 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())) {
|
||||
@ -450,16 +391,6 @@ 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);
|
||||
|
@ -31,11 +31,6 @@ 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]);
|
||||
}
|
||||
@ -77,11 +72,11 @@ public class ExampleGraphs {
|
||||
* Endknoten: E
|
||||
*/
|
||||
|
||||
MarkedVertex A = new MarkedVertex<>(100, 100, "Start", null, null);
|
||||
MarkedVertex A = new MarkedVertex<>(100, 100, "A", 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, "Ende", null, null);
|
||||
MarkedVertex E = new MarkedVertex<>(700, 100, "E", null, null);
|
||||
MarkedVertex F = new MarkedVertex<>(250, 200, "F", null, null);
|
||||
MarkedVertex G = new MarkedVertex<>(550, 200, "G", null, null);
|
||||
|
||||
@ -121,7 +116,7 @@ public class ExampleGraphs {
|
||||
DirectedGraph<VertexMarking, EdgeMarking> example3 = new DirectedGraph<>();
|
||||
|
||||
// Startpunkt A in der Mitte der Y-Koordinate
|
||||
MarkedVertex A = new MarkedVertex<>(100, 250, "Start", null, null);
|
||||
MarkedVertex A = new MarkedVertex<>(100, 250, "A", null, null);
|
||||
|
||||
// Erster Weg
|
||||
MarkedVertex B1 = new MarkedVertex<>(200, 100, "B1", null, null);
|
||||
@ -145,7 +140,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, "Ende", null, null); // Endpunkt des vierten Weges
|
||||
MarkedVertex E4 = new MarkedVertex<>(500, 400, "E4", null, null); // Endpunkt des vierten Weges
|
||||
|
||||
example3.addVertex(A);
|
||||
example3.addVertex(B1);
|
||||
@ -190,7 +185,7 @@ public class ExampleGraphs {
|
||||
|
||||
|
||||
|
||||
public DirectedGraph<VertexMarking, EdgeMarking> example4() {
|
||||
public static DirectedGraph<VertexMarking, EdgeMarking> example4() {
|
||||
|
||||
/**
|
||||
* Erstellt einen Beispielgraphen (Beispiel 4), der sich ideal für die Demonstration der Funktionsweise
|
||||
@ -207,15 +202,14 @@ public class ExampleGraphs {
|
||||
DirectedGraph<VertexMarking, EdgeMarking> example4 = new DirectedGraph<>();
|
||||
|
||||
// Erstellung der Knoten mit Koordinaten
|
||||
MarkedVertex<VertexMarking> A = new MarkedVertex<>(50, 250, "Start", null, null);
|
||||
MarkedVertex<VertexMarking> A = new MarkedVertex<>(50, 250, "A", 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, "Ende", null, null);
|
||||
|
||||
MarkedVertex<VertexMarking> H = new MarkedVertex<>(450, 100, "H", null, null);
|
||||
|
||||
// Hinzufügen der Knoten zum Graphen
|
||||
example4.addVertex(A);
|
||||
|
@ -141,19 +141,16 @@ 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
|
||||
@ -193,25 +190,6 @@ 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())) {
|
||||
|
||||
@ -248,16 +226,6 @@ 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);
|
||||
@ -268,17 +236,13 @@ 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
|
||||
@ -322,25 +286,6 @@ 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())) {
|
||||
|
||||
@ -382,16 +327,6 @@ 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);
|
||||
|
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