diff --git a/out/production/frachtfluege/gfn/marc/Ort.class b/out/production/frachtfluege/gfn/marc/Ort.class index c3a6ac5..83027d2 100644 Binary files a/out/production/frachtfluege/gfn/marc/Ort.class and b/out/production/frachtfluege/gfn/marc/Ort.class differ diff --git a/out/production/frachtfluege/gfn/marc/Routen.class b/out/production/frachtfluege/gfn/marc/Routen.class index 8562d9f..6e95f16 100644 Binary files a/out/production/frachtfluege/gfn/marc/Routen.class and b/out/production/frachtfluege/gfn/marc/Routen.class differ diff --git a/src/gfn/marc/Frachtfluege.java b/src/gfn/marc/Frachtfluege.java index 79154e4..f82f7a2 100644 --- a/src/gfn/marc/Frachtfluege.java +++ b/src/gfn/marc/Frachtfluege.java @@ -4,6 +4,8 @@ public class Frachtfluege { public static void main(String[] args) { - String[][] route = Routen.getRoute("A", "B"); + + String[][] route = Routen.getRoute("C", "E"); + } } diff --git a/src/gfn/marc/Routen.java b/src/gfn/marc/Routen.java index e80d1d2..6a89056 100644 --- a/src/gfn/marc/Routen.java +++ b/src/gfn/marc/Routen.java @@ -4,8 +4,6 @@ package gfn.marc; import java.util.*; -import static java.util.Map.entry; - public class Routen { static Ort a = new Ort("A", 1600, 5.6); @@ -41,6 +39,7 @@ public class Routen { class Ort { static ArrayList orte = new ArrayList<>(); + static HashMap orteMap = new HashMap<>(); String id; int frachtkapazitaet; double frachtkosten; // EUR/kg @@ -53,6 +52,7 @@ class Ort { this.frachtkapazitaet = frachtkapazitaet; this.frachtkosten = frachtkosten; Ort.orte.add(this); + Ort.orteMap.put(this.id, this); } public void setKnoten(Ort... knotenArray) { @@ -68,23 +68,89 @@ class Ort { void berechneRouten() { HashMap routen = new HashMap<>(); - for (Ort o : orte) { - if (!this.id.equals(o.id)) { - routen.put(this.id.concat(o.id), new String[this.knoten.size()][orte.size()]); + Ort start = this; + for (Ort ziel : orte) { + if (!start.id.equals(ziel.id)) { + routen.put(start.id.concat(ziel.id), new String[orte.size()][orte.size() + 1]); + String[][] tabelle = routen.get(start.id.concat(ziel.id)); + for (int i = 0; i < tabelle.length; i++) { + tabelle[i][0] = start.id; + } - for (int i = 0; i < routen.get(this.id.concat(o.id)).length; i++) { - routen.get(this.id.concat(o.id))[i][0] = this.id; - for (int j = 1; j < routen.get(this.id.concat(o.id))[i].length; j++) { - if (routen.get(this.id.concat(o.id))[i][j].isBlank()) { - - // TODO: Hier weitermachen! + int i = 0; + int j = 1; + for (Ort startKnoten : start.knoten) { + if (startKnoten.id.equals(ziel.id)) { + tabelle[i][j] = ziel.id; + i++; + } else { + if (startKnoten.knoten.contains(ziel)) { + tabelle[i][j] = startKnoten.id; + tabelle[i][j + 1] = ziel.id; + i++; + } else { + for (Ort folgeKnoten1 : startKnoten.knoten) { + if (folgeKnoten1.knoten.contains(ziel)) { + if (folgeKnoten1.id.equals(start.id)) continue; + tabelle[i][j] = startKnoten.id; + tabelle[i][j + 1] = folgeKnoten1.id; + tabelle[i][j + 2] = ziel.id; + i++; + } else { + for (Ort folgeKnoten2 : folgeKnoten1.knoten) { + if (folgeKnoten2.knoten.contains(ziel)) { + if (folgeKnoten2.id.equals(folgeKnoten1.id) || + folgeKnoten2.id.equals(startKnoten.id) || + folgeKnoten2.id.equals(start.id) || + folgeKnoten1.id.equals(startKnoten.id) || + folgeKnoten1.id.equals(start.id)) continue; + tabelle[i][j] = startKnoten.id; + tabelle[i][j + 1] = folgeKnoten1.id; + tabelle[i][j + 2] = folgeKnoten2.id; + tabelle[i][j + 3] = ziel.id; + i++; + } else { + for (Ort folgeKnoten3 : folgeKnoten2.knoten) { + if (folgeKnoten3.knoten.contains(ziel)) { + if (folgeKnoten3.id.equals(folgeKnoten2.id) || + folgeKnoten3.id.equals(folgeKnoten1.id) || + folgeKnoten3.id.equals(startKnoten.id) || + folgeKnoten3.id.equals(start.id) || + folgeKnoten2.id.equals(folgeKnoten1.id) || + folgeKnoten2.id.equals(startKnoten.id) || + folgeKnoten2.id.equals(start.id) || + folgeKnoten1.id.equals(startKnoten.id) || + folgeKnoten1.id.equals(start.id)) continue; + tabelle[i][j] = startKnoten.id; + tabelle[i][j + 1] = folgeKnoten1.id; + tabelle[i][j + 2] = folgeKnoten2.id; + tabelle[i][j + 3] = folgeKnoten3.id; + tabelle[i][j + 4] = ziel.id; + i++; + } + } + } + } + } } } } } + System.out.println("-----------------------------------"); + System.out.println("Route: " + start.id.concat(ziel.id)); + for (int x = 0; x < tabelle.length; x++) { + for (int y = 0; y < tabelle[x].length; y++) { + if (tabelle[x][y] != null) { + System.out.print(tabelle[x][y] + " "); + } + } + System.out.println(); + } + } } this.routen = routen; } } +