Changeset 1031
 Timestamp:
 11/27/20 03:01:17 (3 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cpp/frams/_demos/evol_test.cpp
r1009 r1031 10 10 #include "frams/genetics/genman.h" 11 11 #include "frams/model/model.h" 12 #include "frams/model/geometry/modelgeometryinfo.h" 12 13 13 14 … … 25 26 double get_fitness(const Individual &ind, const char *fitness_def) 26 27 { 28 const double GEOM_DENSITY = 5.0; //needs testing and adjusting as needed  tradeoff between precision and speed 29 27 30 SString genotype = ind.geno.getGenes(); 28 31 Model model = Model(ind.geno, Model::SHAPETYPE_UNKNOWN); 29 32 double fitness = 0; 30 33 const char *p = fitness_def; 34 35 Orient axes; 36 Pt3D sizes; 31 37 while (*p) 32 38 { 33 39 switch (*p) 34 40 { 35 case '0': 36 break; 37 case '!': //special symbol for current fitness (used only in printing population stats) 38 fitness += ind.fitness; 39 break; 40 case 'l': 41 case 'L': 42 fitness += criterion(*p, genotype.length()); 43 break; 44 case 'p': 45 case 'P': 46 fitness += criterion(*p, model.getPartCount()); 47 break; 48 case 'j': 49 case 'J': 50 fitness += criterion(*p, model.getJointCount()); 51 break; 52 case 'n': 53 case 'N': 54 fitness += criterion(*p, model.getNeuroCount()); 55 break; 56 case 'c': 57 case 'C': 58 fitness += criterion(*p, model.getConnectionCount()); 59 break; 60 // TODO add more criteria as described in main() below 61 default: 62 printf("Unknown fitness criterion symbol: '%c'\n", *p); 63 exit(3); 41 case '0': 42 break; 43 case '!': //special symbol for current fitness (used only in printing population stats) 44 fitness += ind.fitness; 45 break; 46 case 'g': 47 case 'G': 48 fitness += criterion(*p, genotype.length()); 49 break; 50 case 'p': 51 case 'P': 52 fitness += criterion(*p, model.getPartCount()); 53 break; 54 case 'j': 55 case 'J': 56 fitness += criterion(*p, model.getJointCount()); 57 break; 58 case 'n': 59 case 'N': 60 fitness += criterion(*p, model.getNeuroCount()); 61 break; 62 case 'c': 63 case 'C': 64 fitness += criterion(*p, model.getConnectionCount()); 65 break; 66 case 'b': 67 case 'B': 68 fitness += criterion(*p, model.size.x * model.size.y * model.size.z); 69 break; 70 case 's': 71 case 'S': 72 fitness += criterion(*p, ModelGeometryInfo::area(model, GEOM_DENSITY)); 73 break; 74 case 'v': 75 case 'V': 76 fitness += criterion(*p, ModelGeometryInfo::volume(model, GEOM_DENSITY)); 77 break; 78 case 'l': 79 case 'L': 80 ModelGeometryInfo::findSizesAndAxes(model, GEOM_DENSITY, sizes, axes); 81 fitness += criterion(*p, sizes.x); 82 break; 83 case 'w': 84 case 'W': 85 ModelGeometryInfo::findSizesAndAxes(model, GEOM_DENSITY, sizes, axes); 86 fitness += criterion(*p, sizes.y); 87 break; 88 case 'h': 89 case 'H': 90 ModelGeometryInfo::findSizesAndAxes(model, GEOM_DENSITY, sizes, axes); 91 fitness += criterion(*p, sizes.z); 92 break; 93 default: 94 printf("Unknown fitness criterion symbol: '%c'\n", *p); 95 exit(3); 64 96 } 65 97 p++; … … 81 113 criterion_values.push_back(get_fitness(ind, crit)); 82 114 printf("%g,%g,%g", *std::min_element(criterion_values.begin(), criterion_values.end()), 83 std::accumulate(criterion_values.begin(), criterion_values.end(), 0.0) / criterion_values.size(),84 *std::max_element(criterion_values.begin(), criterion_values.end()));115 std::accumulate(criterion_values.begin(), criterion_values.end(), 0.0) / criterion_values.size(), 116 *std::max_element(criterion_values.begin(), criterion_values.end())); 85 117 } 86 118 … … 120 152 printf("Each letter corresponds to one fitness criterion, and they are all weighted and added together.\n"); 121 153 printf(" 0  a constant value of 0 that provides a flat fitness landscape (e.g. for testing biases of genetic operators).\n"); 122 printf(" l or L  genotype length in characters.\n"); 123 printf(" p or P  the number of Parts.\n"); 124 printf(" j or J  the number of Joints.\n"); 125 printf(" n or N  the number of Neurons.\n"); 126 printf(" c or C  the number of neural Connections.\n"); 127 //TODO add b  bounding box volume (from Model), s  surface area (from geometry), v  volume (from geometry), h,w,d  three consecutive dimensions (from geometry) 154 printf(" g or G  genotype length in characters.\n"); 155 printf(" p or P  number of Parts.\n"); 156 printf(" j or J  number of Joints.\n"); 157 printf(" n or N  number of Neurons.\n"); 158 printf(" c or C  number of neural Connections.\n"); 159 printf(" b or B  volume of the bounding box (absolute coordinates).\n"); 160 printf(" s or S  surface area of the Model.\n"); 161 printf(" v or V  volume of the Model.\n"); 162 printf(" l or L  length of the Model (largest dimension).\n"); 163 printf(" w or W  width of the Model (2nd largest dimension).\n"); 164 printf(" h or H  height of the Model (smallest dimension).\n"); 128 165 129 166 printf("\nThe output consists of 7 columns separated by the TAB character.\n"); … … 193 230 { 194 231 printf("Evaluation %d", i); 195 for (char c : string("!PJNC L"))232 for (char c : string("!PJNCG")) 196 233 { 197 234 printf("\t");
Note: See TracChangeset
for help on using the changeset viewer.