Changeset 732 for cpp/frams/_demos
- Timestamp:
- 02/15/18 00:42:07 (7 years ago)
- Location:
- cpp/frams/_demos
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/_demos/genoconv_test.cpp
r727 r732 27 27 in_format = 'x'; 28 28 } 29 SString convert(SString &i, MultiMap *map ) { return SString("after conversion..."); }29 SString convert(SString &i, MultiMap *map, bool using_checkpoints) { return SString("after conversion..."); } 30 30 ~GenoConv_Test() {} 31 31 }; … … 42 42 } 43 43 44 SString convert(SString &i, MultiMap *map )44 SString convert(SString &i, MultiMap *map, bool using_checkpoints) 45 45 { 46 46 Model mod; … … 53 53 return mod.getF0Geno().getGenes(); 54 54 } 55 55 56 56 ~GenoConv_Test2() {} 57 57 }; … … 70 70 mapsupport = 1; 71 71 } 72 SString convert(SString &in, MultiMap *map );72 SString convert(SString &in, MultiMap *map, bool using_checkpoints); 73 73 ~GenoConv_Test3() {} 74 74 }; 75 75 76 76 /** main converting routine - most important: direct conversion map example */ 77 SString GenoConv_Test3::convert(SString &in, MultiMap *map )77 SString GenoConv_Test3::convert(SString &in, MultiMap *map, bool using_checkpoints) 78 78 { 79 79 SString dst; … … 116 116 } 117 117 118 // arguments: 119 // genotype (or - meaning "read from stdin") [default: X] 120 // target format [default: 0] 121 // "checkpoints" (just write this exact word) [default: not using checkpoints] 118 122 int main(int argc, char *argv[]) 119 123 { … … 146 150 src = "X"; 147 151 char dst = (argc > 2) ? *argv[2] : '0'; 152 bool using_checkpoints = (argc > 3) ? (strcmp(argv[3], "checkpoints") == 0) : false; 148 153 149 154 printf("*** Source genotype:\n"); … … 151 156 printGen(g1); 152 157 MultiMap m; 153 Geno g2 = g1.getConverted(dst, &m );158 Geno g2 = g1.getConverted(dst, &m, using_checkpoints); 154 159 printf("*** Converted to f%c:\n", dst); 155 160 printGen(g2); 156 if (m.isEmpty()) 157 printf("(conversion map not available)\n"); 161 162 if (using_checkpoints) 163 { // using Model with checkpoints 164 Model m1(g2, false, true);//true=using_checkpoints 165 printf("\nModel built from the converted f%c genotype has %d checkpoints\n", g2.getFormat(), m1.getCheckpointCount()); 166 Model m2(g1, false, true);//true=using_checkpoints 167 printf("Model built from the source f%c genotype has %d checkpoints\n", g1.getFormat(), m2.getCheckpointCount()); 168 // accessing individual checkpoint models (if available) 169 if (m1.getCheckpointCount() > 0) 170 { 171 int c = m1.getCheckpointCount() / 2; 172 Model *cm = m1.getCheckpoint(c); 173 printf("Checkpoint #%d (%d parts, %d joint, %d neurons)\n%s", c, cm->getPartCount(), cm->getJointCount(), cm->getNeuroCount(), cm->getF0Geno().getGenesAndFormat().c_str()); 174 } 175 } 158 176 else 159 { 160 printf("Conversion map:\n"); 161 m.print(); 162 printConvMap(g1.getGenes(), g2.getGenes(), m); 163 printf("Reverse conversion map:\n"); 164 MultiMap rm; 165 rm.addReversed(m); 166 rm.print(); 167 printConvMap(g2.getGenes(), g1.getGenes(), rm); 168 } 169 170 Model mod1(g1, 1); 171 printf("\nModel map for f%c genotype:\n", g1.getFormat()); 172 printModelMap(g1.getGenes(), mod1.getMap()); 173 mod1.getMap().print(); 174 Model mod2(g2, 1); 175 printf("\nModel map for f%c genotype:\n", g2.getFormat()); 176 printModelMap(g2.getGenes(), mod2.getMap()); 177 mod2.getMap().print(); 177 { // there is no mapping for checkpoints so it's nothing interesting to see here in the checkpoints mode 178 if (m.isEmpty()) 179 printf("(conversion map not available)\n"); 180 else 181 { 182 printf("Conversion map:\n"); 183 m.print(); 184 printConvMap(g1.getGenes(), g2.getGenes(), m); 185 printf("Reverse conversion map:\n"); 186 MultiMap rm; 187 rm.addReversed(m); 188 rm.print(); 189 printConvMap(g2.getGenes(), g1.getGenes(), rm); 190 } 191 192 Model mod1(g1, 1); 193 printf("\nModel map for f%c genotype:\n", g1.getFormat()); 194 printModelMap(g1.getGenes(), mod1.getMap()); 195 MultiMap mod1combined; 196 mod1combined.addCombined(mod1.getMap(), getModelDisplayMap()); 197 mod1combined.print(); 198 Model mod2(g2, 1); 199 printf("\nModel map for f%c genotype:\n", g2.getFormat()); 200 printModelMap(g2.getGenes(), mod2.getMap()); 201 MultiMap mod2combined; 202 mod2combined.addCombined(mod2.getMap(), getModelDisplayMap()); 203 mod2combined.print(); 204 } 178 205 return 0; 179 206 } -
cpp/frams/_demos/genotypeloader.cpp
r639 r732 5 5 #include "genotypeloader.h" 6 6 7 #define FIELDSTRUCT MiniGenotype8 ParamEntry minigenotype_paramtab[] =9 {10 { "Genotype", 1, 29, "org", },11 7 12 { "name", 0, 0, "Name", "s 0 40", FIELD(name), }, 13 { "genotype", 0, 0, "Genotype", "s 1", FIELD(genotype), "Genes as a string of characters.", }, 8 GenotypeMiniLoader::GenotypeMiniLoader() :genotype_param(genotypemini_paramtab, &genotype_object) { init(); } 9 GenotypeMiniLoader::GenotypeMiniLoader(VirtFILE *f) : MultiParamLoader(f), genotype_param(genotypemini_paramtab, &genotype_object) { init(); } 10 GenotypeMiniLoader::GenotypeMiniLoader(const char* filename) : MultiParamLoader(filename), genotype_param(genotypemini_paramtab, &genotype_object) { init(); } 14 11 15 { "info_timestamp", 1, 0, "Last modified", "ft 0 -1 0", FIELD(info_timestamp), }, 16 { "info_author", 1, 0, "Author name", "s 0 100", FIELD(info_author), }, 17 { "info_author_ispublic", 1, 0, "Author name is public", "d 0 1 1", FIELD(info_author_ispublic), }, 18 { "info_email", 1, 0, "Author email", "s 0 100", FIELD(info_email), }, 19 { "info_email_ispublic", 1, 0, "Author email is public", "d 0 1 0", FIELD(info_email_ispublic), }, 20 { "info", 1, 0, "Description", "s 1 1000", FIELD(info), "Short description of key features of this creature.", }, 21 { "info_origin", 1, 0, "Origin", "d 0 4 0 ~Unspecified~Designed~Designed and evolved~Evolved under various conditions~Evolved using single, constant setup", FIELD(info_origin), "Declaration of how this genotype originated." }, 22 { "info_how_created", 1, 0, "How created", "s 1 1000", FIELD(info_how_created), "Description of the process of designing and/or evolving this genotype." }, 23 { "info_performance", 1, 0, "Performance notes", "s 1 1000", FIELD(info_performance), "Description of why this genotype is special/interesting and how it performs." }, 24 25 { "energy0", 0, 0, "Starting energy", "f 0 -1 0", FIELD(energy0), }, 26 { "numparts", 0, 0, "Body parts", "d", FIELD(numparts), }, 27 { "numjoints", 0, 0, "Body joints", "d", FIELD(numjoints), }, 28 { "numneurons", 0, 0, "Brain size", "d", FIELD(numneurons), }, 29 { "numconnections", 0, 0, "Brain connections", "d", FIELD(numconnections), }, 30 31 { "num", 0, 0, "Ordinal number", "d", FIELD(ordnumber), }, 32 { "gnum", 0, 0, "Generation", "d", FIELD(generation), }, 33 34 { "instances", 0, 0, "Instances", "d", FIELD(instances), "Copies of this genotype", }, 35 36 { "lifespan", 0, 0, "Life span", "f", FIELD(lifespan), "Average life span", }, 37 { "velocity", 0, 0, "Velocity", "f", FIELD(velocity), "Average velocity", }, 38 { "distance", 0, 0, "Distance", "f", FIELD(distance), }, 39 { "vertvel", 0, 0, "Vertical velocity", "f", FIELD(vertvel), }, 40 { "vertpos", 0, 0, "Vertical position", "f", FIELD(vertpos), }, 41 42 { "user1", 0, 0, "User field 1", "x", FIELD(user1), }, 43 { "user2", 0, 0, "User field 2", "x", FIELD(user2), }, 44 { "user3", 0, 0, "User field 3", "x", FIELD(user3), }, 45 46 { "is_valid", 0, 0, "Validity", "d -1 1 -1", FIELD(is_valid), 47 "0 = invalid genotype\n" 48 "1 = valid genotype\n" 49 "-1 = validity is not known." }, 50 51 { "uid", 0, 0, "#", "s", FIELD(uid), "Unique identifier" }, 52 53 { 0, 0, 0, }, 54 }; 55 #undef FIELDSTRUCT 56 57 MiniGenotypeLoader::MiniGenotypeLoader() :genotype_param(minigenotype_paramtab, &genotype_object) { init(); } 58 MiniGenotypeLoader::MiniGenotypeLoader(VirtFILE *f) : MultiParamLoader(f), genotype_param(minigenotype_paramtab, &genotype_object) { init(); } 59 MiniGenotypeLoader::MiniGenotypeLoader(const char* filename) : MultiParamLoader(filename), genotype_param(minigenotype_paramtab, &genotype_object) { init(); } 60 61 void MiniGenotypeLoader::init() 12 void GenotypeMiniLoader::init() 62 13 { 63 14 addObject(&genotype_param); … … 65 16 } 66 17 67 MiniGenotype* MiniGenotypeLoader::loadNextGenotype()18 GenotypeMini* GenotypeMiniLoader::loadNextGenotype() 68 19 { 69 20 genotype_object.clear(); -
cpp/frams/_demos/genotypeloader.h
r635 r732 8 8 #include <frams/util/sstring.h> 9 9 #include <frams/param/multiparamload.h> 10 11 /** Defines the association between "org:" object (found in genotype files) 12 and the MiniGenotype fields. MiniGenotypeLoader uses this definition 13 but you can also use it to make MultiParamLoader load genotype 14 */ 15 extern ParamEntry minigenotype_paramtab[]; 16 17 /** Helper class, mostly useful with MultiParamLoader 18 or its specialized version: MiniGenotypeLoader. 19 MiniGenotype stores the subset of Genotype fields (the ones normally saved in .gen files) 20 */ 21 class MiniGenotype 22 { 23 public: 24 SString name, genotype, info, uid; 25 double info_timestamp; 26 SString info_author, info_email; 27 paInt info_author_ispublic, info_email_ispublic, info_origin; 28 SString info_how_created, info_performance; 29 double energy0, lifespan, velocity, distance, vertvel, vertpos; 30 paInt numparts, numjoints, numneurons, numconnections, ordnumber, generation, instances, is_valid; 31 ExtValue user1, user2, user3; 32 void clear() { Param p(minigenotype_paramtab, this); p.setDefault(); } 33 }; 10 #include "genotypemini.h" 34 11 35 12 /** In most simple cases this is the class you would use to load a series of genotypes from … … 48 25 methods, or you can use it as a guide for creating your own specialized class. 49 26 */ 50 class MiniGenotypeLoader : public MultiParamLoader27 class GenotypeMiniLoader : public MultiParamLoader 51 28 { 52 MiniGenotypegenotype_object;29 GenotypeMini genotype_object; 53 30 Param genotype_param; 54 31 bool initialized; 55 32 void init(); 56 33 public: 57 MiniGenotypeLoader();58 MiniGenotypeLoader(VirtFILE *f);59 MiniGenotypeLoader(const char* filename);34 GenotypeMiniLoader(); 35 GenotypeMiniLoader(VirtFILE *f); 36 GenotypeMiniLoader(const char* filename); 60 37 61 38 /** @returns genotype object if one was loaded or NULL otherwise. 62 39 63 Returned MiniGenotype pointer always references the the same object (MiniGenotypeLoader::genotype_object)40 Returned GenotypeMini pointer always references the the same object (GenotypeMiniLoader::genotype_object) 64 41 which means you may need to copy the data from it before calling loadNextGenotype() again. 65 In the default configuration (simple MiniGenotypeLoader) NULL is always final and should be used42 In the default configuration (simple GenotypeMiniLoader) NULL is always final and should be used 66 43 to finish processing. 67 44 … … 70 47 MultiParamLoader::finished() and other methods to determine the real cause of NULL. 71 48 */ 72 MiniGenotype* loadNextGenotype();49 GenotypeMini* loadNextGenotype(); 73 50 }; 74 51 -
cpp/frams/_demos/geometry/geometrytestutils.cpp
r662 r732 18 18 long count = 0; 19 19 long totalSize = 0; 20 MiniGenotypeLoader loader(file);21 MiniGenotype*genotype;22 20 GenotypeMiniLoader loader(file); 21 GenotypeMini *genotype; 22 23 23 while (genotype = loader.loadNextGenotype()) 24 24 { 25 25 count++; 26 26 totalSize += genotype->genotype.len(); 27 27 28 28 fprintf(stderr, "%d. (%6d chars) %s\n", count, genotype->genotype.len(), 29 29 genotype->name.c_str()); 30 30 } 31 32 if (loader.getStatus() == MiniGenotypeLoader::OnError)31 32 if (loader.getStatus() == GenotypeMiniLoader::OnError) 33 33 { 34 34 fprintf(stderr, "Error: %s\n", loader.getError().c_str()); … … 44 44 class TestInvoker 45 45 { 46 47 46 public: 47 virtual void operator()(Model &model) = 0; 48 48 }; 49 49 … … 53 53 const int genoIndex = isdigit(genoId[0]) ? atol(genoId) : 0; 54 54 long count = 0; 55 MiniGenotypeLoader loader(file);56 MiniGenotype*genotype;57 55 GenotypeMiniLoader loader(file); 56 GenotypeMini *genotype; 57 58 58 while (genotype = loader.loadNextGenotype()) 59 59 { 60 60 count++; 61 61 62 62 if ((genoIndex == count) || (strcmp(genotype->name.c_str(), genoName) == 0)) 63 63 { 64 64 Model model(genotype->genotype); 65 65 66 66 if (!model.isValid()) 67 67 { … … 74 74 } 75 75 } 76 77 if (loader.getStatus() == MiniGenotypeLoader::OnError)76 77 if (loader.getStatus() == GenotypeMiniLoader::OnError) 78 78 { 79 79 fprintf(stderr, "Error: %s\n", loader.getError().c_str()); … … 94 94 if ((shape < 1) || (shape > 3)) 95 95 { 96 shape = (rand() %3) + 1;96 shape = (rand() % 3) + 1; 97 97 } 98 98 … … 106 106 } 107 107 108 class ModelBasedTestInvoker : public TestInvoker109 { 110 111 void(*test)(Model &);112 113 ModelBasedTestInvoker(void (*_test)(Model &)):114 115 116 117 118 119 108 class ModelBasedTestInvoker : public TestInvoker 109 { 110 private: 111 void(*test)(Model &); 112 public: 113 ModelBasedTestInvoker(void(*_test)(Model &)) : 114 test(_test) 115 {} 116 void operator()(Model &model) 117 { 118 test(model); 119 } 120 120 }; 121 121 122 int GeometryTestUtils::execute(const SString header, int argc, char *argv[], void 122 int GeometryTestUtils::execute(const SString header, int argc, char *argv[], void(*test)(Model &)) 123 123 { 124 124 LoggerToStdout messages_to_stdout(LoggerBase::Enable); //comment this object out to mute error/warning messages 125 125 StdioFileSystem_autoselect stdiofilesys; 126 126 PreconfiguredGenetics genetics; 127 127 128 128 srand(time(NULL)); 129 129 … … 132 132 return printGenotypesList(argv[2]); 133 133 } 134 134 135 135 if ((argc == 4) && (strcmp("-l", argv[1]) == 0)) 136 136 { … … 138 138 return executeTestUsingLoadedModel(argv[2], argv[3], invoker); 139 139 } 140 140 141 141 if ((argc == 2) && (strcmp("-c", argv[1]) == 0)) 142 142 { … … 144 144 return executeTestUsingRandomModel(-1, invoker); 145 145 } 146 146 147 147 if ((argc == 3) && (strcmp("-c", argv[1]) == 0) && isdigit(argv[2][0])) 148 148 { … … 151 151 return executeTestUsingRandomModel(shape, invoker); 152 152 } 153 153 154 154 fprintf(stderr, 155 155 "%s\n\n" … … 165 165 } 166 166 167 class ModelAndDensityBasedTestInvoker : public TestInvoker168 { 169 170 void(*test)(Model &, const double);171 172 173 ModelAndDensityBasedTestInvoker(void (*_test)(Model &, const double), double _density):174 175 176 177 178 179 180 181 167 class ModelAndDensityBasedTestInvoker : public TestInvoker 168 { 169 private: 170 void(*test)(Model &, const double); 171 double density; 172 public: 173 ModelAndDensityBasedTestInvoker(void(*_test)(Model &, const double), double _density) : 174 test(_test), 175 density(_density) 176 {} 177 178 void operator()(Model &model) 179 { 180 test(model, density); 181 } 182 182 }; 183 183 184 184 int GeometryTestUtils::execute(const SString header, int argc, char *argv[], 185 void 185 void(*test)(Model &, const double)) 186 186 { 187 187 LoggerToStdout messages_to_stdout(LoggerBase::Enable); //comment this object out to mute error/warning messages 188 188 StdioFileSystem_autoselect stdiofilesys; 189 189 PreconfiguredGenetics genetics; 190 190 191 191 srand(time(NULL)); 192 192 … … 202 202 return executeTestUsingLoadedModel(argv[2], argv[3], invoker); 203 203 } 204 204 205 205 if ((argc == 3) && (strcmp("-c", argv[1]) == 0) && isdigit(argv[2][0])) 206 206 { … … 209 209 return executeTestUsingRandomModel(-1, invoker); 210 210 } 211 211 212 212 if ((argc == 4) && (strcmp("-c", argv[1]) == 0) && isdigit(argv[2][0]) && isdigit(argv[3][0])) 213 213 { … … 217 217 return executeTestUsingRandomModel(shape, invoker); 218 218 } 219 219 220 220 fprintf(stderr, 221 221 "%s\n\n" … … 235 235 { 236 236 Part *part = model.addNewPart(Part::SHAPE_ELLIPSOID); 237 237 238 238 part->p = Pt3D(0); 239 239 part->scale = Pt3D(0.1); 240 240 part->vcolor = Pt3D(1.0, 0.0, 1.0); 241 241 242 242 addAxesToModel(Pt3D(0.5), Orient(Orient_1), Pt3D(0.0), model); 243 243 } … … 247 247 Part *anchor = model.getPart(0); 248 248 Part *part = model.addNewPart(Part::SHAPE_ELLIPSOID); 249 249 250 250 part->p = Pt3D(markerLocation); 251 251 part->scale = Pt3D(0.05); 252 252 part->vcolor = Pt3D(1.0, 1.0, 0.0); 253 253 254 254 model.addNewJoint(anchor, part, Joint::SHAPE_FIXED); 255 255 } … … 260 260 Part *anchor = model.getPart(0); 261 261 Part *part; 262 262 263 263 part = model.addNewPart(Part::SHAPE_CUBOID); 264 264 part->scale = Pt3D(sizes.x, 0.05, 0.05); … … 267 267 part->vcolor = Pt3D(1.0, 0.0, 0.0); 268 268 model.addNewJoint(anchor, part, Joint::SHAPE_FIXED); 269 269 270 270 part = model.addNewPart(Part::SHAPE_CUBOID); 271 271 part->scale = Pt3D(0.05, sizes.y, 0.05); … … 274 274 part->vcolor = Pt3D(0.0, 1.0, 0.0); 275 275 model.addNewJoint(anchor, part, Joint::SHAPE_FIXED); 276 276 277 277 part = model.addNewPart(Part::SHAPE_CUBOID); 278 278 part->scale = Pt3D(0.05, 0.05, sizes.z); … … 287 287 Part *targetAnchor = target.getPart(0); 288 288 Part *sourceAnchor = source.getPart(0); 289 289 290 290 target.moveElementsFrom(source); 291 291 292 292 target.addNewJoint(targetAnchor, sourceAnchor, Joint::SHAPE_FIXED); 293 293 } … … 295 295 double frand(double from, double width) 296 296 { 297 return from + width * ((rand() %10000) / 10000.0);297 return from + width * ((rand() % 10000) / 10000.0); 298 298 } 299 299 -
cpp/frams/_demos/loader_test_geno.cpp
r520 r732 26 26 long count = 0, totalsize = 0; 27 27 StdioFileSystem_autoselect stdiofilesys; 28 MiniGenotypeLoader loader(argv[1]);28 GenotypeMiniLoader loader(argv[1]); 29 29 const char* selected = (argc < 3) ? NULL : argv[2]; 30 30 const char* field_name = (argc < 4) ? NULL : argv[3]; 31 31 int selected_index = (selected&&isdigit(selected[0])) ? atol(selected) : 0; 32 32 // using char* constructor (passing the file name to open) 33 MiniGenotype*loaded;33 GenotypeMini *loaded; 34 34 while (loaded = loader.loadNextGenotype()) 35 35 { // if loaded != NULL then the "org:" object data was … … 51 51 if (field_name) 52 52 { 53 Param p( minigenotype_paramtab, loaded);53 Param p(genotypemini_paramtab, loaded); 54 54 int field_index = p.findId(field_name); 55 55 if (field_index < 0) … … 68 68 } 69 69 // the loop repeats until loaded==NULL, which could be beacause of error 70 if (loader.getStatus() == MiniGenotypeLoader::OnError)70 if (loader.getStatus() == GenotypeMiniLoader::OnError) 71 71 fprintf(stderr, "Error: %s", loader.getError().c_str()); 72 72 // (otherwise it was the end of the file) -
cpp/frams/_demos/paramtree_paramlist_test.cpp
r730 r732 22 22 PreconfiguredGenetics genetics; 23 23 24 Param minigenotype_param(minigenotype_paramtab);24 Param genotypemini_param(genotypemini_paramtab); 25 25 NeuroFactory neurofac; 26 26 neurofac.setStandardImplementation(); … … 36 36 combined += &Pt3D_Ext::getStaticParam(); 37 37 combined += &Orient_Ext::getStaticParam(); 38 combined += & minigenotype_param;38 combined += &genotypemini_param; 39 39 combined += &nn_config.par; 40 40 combined += &modelgeo.par; -
cpp/frams/_demos/printconvmap.cpp
r348 r732 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 6 6 #include <stdio.h> 7 7 #include <frams/util/multimap.h> 8 #include <frams/model/model.h> 8 9 9 10 #define GEN1MAX 15 10 11 11 void printN(const char* t, int maxlen)12 void printN(const char* t, int maxlen) 12 13 { 13 while(maxlen-- > 0)14 if (*t) putchar(*(t++));15 else putchar(' ');14 while (maxlen-- > 0) 15 if (*t) putchar(*(t++)); 16 else putchar(' '); 16 17 } 17 18 18 void printN(char t, int maxlen)19 void printN(char t, int maxlen) 19 20 { 20 while(maxlen-- > 0) putchar(t);21 while (maxlen-- > 0) putchar(t); 21 22 } 22 23 23 void printmapping(const char* gen1, int len1, const MultiRange &mr,const char* gen2,int len2)24 void printmapping(const char* gen1, int len1, const MultiRange &mr, const char* gen2, int len2) 24 25 { 25 printN(' ',GEN1MAX-len1);26 printN(gen1,len1);27 printf(" : ");28 int i;29 for(i=0;i<len2;i++)30 if (mr.contains(i))31 putchar(gen2[i]);32 else33 putchar('.');34 putchar('\n');26 printN(' ', GEN1MAX - len1); 27 printN(gen1, len1); 28 printf(" : "); 29 int i; 30 for (i = 0; i < len2; i++) 31 if (mr.contains(i)) 32 putchar(gen2[i]); 33 else 34 putchar('.'); 35 putchar('\n'); 35 36 } 36 37 37 38 void stripstring(SString &str) 38 39 { 39 char *t=str.directWrite();40 for(;*t;t++)41 if (strchr("\n\r\t",*t)) *t=' ';40 char *t = str.directWrite(); 41 for (; *t; t++) 42 if (strchr("\n\r\t", *t)) *t = ' '; 42 43 } 43 44 44 void printConvMap(const SString& gen1, const SString& gen2,const MultiMap& map)45 void printConvMap(const SString& gen1, const SString& gen2, const MultiMap& map) 45 46 { 46 int y,y2,len1;47 int id=0;48 if (map.isEmpty())47 int y, y2, len1; 48 int id = 0; 49 if (map.isEmpty()) 49 50 { 50 printf("{ empty }\n");51 return;51 printf("{ empty }\n"); 52 return; 52 53 } 53 len1=gen1.len();54 SString g1=gen1;55 stripstring(g1);56 SString g2=gen2;57 stripstring(g2);58 const char* g=g1.c_str();59 y=0;60 MultiRange *mr;61 MultiRange emptyrange;62 printN(' ',GEN1MAX);63 printf(" %s\n",g2.c_str());64 int begin=map.getBegin();65 int end=map.getEnd();66 while(y<len1)54 len1 = gen1.len(); 55 SString g1 = gen1; 56 stripstring(g1); 57 SString g2 = gen2; 58 stripstring(g2); 59 const char* g = g1.c_str(); 60 y = 0; 61 MultiRange *mr; 62 MultiRange emptyrange; 63 printN(' ', GEN1MAX); 64 printf(" %s\n", g2.c_str()); 65 int begin = map.getBegin(); 66 int end = map.getEnd(); 67 while (y < len1) 67 68 { 68 if (y<begin)69 if (y < begin) 69 70 { 70 mr=&emptyrange;71 y2=begin;71 mr = &emptyrange; 72 y2 = begin; 72 73 } 73 else if (y>end)74 else if (y > end) 74 75 { 75 mr=&emptyrange;76 y2=len1;76 mr = &emptyrange; 77 y2 = len1; 77 78 } 78 else {79 id=map.findMappingId(y);80 mr=&map.getMapping(id)->to;81 y2=map.getMapping(id+1)->begin;79 else { 80 id = map.findMappingId(y); 81 mr = &map.getMapping(id)->to; 82 y2 = map.getMapping(id + 1)->begin; 82 83 } 83 if ((y2-y) > GEN1MAX) y2=y+GEN1MAX;84 if (y2>(y+len1)) y2=y+len1;85 printmapping(g+y,y2-y,*mr,g2.c_str(),g2.len());86 y=y2;84 if ((y2 - y) > GEN1MAX) y2 = y + GEN1MAX; 85 if (y2 > (y + len1)) y2 = y + len1; 86 printmapping(g + y, y2 - y, *mr, g2.c_str(), g2.len()); 87 y = y2; 87 88 } 88 89 } 89 90 90 void printModelMap(const SString& gen1,const MultiMap& map)91 const MultiMap & getModelDisplayMap() 91 92 { 92 SString g2("012345678901234567890123456789"); 93 printN(' ',GEN1MAX); 94 printf(" Parts Joints Neurons\n"); 95 printConvMap(gen1,g2,map); 93 static MultiMap display_map; 94 if (display_map.isEmpty()) 95 { 96 for (int i = 0; i < 10; i++) 97 { 98 display_map.add(Model::partToMap(i), Model::partToMap(i), i, i); 99 display_map.add(Model::jointToMap(i), Model::jointToMap(i), 10 + i, 10 + i); 100 display_map.add(Model::neuroToMap(i), Model::neuroToMap(i), 20 + i, 20 + i); 101 } 102 } 103 return display_map; 96 104 } 105 106 void printModelMap(const SString& gen1, const MultiMap& map) 107 { 108 MultiMap combined_map; 109 combined_map.addCombined(map, getModelDisplayMap()); 110 SString g2("012345678901234567890123456789"); 111 printN(' ', GEN1MAX); 112 printf(" Parts Joints Neurons\n"); 113 printConvMap(gen1, g2, combined_map); 114 } -
cpp/frams/_demos/printconvmap.h
r286 r732 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 10 10 class MultiMap; 11 11 12 void printConvMap(const SString& gen1,const SString& gen2,const MultiMap& map); 13 void printModelMap(const SString& gen1,const MultiMap& map); 12 void printConvMap(const SString& gen1, const SString& gen2, const MultiMap& map); 13 void printModelMap(const SString& gen1, const MultiMap& map); //automaticaly combines the map with the ModelDisplayMap 14 const MultiMap & getModelDisplayMap(); // mapping: true model -> display (so the regular map printing/debugging tools can be used for model maps, avoiding invonveniently huge numbers) 14 15 15 16 #endif -
cpp/frams/_demos/saver_test_geno.cpp
r520 r732 28 28 { 29 29 int N = atoi(argv[2]); 30 MiniGenotypeg;31 Param p( minigenotype_paramtab, &g);30 GenotypeMini g; 31 Param p(genotypemini_paramtab, &g); 32 32 g.clear(); 33 33 printf("Saving %d genotypes to %s\n", N, argv[1]); -
cpp/frams/_demos/simil_test.cpp
r612 r732 125 125 126 126 long count = 0, totalsize = 0; 127 MiniGenotypeLoader loader(szFileName);128 MiniGenotype*loaded;127 GenotypeMiniLoader loader(szFileName); 128 GenotypeMini *loaded; 129 129 while (loaded = loader.loadNextGenotype()) 130 130 { … … 147 147 } 148 148 } 149 if (loader.getStatus() == MiniGenotypeLoader::OnError)149 if (loader.getStatus() == GenotypeMiniLoader::OnError) 150 150 { 151 151 printf("Error: %s", loader.getError().c_str());
Note: See TracChangeset
for help on using the changeset viewer.