weiterentwickelt

This commit is contained in:
Marc Koch 2020-04-13 17:45:07 +02:00
parent ff43a6eec8
commit 24a5e51f70
4 changed files with 80 additions and 12 deletions

View File

@ -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");
}
}

View File

@ -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<Ort> orte = new ArrayList<>();
static HashMap<String, Ort> 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<String, String[][]> 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;
}
}