Rundreise unheuristisch:
@Override
public void run() {
a(0, 0, new ArrayDeque<>());
prozent = 0;
b(0, 0, new ArrayDeque<>());
}
void a(int index, int syss1index, ArrayDeque<Pro2> list1) {
if (index == routelen) {
Sys s1 = syss2.get(list1.getLast().sysid2);
Sys s2 = syss2.get(list1.getFirst().sysid1);
float d = (s1.x - s2.x) * (s1.x - s2.x) + (s1.y - s2.y) * (s1.y - s2.y) + (s1.z - s2.z) * (s1.z - s2.z);
if (d <= maxdis) {
ArrayList<Pro2> pro2s = getPro2s(s1, s2, maxbuy, minpro);
if (pro2s != null) {
for (Pro2 pro2 : pro2s) {
if (list1.isEmpty() || list1.getLast().staid2 == pro2.staid1 && list1.getFirst().staid1 == pro2.staid2) {
list1.add(pro2);
list2.add(new ArrayList<>(list1));
list1.removeLast();
}
}
}
}
return;
}
if (index == 0) {
index++;
for (int j = from; j < to; j++) {
a(index, j, new ArrayDeque<>());
if ((j - from) * 100 / (to - from) > prozent) {
prozent = (j - from) * 100 / (to - from);
println(this + " , pro = " + prozent);
}
}
} else {
index++;
Sys s1 = syss1.get(syss1index);
for (int j = syss1index + 1; j < syss1.size(); j++) {
Sys s2 = syss1.get(j);
float d = (s1.x - s2.x) * (s1.x - s2.x) + (s1.y - s2.y) * (s1.y - s2.y) + (s1.z - s2.z) * (s1.z - s2.z);
if (d <= maxdis) {
ArrayList<Pro2> pro2s = getPro2s(s1, s2, maxbuy, minpro);
if (pro2s != null) {
for (Pro2 pro2 : pro2s) {
if (list1.isEmpty() || list1.getLast().staid2 == pro2.staid1) {
list1.add(pro2);
a(index, j, list1);
list1.removeLast();
}
}
}
}
}
}
}
void b(int index, int i, ArrayDeque<Pro2> list1) {
if (index == routelen) {
Sys s1 = syss2.get(list1.getLast().sysid1);
Sys s2 = syss2.get(list1.getFirst().sysid2);
float d = (s1.x - s2.x) * (s1.x - s2.x) + (s1.y - s2.y) * (s1.y - s2.y) + (s1.z - s2.z) * (s1.z - s2.z);
if (d <= maxdis) {
ArrayList<Pro2> pro2s = getPro2s(s2, s1, maxbuy, minpro);
if (pro2s != null) {
for (Pro2 pro2 : pro2s) {
if (list1.isEmpty() || list1.getLast().staid1 == pro2.staid2 && list1.getFirst().staid2 == pro2.staid1) {
list1.add(pro2);
list2.add(new ArrayList<>(list1));
list1.removeLast();
}
}
}
}
return;
}
if (index == 0) {
index++;
for (int j = from; j < to; j++) {
b(index, j, new ArrayDeque<>());
if ((j - from) * 100 / (to - from) > prozent) {
prozent = (j - from) * 100 / (to - from);
println(this + " , pro = " + prozent);
}
}
} else {
index++;
Sys s1 = syss1.get(i);
for (int j = i + 1; j < syss1.size(); j++) {
Sys s2 = syss1.get(j);
float d = (s1.x - s2.x) * (s1.x - s2.x) + (s1.y - s2.y) * (s1.y - s2.y) + (s1.z - s2.z) * (s1.z - s2.z);
if (d <= maxdis) {
ArrayList<Pro2> pro2s = getPro2s(s2, s1, maxbuy, minpro);
if (pro2s != null) {
for (Pro2 pro2 : pro2s) {
if (list1.isEmpty() || list1.getLast().staid1 == pro2.staid2) {
list1.add(pro2);
b(index, j, list1);
list1.removeLast();
}
}
}
}
}
}
}
syss1
„index iterable“
syss2
„SysID pullable“
Pro2
way from Sys a/Sta a to Sys b/Sta b inclusive costs.
if (index == 0) {
Der beginn der rekursiven Methode
} else {
Zwischenschritt(e)
if (index == routelen) {
ende der rekursiven Methode
a
und b
rekursive Methoden, nicht wechselseitiger Aufruf
list1
„ordered temporary results („one cyclic route“)“
list2
„ordered results“
Wie kann man das kürzen und auch beispielsweise if (list1.isEmpty() || list1.getLast().staid2 == pro2.staid1) {
und if (list1.isEmpty() || list1.getLast().staid2 == pro2.staid1 && list1.getFirst().staid1 == pro2.staid2) {
kürzen?
Mir ist das zu unübersichtlich und auch doppelter Code, schwierig nachzuvollziehen und zu erweitern.
void b(int index, int i
das sollte eigentlich heißen void b(int index, int syss1index
und j
müsste eigentlich syss1index2
heißen.