Changeset 33
- Timestamp:
- 10/31/09 00:47:01 (15 years ago)
- Location:
- cpp/f8-to-f1
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/f8-to-f1/conv_f8tof1.cpp
r32 r33 172 172 } 173 173 if (neurons) { 174 for (vector<NeuronProduction*>::iterator iter = this->neuronProductions.begin(); 174 for (vector<NeuronProduction*>::iterator iter = this->neuronProductions.begin(); 175 175 iter != this->neuronProductions.end(); iter++) { 176 176 actions.push_back(*iter); … … 283 283 string sname = sstringToString(name); 284 284 if (position == -1) { 285 this->parameters.push_back(sname); 285 this->parameters.push_back(sname); 286 286 this->paramValues[sname] = value; 287 287 } else { … … 516 516 } 517 517 518 519 520 521 522 523 524 525 526 #define FIELDSTRUCT GenoConv_F8ToF1 527 528 static ParamEntry GENOCONVf8param_tab[]= 529 { 530 {"Genetics: f8: limits",1,1,}, 531 {"f8conv_maxlen", 0, 0, "Maximal genotype length", "d 10 10000 500", FIELD(maxF1Length),"Maximal length of the resulting f1 genotype, in characters. If the f8 L-system produces longer f1 genotype, it will be considered incorrect.", }, 532 {0,}, 533 }; 534 535 #undef FIELDSTRUCT 536 537 GenoConv_F8ToF1::GenoConv_F8ToF1() 538 { 539 name = "f8 converter"; 540 in_format = '8'; 541 out_format = '1'; 542 mapsupport = 0; 543 info = "Generative encoding"; 544 maxF1Length = 500; 545 par.setParamTab(GENOCONVf8param_tab); 546 par.select(this); 547 par.setDefault(); 548 } 549 550 518 551 vector<SString> GenoConv_F8ToF1::readProductionNames(const SString &in) { 519 552 vector<SString> names; … … 764 797 } 765 798 #undef CONV_DEBUG 799 -
cpp/f8-to-f1/conv_f8tof1.h
r26 r33 217 217 map<string, PrimitiveProduction*> primitiveProductions; 218 218 map<string, ParamProduction*> paramProductions; 219 219 220 220 void removeEmptySubproductionsAndProductions(); 221 221 }; 222 223 224 225 222 226 223 227 /// Converter between f8 and f1 format 224 228 class GenoConv_F8ToF1 : public GenoConverter { 225 229 public: 226 /// Default constructor 227 GenoConv_F8ToF1() { 228 name = "f8 to f1 converter"; 229 in_format = '8'; 230 out_format = '1'; 231 mapsupport = 0; 232 info = "ble"; 233 maxF1Length = 500; 234 } 235 236 /// Constructor with parameter 237 /// @param f1LengthLimit If resulting f1 genotype is longer than f1LengthLimit, converter aborts its job 238 GenoConv_F8ToF1(int f1LengthLimit) { 239 name = "f8 to f1 converter"; 240 in_format = '8'; 241 out_format = '1'; 242 mapsupport = 0; 243 info = "ble"; 244 maxF1Length = f1LengthLimit; 245 } 246 230 Param par; 231 232 GenoConv_F8ToF1(); 247 233 ~GenoConv_F8ToF1() {} 248 234 249 235 SString convert(SString &in, MultiMap *map); 250 236 251 237 /// check syntax of given f8 genotype 252 238 /// @param geno f8 genotype to be checked 253 239 bool checkSyntax(const char *geno); 254 240 255 241 /// returns names of productions in a given genotype 256 242 /// @param in f8 genotype 257 243 vector<SString> readProductionNames(const SString &in); 258 244 //Lsystem* createLsystem(const SString &in); 259 245 260 246 /// creates Lsystem object based on input genotype 261 247 /// @param f8 genotype 262 248 Lsystem* createLsystem(SString in); 249 250 int maxF1Length; 263 251 protected: 264 252 bool parseInput(const char* src, Lsystem* lsys); 265 int maxF1Length;266 253 }; 267 254 -
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 -
cpp/f8-to-f1/geno_f8.h
r30 r33 52 52 Geno_f8(); 53 53 ~Geno_f8(); 54 55 //probabilities of mutation operators54 55 //probabilities of mutation operators 56 56 double operation[F8_OPERATION_COUNT]; 57 57 58 58 int checkValidity(const char * geno); 59 59 int validate(char * &geno); … … 62 62 unsigned long style(const char *g, int pos); 63 63 char* getSimplest(); 64 64 65 65 SString testMutate(SString &in, int method); 66 66 protected: 67 67 GenoConv_F8ToF1 *converter; 68 static const int maxTotalIterations = 200;69 static const int maxNormalIterations = 100;70 68 71 69 vector<char> simpleCommandLetters;
Note: See TracChangeset
for help on using the changeset viewer.