Changeset 33 for cpp/f8-to-f1/geno_f8.cpp
- Timestamp:
- 10/31/09 00:47:01 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/f8-to-f1/geno_f8.cpp
r30 r33 32 32 {"f8_mut_chg_cond_sign", 0, 0, "Change condition sign", "f 0 100 7",FIELD(operation[F8_CHANGE_CONDITION_SIGN]),"mutation: probability of changing a condition sign", }, 33 33 {"f8_mut_add_param", 0, 0, "Add parameter", "f 0 100 8", FIELD(operation[F8_ADD_PARAMETER]),"mutation: probability of adding a parameter to the production", }, 34 {"f8_mut_add_cond", 0, 0, "Add condition", "f 0 100 8", FIELD(operation[F8_ADD_CONDITION]),"mutation: probability of ad ing a condition to the subproduction", },34 {"f8_mut_add_cond", 0, 0, "Add condition", "f 0 100 8", FIELD(operation[F8_ADD_CONDITION]),"mutation: probability of adding a condition to the subproduction", }, 35 35 {"f8_mut_add_subprod", 0, 0, "Add subproduction", "f 0 100 8", FIELD(operation[F8_ADD_SUBPRODUCTION]),"mutation: probability of adding a subproduction", }, 36 {"f8_mut_chg_iter_number", 0, 0, "Change iteration number", "f 0 100 7", FIELD(operation[F8_CHANGE_ITERATIONS_NUMBER]),"mutation: probability of changing a n iterations number", },36 {"f8_mut_chg_iter_number", 0, 0, "Change iteration number", "f 0 100 7", FIELD(operation[F8_CHANGE_ITERATIONS_NUMBER]),"mutation: probability of changing a number of iterations", }, 37 37 {"f8_mut_del_param", 0, 0, "Delete parameter", "f 0 100 8", FIELD(operation[F8_DELETE_PARAMETER]),"mutation: probability of deleting a parameter", }, 38 38 {"f8_mut_del_cond", 0, 0, "Delete condition", "f 0 100 8", FIELD(operation[F8_DELETE_CONDITION]),"mutation: probability of deleting a condition", }, 39 {"f8_mut_add_loop", 0, 0, "Add loop", "f 0 100 0", FIELD(operation[F8_ADD_LOOP]),"mutation: probability of ad ing a loop", },39 {"f8_mut_add_loop", 0, 0, "Add loop", "f 0 100 0", FIELD(operation[F8_ADD_LOOP]),"mutation: probability of adding a loop", }, 40 40 {"f8_mut_del_loop", 0, 0, "Delete loop", "f 0 100 0", FIELD(operation[F8_DELETE_LOOP]),"mutation: probability of deleting a loop", }, 41 41 {"f8_mut_del_prod", 0, 0, "Delete production", "f 0 100 8", FIELD(operation[F8_DELETE_PRODUCTION]),"mutation: probability of deleting a production", }, … … 63 63 this->simpleCommandLetters.push_back('^'); 64 64 this->converter = new GenoConv_F8ToF1(); 65 65 66 66 par.setParamTab(GENO8param_tab); 67 67 par.select(this); 68 68 par.setDefault(); 69 70 /*mutation_method_names = new char*[F8_OPERATION_COUNT - 1]; 69 70 /*mutation_method_names = new char*[F8_OPERATION_COUNT - 1]; //FIXME 71 71 int index = 0; 72 72 mutation_method_names[index++]="changed beginning argument"; … … 511 511 newActions.push_back(subproduction->actions[i]); 512 512 } 513 for (i = firstActionIdx; i <= firstActionIdx + randomN(4) + 1 513 for (i = firstActionIdx; i <= firstActionIdx + randomN(4) + 1 514 514 && i < subproduction->actions.size(); i++) { //1..4 actions 515 515 newSubProd->actions.push_back(subproduction->actions[i]); … … 551 551 552 552 delete lsystem; 553 553 554 554 chg = (float) len / (float) in.len(); 555 555 return mutated; … … 569 569 mutated += in; 570 570 chg = 0.0; 571 delete lsystem; 571 572 return mutated; 572 573 } 573 574 int counter = 0; 574 575 575 vector<SString> productionNamesSS = this->converter->readProductionNames(in); 576 576 vector<string> productionNames; … … 601 601 //choose production to which we will append the contents of deleted production 602 602 string prodNameToAppendTo = productionNames[randomN(productionNames.size())]; 603 603 604 604 int len = 0; 605 605 606 606 Production* deletedProd = lsystem->productions[prodNameToDelete]; 607 607 Production* appendProd = lsystem->productions[prodNameToAppendTo]; … … 613 613 } 614 614 } 615 615 616 616 //copy subproductions 617 617 for (vector<SubProduction>::iterator subprodIter = deletedProd->subproductions.begin(); … … 639 639 } 640 640 lsystem->productions.erase(string(prodNameToDelete)); 641 641 642 642 int paramCount = appendProd->parameters.size(); 643 643 for (map<string, Production*>::iterator prodIter = lsystem->productions.begin(); … … 647 647 for (vector<ActionStrP>::iterator actionIter = (*subprodIter).actions.begin(); 648 648 actionIter != (*subprodIter).actions.end(); actionIter++) { 649 if ((*actionIter).action != NULL && (*actionIter).action->name != NULL) { 649 if ((*actionIter).action != NULL && (*actionIter).action->name != NULL) { 650 650 if ((*actionIter).action->name == stringToSString(prodNameToDelete)) { 651 651 (*actionIter).action = appendProd; … … 659 659 } 660 660 } 661 661 662 662 } 663 663 } … … 665 665 } 666 666 delete deletedProd; 667 668 667 668 669 669 mutated = lsystem->toString(); 670 670 671 671 delete lsystem; 672 672 673 673 chg = (float) len / (float) in.len(); 674 674 return mutated; … … 677 677 SString Geno_f8::mutateChangeConditionSign(SString &in, float& chg) { 678 678 SString mutated; 679 679 680 680 Lsystem *newLsystem = this->converter->createLsystem(in); 681 681 if (newLsystem == NULL) { … … 684 684 return mutated; 685 685 } 686 686 687 687 map<int, SubProduction*> interestingSubproductions; 688 688 int counter = 0; 689 689 690 690 for (map<string, Production*>::iterator prodIter = newLsystem->productions.begin(); 691 691 prodIter != newLsystem->productions.end(); prodIter++) { … … 698 698 } 699 699 } 700 700 701 701 if (interestingSubproductions.size() > 0) { 702 702 int random1 = randomN(interestingSubproductions.size()); … … 707 707 chg = 2.0 / (float) in.len(); 708 708 } 709 709 710 710 mutated = newLsystem->toString(); 711 711 712 712 delete newLsystem; 713 713 714 714 return mutated; 715 715 } … … 717 717 SString Geno_f8::mutateAddParameter(SString &in, float& chg) { 718 718 SString mutated; 719 719 720 720 Lsystem *lsystem = this->converter->createLsystem(in); 721 721 if (lsystem == NULL || lsystem->productions.size() == 0) { … … 724 724 return mutated; 725 725 } 726 726 727 727 //cout << "addParameter 1" << endl; 728 728 int rnd = randomN(lsystem->productions.size()); 729 729 int chglen = 0; 730 730 731 731 SString prodName = ""; 732 732 733 733 int counter = 0; 734 734 for (map<string, Production*>::iterator prodIter = lsystem->productions.begin(); … … 746 746 } 747 747 } 748 748 749 749 if (prodName == stringToSString(lsystem->firstProductionName)) { 750 750 lsystem->startParams[sstringToString(newParam)] = 0.0; … … 1083 1083 (method == 13) ? "F8_ADD_LOOP" : 1084 1084 (method == 14) ? "F8_DELETE_LOOP" : 1085 (method == 15) ? "F8_OPERATION_COUNT" : " babol";1085 (method == 15) ? "F8_OPERATION_COUNT" : "*invalid*"; 1086 1086 //cout << "-------------------- " << mutationName << " --------------------" << endl; 1087 1087 #endif
Note: See TracChangeset
for help on using the changeset viewer.