- Timestamp:
- 06/04/09 22:11:32 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/f8-to-f1/geno_f8.cpp
r9 r10 412 412 413 413 Production *p = prodIter->second; 414 SubProduction *sp = &(p->subproductions.at(randomN(p->subproductions.size()))); 414 SubProduction *sp; 415 if (p->subproductions.size() > 0) { 416 sp = &(p->subproductions.at(randomN(p->subproductions.size()))); 417 } else { 418 mutated += in; 419 chg = -1.0; 420 return mutated; 421 } 415 422 416 423 int commandsToInsert = /*randomN(3) +*/ 1; … … 418 425 for (int i = 0; i < commandsToInsert; i++) { 419 426 ActionStrP a; 420 a.action = actions.at(randomN(actions.size())); 427 if (actions.size() > 0) { 428 a.action = actions.at(randomN(actions.size())); 429 } else { 430 mutated += in; 431 chg = -1.0; 432 return mutated; 433 } 421 434 insertLen += a.action->getF8Representation().len(); 422 435 if (a.action->ignoreParams == false && a.action->name[0] == 'P') { … … 453 466 454 467 Lsystem *lsystem = this->converter->createLsystem(in); 455 if (lsystem == NULL ) {468 if (lsystem == NULL || lsystem->productions.size() == 0) { 456 469 mutated += in; 457 470 chg = -1.0; … … 476 489 } 477 490 478 SubProduction *subproduction = &(prodIter->second->subproductions[randomN(prodIter->second->subproductions.size())]); 479 int firstActionIdx = randomN(subproduction->actions.size()); 491 SubProduction *subproduction; 492 if (prodIter->second->subproductions.size() > 0) { 493 subproduction = &(prodIter->second->subproductions[randomN(prodIter->second->subproductions.size())]); 494 } else { 495 mutated += in; 496 chg = -1.0; 497 return mutated; 498 } 499 int firstActionIdx; 500 if (subproduction->actions.size() > 0) { 501 firstActionIdx = randomN(subproduction->actions.size()); 502 } else { 503 mutated += in; 504 chg = -1.0; 505 return mutated; 506 } 480 507 int i; 481 508 vector<ActionStrP> newActions; … … 555 582 int random1 = randomN(interestingSubproductions.size()); 556 583 SubProduction *randomSubproduction = interestingSubproductions[random1]; 557 int random2 = randomN(randomSubproduction->conditions.size()); 584 int random2 = randomN(randomSubproduction->conditions.size()); //all interesting conditions have conditions.size() > 0 558 585 Condition *c = &(randomSubproduction->conditions.at(random2)); 559 586 c->relation = this->getDifferentCondition(c->relation); … … 572 599 573 600 Lsystem *lsystem = this->converter->createLsystem(in); 574 if (lsystem == NULL ) {601 if (lsystem == NULL || lsystem->productions.size() == 0) { 575 602 mutated += in; 576 603 chg = -1.0; … … 1094 1121 subprodIter != prodIter->second->subproductions.end(); subprodIter++) { 1095 1122 //conditions 1096 for (vector<Condition>::iterator condIter = (*subprodIter).conditions.begin(); 1097 condIter != (*subprodIter).conditions.end(); condIter++) { 1098 vector<SString>::iterator searchIter = find(paramNames.begin(), paramNames.end(), 1099 (*condIter).parameter); 1100 if (searchIter == paramNames.end()) { //unknown parameter name! 1101 //choose random existing parameter 1102 (*condIter).parameter = paramNames[randomN(paramNames.size())]; 1123 if (paramNames.size() > 0) { 1124 for (vector<Condition>::iterator condIter = (*subprodIter).conditions.begin(); 1125 condIter != (*subprodIter).conditions.end(); condIter++) { 1126 vector<SString>::iterator searchIter = find(paramNames.begin(), paramNames.end(), 1127 (*condIter).parameter); 1128 if (searchIter == paramNames.end()) { //unknown parameter name! 1129 //choose random existing parameter 1130 (*condIter).parameter = paramNames[randomN(paramNames.size())]; 1131 } 1103 1132 } 1133 } else { //no params, so delete all conditions 1134 (*subprodIter).conditions.clear(); 1104 1135 } 1105 1136 … … 1109 1140 SString &actionName = (*actionIter).action->name; 1110 1141 if (actionName[0] == 'n') { 1111 vector<SString>::iterator searchIter = find(paramNames.begin(), paramNames.end(), 1112 actionName); 1113 if (searchIter != paramNames.end()) { //valid name 1114 //ensure it is linked to the correct production 1115 (*actionIter).action = newLsystem->getParamProduction(actionName); 1116 } else { 1117 //link to random parameter prodution 1118 SString name = paramNames[randomN(paramNames.size())]; 1119 (*actionIter).action = newLsystem->getParamProduction(name); 1142 if (paramNames.size() > 0) { 1143 vector<SString>::iterator searchIter = find(paramNames.begin(), paramNames.end(), 1144 actionName); 1145 if (searchIter != paramNames.end()) { //valid name 1146 //ensure it is linked to the correct production 1147 (*actionIter).action = newLsystem->getParamProduction(actionName); 1148 } else { 1149 //link to random parameter prodution 1150 SString name = paramNames[randomN(paramNames.size())]; 1151 (*actionIter).action = newLsystem->getParamProduction(name); 1152 } 1153 } else { //no params, so delete this param production 1154 (*subprodIter).actions.erase(actionIter); //TODO sprawdzić zachowanie iteratora!!! 1120 1155 } 1121 1156 } else if (actionName[0] == 'P') {
Note: See TracChangeset
for help on using the changeset viewer.