Knoten zwischKnoten;
boolean vorhandenAll;
Iterator<Integer> it;
Iterator<Integer> it1;
Iterator<Integer> it2;
RobEA aktRob = null;
EndlicherAutomat[] kind;
ArrayList<Integer> zustaende;
RobCode[] robC = new RobCode[1];
Knoten[] knotList = new Knoten[rob.length];
Condition[] condListe = new Condition[rob.length];
ArrayList<Long> vert = new ArrayList<Long>(rob.length);
if (rob.length <= 0 || rob[0] == null) {
StaticMethods.log(StaticMethods.LOG_ERROR,
"Kein Roboter zum Rekombinieren übergeben ("
+ this + ")",
this.pars);
}
id = rob[0].id();
kind = new EndlicherAutomat[rob[0].vAuts().length];
/*
* Ersetzt alle Vorkommnisse von <code>null</code> im Array rob durch
* gültige im Array weiter vorne stehende Roboter. Dabei wird die
* Liste der Roboter VOR dem ersten Vorkommnis von <code>null</code>
* immer wieder über das Array gelegt und die null-Werte werden
* überschrieben:
*
* [1 3 null null null null] => [1 3 1 3 1 3].
*
* Wenn nach dem ersten Vorkommnis von <code>null</code> ein gültiger
* Roboter vorkommt (dies ist allerdings kein erw�nschter Fall), dann
* wird er im Array belassen.
*/
anzRobs = -1;
for (int i = 0; i < rob.length; i++) {
if (rob[i] == null) {
if (anzRobs < 0) {
anzRobs = i;
}
rob[i] = rob[i % anzRobs];
}
}
fitness = new int[rob[0].vAuts().length];
for (int i = 0; i < rob[0].vAuts().length; i++) {
vert.clear();
// Erzeuge Wahrscheinlichkeitsverteilung fitnessproportional.
for (int j = 0; j < rob.length; j++) {
if (rob[j].getFitness()[i] > 0) {
vert.add(new Long(rob[j].getFitness()[i]));
} else {
vert.add(new Long(0));
}
}
aktRob = (RobEA) MiscMath.randVerteilung(rob, vert, this.rand);
zustaende = aktRob.vAuts()[i].getKnList();
fitness[i] = aktRob.getFitness()[i];
kind[i] = new EndlicherAutomat();
vorhandenAll = true;
// Zustände einfügen.
it = zustaende.iterator();
while (it.hasNext()) {
aktName = it.next();
for (int j = 0; j < rob.length; j++) {
zwischKnoten = rob[j].vAuts()[i].holeKnoten(aktName);
if (zwischKnoten != null) {
knotList[j] = zwischKnoten;
} else {
vorhandenAll = false;
break;
}
}
if (vorhandenAll) {
zwischKnoten = (Knoten) MiscMath.randVerteilung(knotList,
vert,
this.rand);
} else {
zwischKnoten = aktRob.vAuts()[i].holeKnoten(aktName);
}
aktion = (zwischKnoten.getInfo()).getAktion();
param = (zwischKnoten.getInfo()).getParam();
alt = (zwischKnoten.getInfo()).getAlter();
kind[i].einfuegenKnoten(aktName, aktion, param, alt);
}
kind[i].setStartBeliebig(); // Setze auf ersten vorh. Knoten.
if (aktRob.vAuts()[i].holeStartzustand() != null) {
// Setze auf Startkn, falls vorhanden.
kind[i].setStart(aktRob.vAuts()[i].holeStartzustand());
}
// Kanten einfügen.
it1 = zustaende.iterator();
while (it1.hasNext()) {
kn1 = it1.next();
it2 = zustaende.iterator();
while (it2.hasNext()) {
kn2 = it2.next();
vorhandenAll = true;
if (aktRob.vAuts()[i].kanteExistiert(kn1, kn2)) {
for (int j = 0; j < rob.length; j++) {
if (rob[j].vAuts()[i].kanteExistiert(kn1, kn2)) {
condListe[j] = rob[j].vAuts()[i].getCondZuTrans(
kn1,
kn2);
} else {
vorhandenAll = false;
break;
}
}
if (vorhandenAll) {
zCond = (Condition) MiscMath.randVerteilung(
condListe,
vert,
this.rand);
} else {
zCond = aktRob.vAuts()[i].getCondZuTrans(kn1, kn2);
}
kind[i].einfuegKante(kn1, kn2, zCond, 1);
}
}
}
}
String[] codes = new String[rob[0].vAuts().length];
for (int i = 0; i < rob[0].vAuts().length; i++) {
codes[i] = kind[i].erzeugeStringSeq();
}
// Erzeuge W'keits-Vert. fitprop. für Bedingungen.
vert.clear();
for (int j = 0; j < rob.length; j++) {
if (rob[j].getFitSum() > 0) {
vert.add(new Long(rob[j].getFitSum()));
} else {
vert.add(new Long(0));
}
}
aktRob = (RobEA) MiscMath.randVerteilung(rob, vert, this.rand);
robC[0] = new RobCode(
id,
fitness,
codes,
aktRob.getConds(),
aktRob.getTransStdCodes(),
StaticMethods.stringAusListSeqs(aktRob.getTransCodes()),
StaticMethods.stringAusListSeqs(aktRob.getVerhCodes()));
return robC;
}