weiterentwickelt
This commit is contained in:
parent
ff43a6eec8
commit
24a5e51f70
Binary file not shown.
Binary file not shown.
|
|
@ -4,6 +4,8 @@ public class Frachtfluege {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
String[][] route = Routen.getRoute("A", "B");
|
|
||||||
|
String[][] route = Routen.getRoute("C", "E");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ package gfn.marc;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static java.util.Map.entry;
|
|
||||||
|
|
||||||
public class Routen {
|
public class Routen {
|
||||||
|
|
||||||
static Ort a = new Ort("A", 1600, 5.6);
|
static Ort a = new Ort("A", 1600, 5.6);
|
||||||
|
|
@ -41,6 +39,7 @@ public class Routen {
|
||||||
|
|
||||||
class Ort {
|
class Ort {
|
||||||
static ArrayList<Ort> orte = new ArrayList<>();
|
static ArrayList<Ort> orte = new ArrayList<>();
|
||||||
|
static HashMap<String, Ort> orteMap = new HashMap<>();
|
||||||
String id;
|
String id;
|
||||||
int frachtkapazitaet;
|
int frachtkapazitaet;
|
||||||
double frachtkosten; // EUR/kg
|
double frachtkosten; // EUR/kg
|
||||||
|
|
@ -53,6 +52,7 @@ class Ort {
|
||||||
this.frachtkapazitaet = frachtkapazitaet;
|
this.frachtkapazitaet = frachtkapazitaet;
|
||||||
this.frachtkosten = frachtkosten;
|
this.frachtkosten = frachtkosten;
|
||||||
Ort.orte.add(this);
|
Ort.orte.add(this);
|
||||||
|
Ort.orteMap.put(this.id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKnoten(Ort... knotenArray) {
|
public void setKnoten(Ort... knotenArray) {
|
||||||
|
|
@ -68,23 +68,89 @@ class Ort {
|
||||||
|
|
||||||
void berechneRouten() {
|
void berechneRouten() {
|
||||||
HashMap<String, String[][]> routen = new HashMap<>();
|
HashMap<String, String[][]> routen = new HashMap<>();
|
||||||
for (Ort o : orte) {
|
Ort start = this;
|
||||||
if (!this.id.equals(o.id)) {
|
for (Ort ziel : orte) {
|
||||||
routen.put(this.id.concat(o.id), new String[this.knoten.size()][orte.size()]);
|
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;
|
this.routen = routen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue