diff --git a/.idea/Routen2.java b/.idea/Routen2.java new file mode 100644 index 0000000..42e2e64 --- /dev/null +++ b/.idea/Routen2.java @@ -0,0 +1,157 @@ +package gfn.marc; + +// Hilfsklasse zur Simulation der Aufgabenstellung + +import java.util.ArrayList; +import java.util.HashMap; + +public class Routen { + + static Ort a = new Ort("A", 1600, 5.6); + static Ort b = new Ort("B", 1800, 5.2); + static Ort c = new Ort("C", 1300, 5.5); + static Ort d = new Ort("D", 1450, 4.9); + static Ort e = new Ort("E", 1400, 5.1); + + static { + a.setKnoten(b, c, d); + b.setKnoten(a, c, e); + c.setKnoten(a, b); + d.setKnoten(a, e); + e.setKnoten(b, d); + + a.berechneRouten(); + b.berechneRouten(); + c.berechneRouten(); + d.berechneRouten(); + e.berechneRouten(); + } + + public static String[][] getRoute(String SB, String SE) { + for (Ort ort : Ort.orte) { + if (ort.id.matches(SB)) { + return ort.routen.get(SB.concat(SE)); + } + } + return null; + } + +} + +class Ort { + static ArrayList orte = new ArrayList<>(); + static HashMap orteMap = new HashMap<>(); + String id; + int frachtkapazitaet; + double frachtkosten; // EUR/kg + ArrayList knoten; + HashMap knotenMap; + HashMap routen; + + public Ort(String id, int frachtkapazitaet, double frachtkosten) { + this.id = id; + this.frachtkapazitaet = frachtkapazitaet; + this.frachtkosten = frachtkosten; + Ort.orte.add(this); + Ort.orteMap.put(this.id, this); + } + + public void setKnoten(Ort... knotenArray) { + ArrayList knoten = new ArrayList<>(); + HashMap knotenMap = new HashMap<>(); + for (Ort k : knotenArray) { + knoten.add(k); + knotenMap.put(k.id, k); + } + this.knoten = knoten; + this.knotenMap = knotenMap; + } + + void berechneRouten() { + HashMap routen = new HashMap<>(); + 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; + } + + + int i = 0; + int j = 1; + for (int k = 0; k < start.knoten.size(); k++) { + Ort startKnoten = start.knoten.get(k); + 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 { + startKnoten = startKnoten.knoten + for (Ort folgeKnoten1 : startKnoten.knoten) { + if (folgeKnoten1.knoten.contains(ziel)) { + if (folgeKnoten1.id.equals(startKnoten.id)) continue; + 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; + } +} + + diff --git a/out/production/frachtfluege/gfn/marc/Frachtfluege.class b/out/production/frachtfluege/gfn/marc/Frachtfluege.class index 68814d9..ee27b29 100644 Binary files a/out/production/frachtfluege/gfn/marc/Frachtfluege.class and b/out/production/frachtfluege/gfn/marc/Frachtfluege.class differ diff --git a/out/production/frachtfluege/gfn/marc/Ort.class b/out/production/frachtfluege/gfn/marc/Ort.class index 83027d2..a7047a2 100644 Binary files a/out/production/frachtfluege/gfn/marc/Ort.class and b/out/production/frachtfluege/gfn/marc/Ort.class differ diff --git a/src/gfn/marc/Routen.java b/src/gfn/marc/Routen.java index 6a89056..07fa904 100644 --- a/src/gfn/marc/Routen.java +++ b/src/gfn/marc/Routen.java @@ -84,51 +84,50 @@ class Ort { 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 { - 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++; - } + for (Ort folgeKnoten1 : startKnoten.knoten) { + if (folgeKnoten1.knoten.contains(ziel)) { + if (folgeKnoten1.id.equals(startKnoten.id)) continue; + 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++; } } } @@ -147,10 +146,12 @@ class Ort { } System.out.println(); } - } } this.routen = routen; } } + + +