diff --git a/OurApplication/OurAlgorithm.java b/OurApplication/OurAlgorithm.java index 1c61e16..f9409a1 100644 --- a/OurApplication/OurAlgorithm.java +++ b/OurApplication/OurAlgorithm.java @@ -76,9 +76,9 @@ public class OurAlgorithm extends Algorithm { info.setContentPane(contentpane); JOptionPane.showMessageDialog( contentpane, - "Bitte geben SIe einen gültige Graphen an. Hilfestellung für das Erstellen von Knoten und Kanten:\n" + + "Bitte geben Sie einen gültigen Graphen an. Hilfestellung für das Erstellen von Knoten und Kanten:\n" + "Knoten: Name;X-Coordinate;Y-Coordinate\nKanten: StartKnoten;Endknoten;Gewichtung\n" + - "Hinweis: ein Koten benötigt den Namen 'Startknoten', ein anderer 'Endknoten'\n" + + "Hinweis: ein Koten benötigt den Namen 'Start', ein anderer 'Ende'\n" + "(Festlegen der Start und Endknoten für die Algorithmen)", "Eingabefehler", JOptionPane.INFORMATION_MESSAGE, diff --git a/OurApplication/OurParameterArea.java b/OurApplication/OurParameterArea.java index 09c6653..c0ab207 100644 --- a/OurApplication/OurParameterArea.java +++ b/OurApplication/OurParameterArea.java @@ -146,19 +146,21 @@ public class OurParameterArea extends ParameterArea { } // Create edges - MarkedVertex start = null; - MarkedVertex end = null; - for (String i: allEdges) { - String[] current = i.split("-"); - for (MarkedVertex j: newGraph.getAllVertexes()) { - if (Objects.equals(j.getName(), current[0])) { - start = j; - } - if (Objects.equals(j.getName(), current[1])) { - end = j; + if(allEdges.length != 1 || !Objects.equals(allEdges[0], "")){ + MarkedVertex start = null; + MarkedVertex end = null; + for (String i: allEdges) { + String[] current = i.split("-"); + for (MarkedVertex j: newGraph.getAllVertexes()) { + if (Objects.equals(j.getName(), current[0])) { + start = j; + } + if (Objects.equals(j.getName(), current[1])) { + end = j; + } } + newGraph.addEdge(new MarkedEdge<>(i, start, end, new EdgeWeightMarking(Integer.parseInt(current[2])))); } - newGraph.addEdge(new MarkedEdge<>(i, start, end, new EdgeWeightMarking(Integer.parseInt(current[2])))); } //Fehlerbehandlung }catch(Throwable e){ @@ -169,7 +171,7 @@ public class OurParameterArea extends ParameterArea { contentpane, "Fehler bei der Eingabe des Graphen. Beispieleingabe für Knoten und Kanten:\n" + "Knoten: Name;X-Coordinate;Y-Coordinate\nKanten: StartKnoten;Endknoten;Gewichtung\n" + - "Hinweis: ein Koten benötigt den Namen 'Startknoten', ein anderer 'Endknoten'\n" + + "Hinweis: ein Koten benötigt den Namen 'Start', ein anderer 'Ende'\n" + "(Festlegen der Start und Endknoten für die Algorithmen)", "Eingabefehler", JOptionPane.INFORMATION_MESSAGE, diff --git a/graph/DirectedGraph.java b/graph/DirectedGraph.java index 6eb666b..96a3545 100644 --- a/graph/DirectedGraph.java +++ b/graph/DirectedGraph.java @@ -419,19 +419,26 @@ public class DirectedGraph exten } } + MarkedVertex colorroute = n2; + // Falls kein Weg gefunden wurde + if (predecessors.get(n2) == null) { + textDescription = "Kein Weg gefunden!"; + this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); + }else{ + // Falls ein Weg gefunden wurde + 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(); - MarkedVertex 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); @@ -568,19 +575,26 @@ public class DirectedGraph exten } } + MarkedVertex colorroute = n2; + // Falls kein Weg gefunden wurde + if (predecessors.get(n2) == null) { + textDescription = "Kein Weg gefunden!"; + this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); + }else{ + // Falls ein Weg gefunden wurde + 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(); - MarkedVertex 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); diff --git a/graph/UndirectedGraph.java b/graph/UndirectedGraph.java index 510bddf..9d2734a 100644 --- a/graph/UndirectedGraph.java +++ b/graph/UndirectedGraph.java @@ -324,19 +324,26 @@ public class UndirectedGraph ext } } + MarkedVertex colorroute = n2; + // Falls kein Weg gefunden wurde + if (predecessors.get(n2) == null) { + textDescription = "Kein Weg gefunden!"; + this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); + }else{ + // Falls ein Weg gefunden wurde + 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(); - MarkedVertex 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); @@ -469,19 +476,26 @@ public class UndirectedGraph ext } } + MarkedVertex colorroute = n2; + // Falls kein Weg gefunden wurde + if (predecessors.get(n2) == null) { + textDescription = "Kein Weg gefunden!"; + this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); + }else{ + // Falls ein Weg gefunden wurde + 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(); - MarkedVertex 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); diff --git a/out/production/ProjektGraph/.gitignore b/out/production/ProjektGraph/.gitignore index 6a3417b..e0d52eb 100644 --- a/out/production/ProjektGraph/.gitignore +++ b/out/production/ProjektGraph/.gitignore @@ -1 +1,2 @@ /out/ +/.idea/ diff --git a/out/production/ProjektGraph/OurApplication/OurAlgorithm.class b/out/production/ProjektGraph/OurApplication/OurAlgorithm.class index 100e8c3..6873801 100644 Binary files a/out/production/ProjektGraph/OurApplication/OurAlgorithm.class and b/out/production/ProjektGraph/OurApplication/OurAlgorithm.class differ diff --git a/out/production/ProjektGraph/OurApplication/OurDrawArea.class b/out/production/ProjektGraph/OurApplication/OurDrawArea.class index 0f9d835..208b289 100644 Binary files a/out/production/ProjektGraph/OurApplication/OurDrawArea.class and b/out/production/ProjektGraph/OurApplication/OurDrawArea.class differ diff --git a/out/production/ProjektGraph/OurApplication/OurParameterArea.class b/out/production/ProjektGraph/OurApplication/OurParameterArea.class index 7674232..a425de5 100644 Binary files a/out/production/ProjektGraph/OurApplication/OurParameterArea.class and b/out/production/ProjektGraph/OurApplication/OurParameterArea.class differ diff --git a/out/production/ProjektGraph/graph/DirectedGraph.class b/out/production/ProjektGraph/graph/DirectedGraph.class index 3491825..2f7bcf6 100644 Binary files a/out/production/ProjektGraph/graph/DirectedGraph.class and b/out/production/ProjektGraph/graph/DirectedGraph.class differ diff --git a/out/production/ProjektGraph/graph/UndirectedGraph.class b/out/production/ProjektGraph/graph/UndirectedGraph.class index 378fc4b..bb03a8c 100644 Binary files a/out/production/ProjektGraph/graph/UndirectedGraph.class and b/out/production/ProjektGraph/graph/UndirectedGraph.class differ