- Timestamp:
- 02/15/18 00:42:07 (7 years ago)
- Location:
- cpp/frams
- Files:
-
- 2 added
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/Makefile-SDK-files
r729 r732 25 25 STDOUT_LOGGER_OBJS=common/virtfile/virtfile.o common/loggers/loggertostdout.o common/console.o 26 26 27 GENOTYPE_LOADER_OBJS=frams/_demos/genotypeloader.o frams/ param/multiparamload.o27 GENOTYPE_LOADER_OBJS=frams/_demos/genotypeloader.o frams/_demos/genotypemini.o frams/param/multiparamload.o 28 28 SDK_LIB_OBJS= $(STDOUT_LOGGER_OBJS) $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GENMAN_SDK_OBJS) $(GEOMETRY_OBJS) $(GENOTYPE_LOADER_OBJS) common/virtfile/stdiofile.o 29 29 … … 36 36 F0_VARIANTS_OBJS=frams/_demos/f0_variants_test.o $(STDOUT_LOGGER_OBJS) $(SDK_OBJS) $(GENOCONV_SDK_OBJS) 37 37 38 LOADER_TEST_OBJS=frams/_demos/genotypeloader.o frams/_demos/ loader_test_geno.o common/virtfile/virtfile.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS)38 LOADER_TEST_OBJS=frams/_demos/genotypeloader.o frams/_demos/genotypemini.o frams/_demos/loader_test_geno.o common/virtfile/virtfile.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS) 39 39 40 40 LOADER_TEST_PARAM_OBJS=frams/_demos/loader_test_param.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(STDOUT_LOGGER_OBJS) $(SDK_OBJS) 41 41 42 SAVER_TEST_OBJS=frams/_demos/genotypeloader.o frams/_demos/ saver_test_geno.o common/virtfile/virtfile.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS)42 SAVER_TEST_OBJS=frams/_demos/genotypeloader.o frams/_demos/genotypemini.o frams/_demos/saver_test_geno.o common/virtfile/virtfile.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS) 43 43 44 44 GENOCONV_TEST_OBJS= frams/_demos/genoconv_test.o frams/_demos/printconvmap.o $(STDOUT_LOGGER_OBJS) $(SDK_OBJS) $(GENOCONV_SDK_OBJS) … … 64 64 NEURO_LAYOUT_TEST_OBJS= frams/_demos/neuro_layout_test.o $(STDOUT_LOGGER_OBJS) $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GENMAN_SDK_OBJS) frams/canvas/nn_layout_model.o frams/canvas/nn_simple_layout.o frams/canvas/nn_smart_layout.o 65 65 66 GEOMETRY_INFO_TEST_OBJS=frams/_demos/geometry/info_test.o frams/_demos/geometry/geometrytestutils.o frams/_demos/genotypeloader.o frams/ param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GEOMETRY_OBJS) $(GENMAN_SDK_OBJS) $(STDOUT_LOGGER_OBJS)66 GEOMETRY_INFO_TEST_OBJS=frams/_demos/geometry/info_test.o frams/_demos/geometry/geometrytestutils.o frams/_demos/genotypeloader.o frams/_demos/genotypemini.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GEOMETRY_OBJS) $(GENMAN_SDK_OBJS) $(STDOUT_LOGGER_OBJS) 67 67 68 GEOMETRY_SURFACE_TEST_OBJS=frams/_demos/geometry/surface_test.o frams/_demos/geometry/geometrytestutils.o frams/_demos/genotypeloader.o frams/ param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GEOMETRY_OBJS) $(GENMAN_SDK_OBJS) $(STDOUT_LOGGER_OBJS)68 GEOMETRY_SURFACE_TEST_OBJS=frams/_demos/geometry/surface_test.o frams/_demos/geometry/geometrytestutils.o frams/_demos/genotypeloader.o frams/_demos/genotypemini.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GEOMETRY_OBJS) $(GENMAN_SDK_OBJS) $(STDOUT_LOGGER_OBJS) 69 69 70 GEOMETRY_VOLUME_TEST_OBJS=frams/_demos/geometry/volume_test.o frams/_demos/geometry/geometrytestutils.o frams/_demos/genotypeloader.o frams/ param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GEOMETRY_OBJS) $(GENMAN_SDK_OBJS) $(STDOUT_LOGGER_OBJS)70 GEOMETRY_VOLUME_TEST_OBJS=frams/_demos/geometry/volume_test.o frams/_demos/geometry/geometrytestutils.o frams/_demos/genotypeloader.o frams/_demos/genotypemini.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GEOMETRY_OBJS) $(GENMAN_SDK_OBJS) $(STDOUT_LOGGER_OBJS) 71 71 72 GEOMETRY_APICES_TEST_OBJS=frams/_demos/geometry/apices_test.o frams/_demos/geometry/geometrytestutils.o frams/_demos/genotypeloader.o frams/ param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GEOMETRY_OBJS) $(GENMAN_SDK_OBJS) $(STDOUT_LOGGER_OBJS)72 GEOMETRY_APICES_TEST_OBJS=frams/_demos/geometry/apices_test.o frams/_demos/geometry/geometrytestutils.o frams/_demos/genotypeloader.o frams/_demos/genotypemini.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GEOMETRY_OBJS) $(GENMAN_SDK_OBJS) $(STDOUT_LOGGER_OBJS) 73 73 74 74 SIMIL_TEST_OBJS=frams/_demos/simil_test.o frams/model/similarity/SVD/lapack.o frams/model/similarity/SVD/matrix_tools.o frams/model/similarity/simil_match.o frams/model/similarity/simil_model.o \ 75 frams/_demos/genotypeloader.o frams/ param/multiparamload.o common/virtfile/stdiofile.o $(STDOUT_LOGGER_OBJS) $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GENMAN_SDK_OBJS)75 frams/_demos/genotypeloader.o frams/_demos/genotypemini.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(STDOUT_LOGGER_OBJS) $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GENMAN_SDK_OBJS) 76 76 77 77 SIMIL_UNITTESTS_OBJS=frams/_demos/simil_unittests.o frams/model/similarity/simil_match.o -
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()); -
cpp/frams/config/f0-SDK.def
r528 r732 89 89 PROP(getInputNeuroIndex,0,1+2,`get input neuron index',p d(d),,,,p_getInputNeuroIndex,PROCEDURE) 90 90 PROP(getInputWeight,0,1+2,`get input weight',p f(d),,,,p_getInputWeight,PROCEDURE) 91 PROP(classObject,0,1+2,`neuron class',o 91 PROP(classObject,0,1+2,`neuron class',oNeuroClass,,,,classObject,GETONLY) 92 92 ENDCLASS 93 93 -
cpp/frams/config/f0.def
r656 r732 89 89 PROP(getInputNeuroIndex,0,0,`get input neuron index',p d(d),,,,p_getInputNeuroIndex,PROCEDURE) 90 90 PROP(getInputWeight,0,0,`get input weight',p f(d),,,,p_getInputWeight,PROCEDURE) 91 PROP(classObject,0,1+2,`neuron class',o 91 PROP(classObject,0,1+2,`neuron class',oNeuroClass,,,,classObject,GETONLY) 92 92 ENDCLASS 93 93 -
cpp/frams/config/sdk_build_config.h
r318 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 … … 15 15 16 16 #define NOCREATUREOBJECT 17 #define EASYMAPDEBUG18 17 #define SDK_WITHOUT_FRAMS 19 18 #define NO_BARRIER -
cpp/frams/genetics/f1/conv_f1.cpp
r726 r732 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 7Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 14 14 15 15 F1Props stdprops = { 1, 0, 1, 0.4, 0.25, 0.25, 0.25, 0.25, 0.0, 1.0, 1.0, 1, 16 16 0.2, 0.5, 0.5, 0.5 }; 17 17 18 18 class Builder … … 106 106 107 107 /** main conversion function - with conversion map support */ 108 SString GenoConv_f1::convert(SString &i, MultiMap *map )108 SString GenoConv_f1::convert(SString &i, MultiMap *map, bool using_checkpoints) 109 109 { 110 110 const char* g = i.c_str(); 111 111 Builder builder(g, map ? 1 : 0); 112 builder.model.open( );112 builder.model.open(using_checkpoints); 113 113 builder.grow(-1, g, Pt3D_0, stdprops, -1); // uses Model::addFromString() to create model elements 114 114 if (builder.invalid) return SString(); … … 242 242 243 243 if (c.muscle_reset_range) c.muscle_bend_range = 1.0; else c.muscle_reset_range = true; 244 model.checkpoint(); 244 245 grow(part2, g + 1, Pt3D_0, c, branching_part); 245 246 return; -
cpp/frams/genetics/f1/conv_f1.h
r671 r732 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 7Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 69 69 mapsupport = 1; 70 70 } 71 SString convert(SString &i, MultiMap *map );71 SString convert(SString &i, MultiMap *map, bool using_checkpoints); 72 72 ~GenoConv_f1() {} 73 73 }; -
cpp/frams/genetics/geno.cpp
r534 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 … … 32 32 name = genname; 33 33 txt = comment; 34 setGenesAndFormat(genstring, genformat);34 setGenesAndFormat(genstring, genformat); 35 35 } 36 36 … … 54 54 mapinshift = end + 1; 55 55 gencopy = genstring.substr(end + 1); 56 if ((end >0) && (genstring[end-1]=='\r')) end--;56 if ((end > 0) && (genstring[end - 1] == '\r')) end--; 57 57 error_end = end; 58 58 if (end != 3) genformat = INVALID_FORMAT; … … 82 82 break; 83 83 } 84 if (!isalnum(genformat)) genformat =INVALID_FORMAT;84 if (!isalnum(genformat)) genformat = INVALID_FORMAT; 85 85 if (genformat == INVALID_FORMAT) 86 86 { … … 93 93 cut = genstring.substr(0, error_end); 94 94 int lf = cut.indexOf('\n'); 95 if (lf >= 0) { if ((lf >0)&&(cut[lf-1]=='\r')) lf--; cut = cut.substr(0, lf); }95 if (lf >= 0) { if ((lf > 0) && (cut[lf - 1] == '\r')) lf--; cut = cut.substr(0, lf); } 96 96 sstringQuote(cut); 97 97 logPrintf("Geno", "init", LOG_ERROR, "Invalid genotype format declaration: '%s'%s", cut.c_str(), name.len() ? SString::sprintf(" in '%s'", name.c_str()).c_str() : ""); … … 226 226 { 227 227 bool converter_missing; 228 Geno f0geno = g.getConverted('0', NULL, &converter_missing);228 Geno f0geno = g.getConverted('0', NULL, false, &converter_missing); 229 229 if (converter_missing) 230 230 return -1;//no result … … 295 295 } 296 296 297 Geno Geno::getConverted(char otherformat, MultiMap *m, bool *converter_missing)297 Geno Geno::getConverted(char otherformat, MultiMap *m, bool using_checkpoints, bool *converter_missing) 298 298 { 299 299 if (otherformat == getFormat()) { if (converter_missing) *converter_missing = false; return *this; } … … 302 302 if (converters) 303 303 { 304 if ((otherformat == '0') && (!m) )304 if ((otherformat == '0') && (!m) && (!using_checkpoints)) 305 305 { 306 306 if (!f0gen) 307 f0gen = new Geno(converters->convert(*this, otherformat, NULL, converter_missing));307 f0gen = new Geno(converters->convert(*this, otherformat, NULL, using_checkpoints, converter_missing)); 308 308 else 309 309 { … … 313 313 } 314 314 else 315 return converters->convert(*this, otherformat, m, converter_missing);315 return converters->convert(*this, otherformat, m, using_checkpoints, converter_missing); 316 316 } 317 317 #endif -
cpp/frams/genetics/geno.h
r534 r732 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 6Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 90 90 91 91 /** @param genformat=-1 -> detect genotype format from genstring comment (like the constructor does), else specify the valid format in genformat and pure genes in genstring. */ 92 void setGenesAndFormat(const SString& genstring, char genformat =-1);92 void setGenesAndFormat(const SString& genstring, char genformat = -1); 93 93 /** g must be pure genes, without format. For the standard behavior use setGenesAndFormat() */ 94 94 void setGenesAssumingSameFormat(const SString& g); … … 107 107 /// make converted version of the genotype. 108 108 /// @param converter_missing optional output parameter (ignored when NULL). Receives true if the conversion fails because of the lack of appropriate converter(s) (the returned Geno is always invalid in this case). Receives false if the genotype was converted by a converter or a converter chain (the returned Geno can be valid or invalid, depending on the converter's decision). 109 Geno getConverted(char otherformat, MultiMap *m = 0, bool *converter_missing = NULL);109 Geno getConverted(char otherformat, MultiMap *m = 0, bool using_checkpoints = false, bool *converter_missing = NULL); 110 110 111 111 /// @return -1 = before first char in the string -
cpp/frams/genetics/genoconv.cpp
r534 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 … … 81 81 82 82 GenoConvManager::GenoConvManager() 83 :param(this)83 :param(this) 84 84 { 85 85 } … … 166 166 } 167 167 168 Geno GenoConvManager::convert(Geno &in, char format, MultiMap *map, bool *converter_missing)168 Geno GenoConvManager::convert(Geno &in, char format, MultiMap *map, bool using_checkpoints, bool *converter_missing) 169 169 { 170 170 if (in.getFormat() == format) { if (converter_missing) *converter_missing = false; return in; } … … 187 187 { 188 188 GenoConverter *gk = (GenoConverter*)converters(*t); 189 tmp = gk->convert(tmp, mapavail ? &tmpmap : 0 );189 tmp = gk->convert(tmp, mapavail ? &tmpmap : 0, using_checkpoints); 190 190 if (!tmp.len()) 191 191 { 192 string t =ssprintf("f%c->f%c conversion failed (%s)", gk->in_format, gk->out_format, gk->name);192 string t = ssprintf("f%c->f%c conversion failed (%s)", gk->in_format, gk->out_format, gk->name); 193 193 return Geno(0, 0, 0, t.c_str()); 194 194 } -
cpp/frams/genetics/genoconv.h
r513 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 … … 53 53 /// Any other return value is assumed to be output genotype. 54 54 /// @param map if not null, mapping informaton is requested, converter should add conversion map to this object 55 virtual SString convert(SString &i, MultiMap *map ) { return SString(); }55 virtual SString convert(SString &i, MultiMap *map, bool using_checkpoints) { return SString(); } 56 56 57 57 virtual ~GenoConverter() {} … … 78 78 /// make a genotype in other format. genotype will be invalid 79 79 /// if GenoConvManager cannot convert it. 80 Geno convert(Geno &in, char format, MultiMap *map = 0, bool *converter_missing = NULL);80 Geno convert(Geno &in, char format, MultiMap *map = 0, bool using_checkpoints = false, bool *converter_missing = NULL); 81 81 /// register GenoConverter, the added object will be automatically deleted when GenoConvManager is destructed (call removeConverter() if this is not desirable) 82 82 void addConverter(GenoConverter *conv); -
cpp/frams/model/defassign-f0-SDK.h
r528 r732 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 6Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 -
cpp/frams/model/f0-SDK-classes.h
r528 r732 155 155 {"getInputNeuroIndex",0,1+2,"get input neuron index","p d(d)",PROCEDURE(p_getInputNeuroIndex),}, 156 156 {"getInputWeight",0,1+2,"get input weight","p f(d)",PROCEDURE(p_getInputWeight),}, 157 {"classObject",0,1+2,"neuron class","o 157 {"classObject",0,1+2,"neuron class","oNeuroClass",GETONLY(classObject),}, 158 158 {0,0,0,} 159 159 }; -
cpp/frams/model/model.cpp
r726 r732 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 7Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 9 9 #include <common/loggers/loggers.h> 10 10 11 #define F0_CHECKPOINT_LINE "checkpoint:" 12 11 13 Model::Model() 12 14 { … … 18 20 { 19 21 partmappingchanged = 0; 22 using_checkpoints = false; 23 is_checkpoint = false; 20 24 buildstatus = empty; 21 25 modelfromgenotype = 0; … … 47 51 f0genoknown = 0; 48 52 startenergy = mod.startenergy; 49 if (mod.getStatus() == valid) 50 { 51 modelfromgenotype = mod.modelfromgenotype; 52 {for (int i = 0; i < mod.getPartCount(); i++) 53 addPart(new Part(*mod.getPart(i))); } 54 {for (int i = 0; i < mod.getJointCount(); i++) 53 modelfromgenotype = mod.modelfromgenotype; 54 for (int i = 0; i < mod.getPartCount(); i++) 55 addPart(new Part(*mod.getPart(i))); 56 for (int i = 0; i < mod.getJointCount(); i++) 55 57 { 56 58 Joint *oldj = mod.getJoint(i); … … 58 60 addJoint(j); 59 61 j->attachToParts(oldj->part1->refno, oldj->part2->refno); 60 } }61 {for (int i = 0; i < mod.getNeuroCount(); i++)62 } 63 for (int i = 0; i < mod.getNeuroCount(); i++) 62 64 { 63 65 Neuro *oldn = mod.getNeuro(i); … … 66 68 if (oldn->part_refno >= 0) n->attachToPart(oldn->part_refno); 67 69 else n->attachToJoint(oldn->joint_refno); 68 }} 69 for (int i = 0; i < mod.getNeuroCount(); i++) 70 { 71 Neuro *oldn = mod.getNeuro(i); 72 Neuro *n = getNeuro(i); 73 for (int ni = 0; ni < oldn->getInputCount(); ni++) 74 { 75 double w; 76 Neuro *oldinput = oldn->getInput(ni, w); 77 SString info = n->getInputInfo(ni); 78 n->addInput(getNeuro(oldinput->refno), w, &info); 79 } 80 } 81 } 82 } 83 84 85 Model::Model(const Geno &src, bool buildmaps) 70 } 71 for (int i = 0; i < mod.getNeuroCount(); i++) 72 { 73 Neuro *oldn = mod.getNeuro(i); 74 Neuro *n = getNeuro(i); 75 for (int ni = 0; ni < oldn->getInputCount(); ni++) 76 { 77 double w; 78 Neuro *oldinput = oldn->getInput(ni, w); 79 SString info = n->getInputInfo(ni); 80 n->addInput(getNeuro(oldinput->refno), w, &info); 81 } 82 } 83 updateRefno(); 84 if (using_checkpoints) 85 for (vector<Model*>::const_iterator it = mod.checkpoints.begin(); it != mod.checkpoints.end(); it++) 86 { 87 Model *m = *it; 88 Model *n = new Model(*m, m->autobuildmaps, false, true); 89 checkpoints.push_back(n); 90 } 91 } 92 93 94 Model::Model(const Geno &src, bool buildmaps, bool _using_checkpoints, bool _is_checkpoint) 86 95 :autobuildmaps(buildmaps) 87 96 { 88 init(src );97 init(src, _using_checkpoints, _is_checkpoint); 89 98 } 90 99 … … 92 101 { 93 102 clear(); 94 open( );103 open(mod.isUsingCheckpoints(), mod.isCheckpoint()); 95 104 internalCopy(mod); 96 105 buildstatus = mod.buildstatus; 97 106 } 98 107 99 Model::Model(const Model &mod, bool buildmaps )108 Model::Model(const Model &mod, bool buildmaps, bool _using_checkpoints, bool _is_checkpoint) 100 109 :autobuildmaps(buildmaps) 101 110 { 102 111 init(); 103 open( );112 open(_using_checkpoints, _is_checkpoint); 104 113 internalCopy(mod); 105 buildstatus = mod.buildstatus; 106 } 107 108 void Model::init(const Geno &src) 114 if (is_checkpoint) 115 close(); 116 else 117 buildstatus = mod.buildstatus; 118 if (mod.map) 119 map = new MultiMap(*mod.map); 120 if (mod.f0map) 121 f0map = new MultiMap(*mod.f0map); 122 } 123 124 void Model::init(const Geno &src, bool _using_checkpoints, bool _is_checkpoint) 109 125 { 110 126 init(); 127 using_checkpoints = _using_checkpoints; 128 is_checkpoint = _is_checkpoint; 111 129 modelfromgenotype = 1; 112 130 geno = src; … … 146 164 geno = Geno(); 147 165 f0geno = Geno(); 166 for (vector<Model*>::iterator it = checkpoints.begin(); it != checkpoints.end(); it++) 167 delete *it; 168 checkpoints.clear(); 148 169 } 149 170 … … 293 314 Model::ItemType Model::itemTypeFromLinePrefix(const char* line) 294 315 { 295 struct PrefixAndItem { const char* prefix; ItemType type; };296 static const PrefixAndItem types[]={ {"m:",ModelType},{"p:",PartType},{"j:",JointType},{"n:",NeuronType},{"c:",NeuronConnectionType},{NULL} };297 for(const PrefixAndItem *t=types;t->prefix!=NULL;t++)298 { 299 const char* in=line;300 const char* pattern=t->prefix;301 for(;*in==*pattern;in++,pattern++)302 if (*pattern==':')303 return t->type;304 } 305 return UnknownType;316 struct PrefixAndItem { const char* prefix; ItemType type; }; 317 static const PrefixAndItem types[] = { { "m:", ModelType }, { "p:", PartType }, { "j:", JointType }, { "n:", NeuronType }, { "c:", NeuronConnectionType }, { F0_CHECKPOINT_LINE, CheckpointType }, { NULL } }; 318 for (const PrefixAndItem *t = types; t->prefix != NULL; t++) 319 { 320 const char* in = line; 321 const char* pattern = t->prefix; 322 for (; *in == *pattern; in++, pattern++) 323 if (*pattern == ':') 324 return t->type; 325 } 326 return UnknownType; 306 327 } 307 328 … … 311 332 f0warnposition = -1; 312 333 MultiMap *convmap = autobuildmaps ? new MultiMap() : NULL; 313 f0geno = (geno.getFormat() == '0') ? geno : geno.getConverted('0', convmap );334 f0geno = (geno.getFormat() == '0') ? geno : geno.getConverted('0', convmap, using_checkpoints); 314 335 f0genoknown = 1; 315 336 if (f0geno.isInvalid()) … … 331 352 MultiRange frommap; 332 353 LoggerToMemory mh(LoggerBase::Enable | LoggerBase::DontBlock); 354 Model *current_model = this; 333 355 for (; f0txt.getNextToken(pos, line, '\n'); lnum++) 334 356 { 335 const char* line_ptr =line.c_str();357 const char* line_ptr = line.c_str(); 336 358 for (; *line_ptr; line_ptr++) 337 359 if (!strchr(" \r\t", *line_ptr)) break; … … 339 361 if (!*line_ptr) continue; 340 362 341 const char* colon =strchr(line_ptr,':');342 ItemType type =UnknownType;363 const char* colon = strchr(line_ptr, ':'); 364 ItemType type = UnknownType; 343 365 SString excluding_prefix; 344 if (colon !=NULL)345 366 if (colon != NULL) 367 { 346 368 colon++; 347 type =itemTypeFromLinePrefix(line_ptr);369 type = itemTypeFromLinePrefix(line_ptr); 348 370 for (; *colon; colon++) 349 371 if (!strchr(" \r\t", *colon)) break; 350 excluding_prefix =colon;351 352 372 excluding_prefix = colon; 373 } 374 353 375 if (autobuildmaps) 354 376 { … … 357 379 } 358 380 mh.reset(); 359 if (addFromString(type, excluding_prefix, lnum, autobuildmaps ? (&frommap) : 0) == -1) 381 if (type == CheckpointType) 382 { 383 current_model->close(); 384 current_model = new Model; 385 current_model->open(false, true); 386 checkpoints.push_back(current_model); 387 } 388 else if (current_model->addFromString(type, excluding_prefix, lnum, autobuildmaps ? (&frommap) : 0) == -1) 360 389 { 361 390 buildstatus = invalid; … … 371 400 } 372 401 mh.disable(); 373 c lose();402 current_model->close(); 374 403 if (convmap) 375 404 { … … 503 532 } 504 533 } 534 535 for (vector<Model*>::const_iterator it = checkpoints.begin(); it != checkpoints.end(); it++) 536 { 537 Geno g = (*it)->getF0Geno(); 538 gen += F0_CHECKPOINT_LINE "\n"; 539 gen += g.getGenes(); 540 } 541 505 542 g = Geno(gen.c_str(), '0'); 506 543 } … … 508 545 ////////////// 509 546 510 void Model::open( )547 void Model::open(bool _using_checkpoints, bool _is_checkpoint) 511 548 { 512 549 if (buildstatus == building) return; 550 using_checkpoints = _using_checkpoints; 551 is_checkpoint = _is_checkpoint; 513 552 buildstatus = building; 514 553 modelfromgenotype = 0; … … 518 557 } 519 558 559 int Model::getCheckpointCount() 560 { 561 return checkpoints.size(); 562 } 563 564 Model* Model::getCheckpoint(int i) 565 { 566 return checkpoints[i]; 567 } 568 520 569 void Model::checkpoint() 521 {} 570 { 571 if (!using_checkpoints) return; 572 updateRefno(); 573 Model *m = new Model(*this, false, false, true); 574 checkpoints.push_back(m); 575 } 522 576 523 577 void Model::setGeno(const Geno& newgeno) … … 544 598 if (buildstatus != building) 545 599 logPrintf("Model", "close", LOG_WARN, "Unexpected close() - no open()"); 546 if (internalcheck( building_live_model ? LIVE_CHECK : FINAL_CHECK) > 0)600 if (internalcheck(is_checkpoint ? CHECKPOINT_CHECK : (building_live_model ? LIVE_CHECK : FINAL_CHECK)) > 0) 547 601 { 548 602 buildstatus = valid; … … 589 643 int Model::addFromString(ItemType item_type, const SString &singleline, const MultiRange* srcrange) 590 644 { 591 return addFromString(item_type, singleline, 0, srcrange);645 return addFromString(item_type, singleline, 0, srcrange); 592 646 } 593 647 … … 612 666 error_message = SString::empty(); 613 667 ParamInterface::LoadOptions opts; 614 switch (item_type)615 616 617 668 switch (item_type) 669 { 670 case PartType: 671 { 618 672 Param partparam(f0_part_paramtab); 619 673 Part *p = new Part(); … … 626 680 if (srcrange) p->setMapping(*srcrange); 627 681 return getPartCount() - 1; 628 629 630 631 682 } 683 684 case ModelType: 685 { 632 686 Param modelparam(f0_model_paramtab); 633 687 modelparam.select(this); … … 635 689 if (opts.parse_failed) { error_message = "Invalid 'm:'"; return -1; } 636 690 return 0; 637 638 639 640 691 } 692 693 case JointType: 694 { 641 695 Param jointparam(f0_joint_paramtab); 642 696 Joint *j = new Joint(); … … 665 719 return -1; 666 720 } 667 668 669 670 721 } 722 723 case NeuronType: 724 { 671 725 Param neuroparam(f0_neuro_paramtab); 672 726 Neuro *nu = new Neuro(); … … 714 768 return neurons.size() - 1; 715 769 } 716 717 718 case NeuronConnectionType:719 770 } 771 772 case NeuronConnectionType: 773 { 720 774 Param ncparam(f0_neuroconn_paramtab); 721 775 NeuroConn c; … … 736 790 error_message = SString::sprintf("Invalid reference to Neuro #%d", n1_ok ? c.n2_refno : c.n1_refno); 737 791 return -1; 738 739 740 741 742 792 } 793 794 case CheckpointType: case UnknownType: //handled by addFromString for uniform error handling 795 return -1; 796 } 743 797 return -1; 744 798 } … … 747 801 ///////////// 748 802 749 /** change the sequence of neuro units 750 and fix references in "-" objects (n-n connections) */ 751 void Model::moveNeuro(int oldpos, int newpos) 752 { 753 if (oldpos == newpos) return; // nop! 754 Neuro *n = getNeuro(oldpos); 755 neurons -= oldpos; 756 neurons.insert(newpos, n); 757 // conn_refno could be broken -> fix it 758 } 759 760 //////////// 761 762 void Model::updateNeuroRefno() 763 { 803 void Model::updateRefno() 804 { 805 for (int i = 0; i < parts.size(); i++) 806 getPart(i)->refno = i; 807 for (int i = 0; i < joints.size(); i++) 808 { 809 Joint *j = getJoint(i); 810 j->refno = i; 811 if (j->part1 && j->part2 && (j->part1 != j->part2)) 812 { 813 j->p1_refno = j->part1->refno; 814 j->p2_refno = j->part2->refno; 815 } 816 } 764 817 for (int i = 0; i < neurons.size(); i++) 765 { 766 Neuro* n = (Neuro*)neurons(i); 767 n->refno = i; 768 } 818 getNeuro(i)->refno = i; 769 819 } 770 820 … … 779 829 #define LINKFLAG 0x8000000 780 830 781 void Model::updateRefno()782 {783 int i;784 for (i = 0; i < getPartCount(); i++) getPart(i)->refno = i;785 for (i = 0; i < getJointCount(); i++) getJoint(i)->refno = i;786 for (i = 0; i < getNeuroCount(); i++) getNeuro(i)->refno = i;787 }788 789 831 SString Model::nameForErrors() const 790 832 { … … 802 844 int ret = 1; 803 845 shape = SHAPE_UNKNOWN; 846 updateRefno(); 804 847 if ((parts.size() == 0) && (neurons.size() == 0)) return 0; 805 848 if (parts.size() == 0) … … 812 855 p = (Part*)parts(i); 813 856 p->owner = this; 814 p->refno = i;815 857 if (checklevel > 0) 816 858 p->mass = 0.0; … … 907 949 } 908 950 } 909 if ( check != LIVE_CHECK)951 if ((check != LIVE_CHECK) && (check != CHECKPOINT_CHECK)) 910 952 { 911 953 if (j->shape != Joint::SHAPE_FIXED) … … 935 977 } 936 978 937 updateNeuroRefno(); // valid refno is important for n-n connections check (later)938 939 979 for (i = 0; i < neurons.size(); i++) 940 980 { … … 944 984 } 945 985 946 if ( parts.size() && (checklevel > 0))947 { 948 for (i = 0; i < parts.size(); i++) 949 {950 p = (Part*)parts(i);951 if (p->mass <= 0.001)952 p->mass = 1.0;953 p->flags &= ~LINKFLAG;954 }955 getPart(0)->flags |= LINKFLAG;956 int change = 1;957 while (change)958 {959 change = 0;960 for (i = 0; i < joints.size(); i++)961 { 962 j = (Joint*)joints(i);963 if (j->part1->flags&LINKFLAG)986 if (check != CHECKPOINT_CHECK) 987 { 988 989 if (parts.size() && (checklevel > 0)) 990 { 991 for (i = 0; i < parts.size(); i++) 992 { 993 p = (Part*)parts(i); 994 if (p->mass <= 0.001) 995 p->mass = 1.0; 996 p->flags &= ~LINKFLAG; 997 } 998 getPart(0)->flags |= LINKFLAG; 999 int change = 1; 1000 while (change) 1001 { 1002 change = 0; 1003 for (i = 0; i < joints.size(); i++) 964 1004 { 965 if (!(j->part2->flags&LINKFLAG)) 1005 j = (Joint*)joints(i); 1006 if (j->part1->flags&LINKFLAG) 966 1007 { 967 change = 1; 968 j->part2->flags |= LINKFLAG; 1008 if (!(j->part2->flags&LINKFLAG)) 1009 { 1010 change = 1; 1011 j->part2->flags |= LINKFLAG; 1012 } 969 1013 } 1014 else 1015 if (j->part2->flags&LINKFLAG) 1016 { 1017 if (!(j->part1->flags&LINKFLAG)) 1018 { 1019 change = 1; 1020 j->part1->flags |= LINKFLAG; 1021 } 1022 } 970 1023 } 971 else 972 if (j->part2->flags&LINKFLAG) 973 { 974 if (!(j->part1->flags&LINKFLAG)) 975 { 976 change = 1; 977 j->part1->flags |= LINKFLAG; 978 } 979 } 980 } 981 } 982 for (i = 0; i < parts.size(); i++) 983 { 984 p = (Part*)parts(i); 985 if (!(p->flags&LINKFLAG)) 986 { 987 logPrintf("Model", "internalCheck", LOG_ERROR, "Not all parts connected (eg. Part #0 and Part #%d)%s", i, nameForErrors().c_str()); 1024 } 1025 for (i = 0; i < parts.size(); i++) 1026 { 1027 p = (Part*)parts(i); 1028 if (!(p->flags&LINKFLAG)) 1029 { 1030 logPrintf("Model", "internalCheck", LOG_ERROR, "Not all parts connected (eg. Part #0 and Part #%d)%s", i, nameForErrors().c_str()); 1031 ret = 0; 1032 break; 1033 } 1034 } 1035 } 1036 1037 for (i = 0; i < joints.size(); i++) 1038 { 1039 j = (Joint*)joints(i); 1040 if (j->p1_refno == j->p2_refno) 1041 { 1042 logPrintf("Model", "internalCheck", LOG_ERROR, "Illegal self connection, Joint #%d%s", i, nameForErrors().c_str()); 988 1043 ret = 0; 989 1044 break; 990 1045 } 991 } 992 } 993 994 for (i = 0; i < joints.size(); i++) 995 { 996 j = (Joint*)joints(i); 997 if (j->p1_refno == j->p2_refno) 998 { 999 logPrintf("Model", "internalCheck", LOG_ERROR, "Illegal self connection, Joint #%d%s", i, nameForErrors().c_str()); 1000 ret = 0; 1001 break; 1002 } 1003 for (k = i + 1; k < joints.size(); k++) 1004 { 1005 Joint* j2 = (Joint*)joints(k); 1006 if (((j->p1_refno == j2->p1_refno) && (j->p2_refno == j2->p2_refno)) 1007 || ((j->p1_refno == j2->p2_refno) && (j->p2_refno == j2->p1_refno))) 1008 { 1009 logPrintf("Model", "internalCheck", LOG_ERROR, "Illegal duplicate Joint #%d and Joint #%d%s", i, k, nameForErrors().c_str()); 1010 ret = 0; 1011 break; 1012 } 1013 } 1014 } 1046 for (k = i + 1; k < joints.size(); k++) 1047 { 1048 Joint* j2 = (Joint*)joints(k); 1049 if (((j->p1_refno == j2->p1_refno) && (j->p2_refno == j2->p2_refno)) 1050 || ((j->p1_refno == j2->p2_refno) && (j->p2_refno == j2->p1_refno))) 1051 { 1052 logPrintf("Model", "internalCheck", LOG_ERROR, "Illegal duplicate Joint #%d and Joint #%d%s", i, k, nameForErrors().c_str()); 1053 ret = 0; 1054 break; 1055 } 1056 } 1057 } 1058 } 1059 1015 1060 if (shape == SHAPE_ILLEGAL) 1016 1061 ret = 0; … … 1250 1295 ////////////////////// 1251 1296 1297 int Model::elementToMap(ItemType type, int index) 1298 { 1299 switch (type) 1300 { 1301 case PartType: return partToMap(index); 1302 case JointType: return jointToMap(index); 1303 case NeuronType: return neuroToMap(index); 1304 default: return -1; 1305 } 1306 } 1307 1308 Model::TypeAndIndex Model::mapToElement(int map_index) 1309 { 1310 if ((map_index >= 0) && (map_index < MODEL_MAPPING_OFFSET)) 1311 return TypeAndIndex(PartType, mapToPart(map_index)); 1312 if ((map_index >= MODEL_MAPPING_OFFSET) && (map_index < 2 * MODEL_MAPPING_OFFSET)) 1313 return TypeAndIndex(JointType, mapToJoint(map_index)); 1314 if ((map_index >= 2 * MODEL_MAPPING_OFFSET) && (map_index < 3 * MODEL_MAPPING_OFFSET)) 1315 return TypeAndIndex(NeuronType, mapToNeuro(map_index)); 1316 return TypeAndIndex(); 1317 } 1318 1319 int Model::partToMap(int i) { return MODEL_MAPPING_OFFSET + i; } 1320 int Model::jointToMap(int i) { return 2 * MODEL_MAPPING_OFFSET + i; } 1321 int Model::neuroToMap(int i) { return 3 * MODEL_MAPPING_OFFSET + i; } 1322 int Model::mapToPart(int i) { return i - MODEL_MAPPING_OFFSET; } 1323 int Model::mapToJoint(int i) { return i - 2 * MODEL_MAPPING_OFFSET; } 1324 int Model::mapToNeuro(int i) { return i - 3 * MODEL_MAPPING_OFFSET; } 1325 1326 1327 ////////////////////// 1328 1252 1329 class MinPart : public Part { public: MinPart() { Param par(f0_part_paramtab, this); par.setMin(); } }; 1253 1330 class MaxPart : public Part { public: MaxPart() { Param par(f0_part_paramtab, this); par.setMax(); } }; -
cpp/frams/model/model.h
r726 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 … … 15 15 16 16 extern ParamEntry f0_model_paramtab[]; 17 18 //#define EASYMAPDEBUG19 17 20 18 enum ModelBuildStatus { empty, building, invalid, valid }; … … 64 62 /// make model map in build() 65 63 bool autobuildmaps; 64 /// supports adding checkpoints 65 bool using_checkpoints; 66 /// means less strict validation 67 bool is_checkpoint; 66 68 /// valid if build from f0 genotype 67 69 int f0errorposition; … … 75 77 SList parts, joints, neurons; 76 78 char partmappingchanged; 79 vector<Model*> checkpoints; 77 80 78 81 void internalCopy(const Model &mod); … … 95 98 EDITING_CHECK, ///< Used in Model::validate(). Default validation - does not modify elements of the Model. 96 99 FINAL_CHECK, ///< Used in Model::close() when a Model is built from a genotype. Like EDITING_CHECK, but also calculates Joint::d and Joint::rot. 97 LIVE_CHECK ///< used in Model::close() when a Model is built from a Creature. Like FINAL_CHECK but does not limit joint length which could make some liveModels invalid. 100 LIVE_CHECK, ///< used in Model::close() when a Model is built from a Creature. Like FINAL_CHECK but does not limit joint length which could make some liveModels invalid. 101 CHECKPOINT_CHECK ///< used when storing checkpoint models. Like LIVE_CHECK, excluding consistency check (disjoint parts are acceptable) 98 102 }; 99 103 protected: 100 104 ShapeType shape; 101 105 102 void updateNeuroRefno(); // set Neuro::refno for all neurons103 106 SString nameForErrors() const; 104 107 int internalcheck(CheckType check); 105 108 106 void moveNeuro(int oldpos, int newpos); 107 108 void init(const Geno &srcgen); 109 void init(const Geno &srcgen, bool _using_checkpoints, bool _is_checkpoint); 109 110 void init(); 110 111 … … 134 135 int getErrorPosition(bool includingwarnings = false); 135 136 ShapeType getShapeType() const { return shape; } 137 bool isUsingCheckpoints() const { return using_checkpoints; } 138 bool isCheckpoint() const { return is_checkpoint; } 136 139 137 140 void updateRefno(); // set ::refno for all elements 141 142 int getCheckpointCount(); 143 Model* getCheckpoint(int i); 138 144 139 145 /// The bounding box size. Valid if the model is valid. Read only. … … 153 159 @see getMap() 154 160 */ 155 Model(const Geno &src, bool buildmaps = false );156 Model(const Model &mod, bool buildmaps = false );161 Model(const Geno &src, bool buildmaps = false, bool _using_checkpoints = false, bool _is_checkpoint = false); 162 Model(const Model &mod, bool buildmaps = false, bool _using_checkpoints = false, bool _is_checkpoint = false); 157 163 /** duplicate the model. 158 164 the resulting object's status is 'building' (opened). … … 255 261 void clear(); 256 262 257 enum ItemType { UnknownType, ModelType,PartType,JointType,NeuronType,NeuronConnectionType };263 enum ItemType { UnknownType, ModelType, PartType, JointType, NeuronType, NeuronConnectionType, CheckpointType }; 258 264 static ItemType itemTypeFromLinePrefix(const char* line); 259 265 /** Execute single line of <B>f0</B> genotype. … … 264 270 @param srcrange source genotype range which will be mapped to this element 265 271 */ 266 int addFromString(ItemType item_type, const SString &singleline, int line_num, const MultiRange* srcrange = NULL);272 int addFromString(ItemType item_type, const SString &singleline, int line_num, const MultiRange* srcrange = NULL); 267 273 /** Execute single line of <B>f0</B> genotype - compatiblity variant */ 268 int addFromString(ItemType item_type, const SString &singleline, const MultiRange* srcrange = NULL);274 int addFromString(ItemType item_type, const SString &singleline, const MultiRange* srcrange = NULL); 269 275 /** Execute single line of <B>f0</B> genotype - low level variant, used by Model::build(), error messages returned as string instead of calling logger */ 270 int addFromStringNoLog(ItemType item_type, const SString &singleline, SString& error_message, const MultiRange* srcrange = 0);276 int addFromStringNoLog(ItemType item_type, const SString &singleline, SString& error_message, const MultiRange* srcrange = 0); 271 277 272 278 /// separate build stages (for future use) … … 289 295 /// or modify the model created from the genotype. 290 296 /// Between open() and close() the model is not fully usable. 291 void open( );297 void open(bool _using_checkpoints = false, bool _is_checkpoint = false); 292 298 293 299 /// Current model written as f0 genotype while building … … 379 385 void buildUsingSolidShapeTypes(const Model& src_ballandstick_shapes, Part::Shape use_shape = Part::SHAPE_CYLINDER, float thickness = 0.2); 380 386 381 #ifdef EASYMAPDEBUG 382 static int partToMap(int i) {return 0+i;} 383 static int jointToMap(int i) {return 10+i;} 384 static int neuroToMap(int i) {return 20+i;} 385 static int mapToPart(int i) {return i-0;} 386 static int mapToJoint(int i) {return i-10;} 387 static int mapToNeuro(int i) {return i-20;} 388 #else 389 static int partToMap(int i) { return 0x10000000 + i; } 390 static int jointToMap(int i) { return 0x20000000 + i; } 391 static int neuroToMap(int i) { return 0x30000000 + i; } 392 static int mapToPart(int i) { return i - 0x10000000; } 393 static int mapToJoint(int i) { return i - 0x20000000; } 394 static int mapToNeuro(int i) { return i - 0x30000000; } 395 #endif 387 protected: 388 static const int MODEL_MAPPING_OFFSET = 0x10000000; 389 public: 390 static int elementToMap(ItemType t, int i); 391 struct TypeAndIndex 392 { 393 ItemType type; int index; 394 TypeAndIndex() :type(UnknownType), index(0) {} 395 TypeAndIndex(ItemType _type, int _index) :type(_type), index(_index) {} 396 }; 397 static TypeAndIndex mapToElement(int i); 398 static int partToMap(int i); 399 static int jointToMap(int i); 400 static int neuroToMap(int i); 401 static int mapToPart(int i); 402 static int mapToJoint(int i); 403 static int mapToNeuro(int i); 396 404 397 405 static void makeGenToGenMap(MultiMap& result, const MultiMap& gen1tomodel, const MultiMap& gen2tomodel); -
cpp/frams/model/modelobj.cpp
r722 r732 7 7 ParamEntry modelobj_paramtab[] = 8 8 { 9 { "Model", 1, 16, "Model", },9 { "Model", 1, 21, "Model", }, 10 10 { "se", 0, PARAM_NOSTATIC, "startenergy", "f", FIELD(startenergy), }, 11 11 { "Vstyle", 0, PARAM_NOSTATIC, "vis_style", "s", FIELD(vis_style), }, 12 12 13 { "geno", 0, PARAM_NOSTATIC | PARAM_READONLY, "geno", "o Geno", GETONLY(geno), }, 14 { "newFromString", 0, 0, "create new object", "p oModel(s genotype)", PROCEDURE(p_newfromstring), }, 15 { "newFromGeno", 0, 0, "create new object", "p oModel(oGeno)", PROCEDURE(p_newfromgeno), }, 13 { "geno", 0, PARAM_NOSTATIC | PARAM_READONLY, "Geno", "oGeno", GETONLY(geno), }, 14 { "newFromString", 0, 0, "Create a new object", "p oModel(s genotype)", PROCEDURE(p_newfromstring), }, 15 { "newFromGeno", 0, 0, "Create a new object", "p oModel(oGeno)", PROCEDURE(p_newfromgeno), }, 16 { "newWithCheckpoints", 0, 0, "Create a new object", "p oModel(x Geno object or string genotype)", PROCEDURE(p_newwithcheckpoints), "Creates a Model with the \"Checkpoints\" option enabled. Genotype converters supporting Checkpoints provide a sequence of Models that reflects development stages of the creature (this sequence is used purely for debugging and visualization of phenotype growth/development). Checkpoint Models can be accessed using getCheckpoint(i) for i ranging from 0 to numcheckpoints-1. Models created without the Checkpoint option and Models coming from unsupported converters have numcheckpoints=0." }, 16 17 17 { "numparts", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, " number of parts", "d", GETONLY(numparts), },18 { "numjoints", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, " number of joints", "d", GETONLY(numjoints), },19 { "numneurons", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, " number of neurons", "d", GETONLY(numneurons), },20 { "numconnections", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, " number of neuron connections", "d", GETONLY(numconnections), },18 { "numparts", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of parts", "d", GETONLY(numparts), }, 19 { "numjoints", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of joints", "d", GETONLY(numjoints), }, 20 { "numneurons", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of neurons", "d", GETONLY(numneurons), }, 21 { "numconnections", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Number of neuron connections", "d", GETONLY(numconnections), }, 21 22 22 23 { "getPart", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "getPart (static model information)", "p oPart(d index)", PROCEDURE(p_getpart), }, … … 24 25 { "getNeuroDef", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "getNeuroDef", "p oNeuroDef(d index)", PROCEDURE(p_getneuro), }, 25 26 26 { "size_x", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, " bounding box x size", "f", FIELD(size.x), "(size_x,size_y,size_z) are dimensions of the axis-aligned bounding box of the creature, including imaginary Part sizes (Part.s, usually 1.0). A creature consisting of a single default part has the size of (2.0,2.0,2.0) - twice the Part.s value (like a sphere diameter is twice its radius).\nSee also: Creature.moveAbs" },27 { "size_y", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, " bounding box y size", "f", FIELD(size.y), "See Model.size_x" },28 { "size_z", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, " bounding box z size", "f", FIELD(size.z), "See Model.size_x" },27 { "size_x", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "Bounding box x size", "f", FIELD(size.x), "(size_x,size_y,size_z) are dimensions of the axis-aligned bounding box of the creature, including imaginary Part sizes (Part.s, usually 1.0). A creature consisting of a single default part has the size of (2.0,2.0,2.0) - twice the Part.s value (like a sphere diameter is twice its radius).\nSee also: Creature.moveAbs" }, 28 { "size_y", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "Bounding box y size", "f", FIELD(size.y), "See Model.size_x" }, 29 { "size_z", 0, PARAM_READONLY | PARAM_NOSTATIC | PARAM_DEPRECATED, "Bounding box z size", "f", FIELD(size.z), "See Model.size_x" }, 29 30 { "bboxSize", 0, PARAM_READONLY | PARAM_NOSTATIC, "Bounding box size", "oXYZ", GETONLY(bboxsize) }, 31 { "numcheckpoints", 0, PARAM_DONTSAVE | PARAM_READONLY | PARAM_NOSTATIC, "Number of checkpoints", "d", GETONLY(numcheckpoints) }, 32 { "getCheckpoint", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "getCheckpoint", "p oModel(d index)", PROCEDURE(p_getcheckpoint), 33 "Checkpoint Model objects are only valid as long as the parent Model object exists.\n" 34 "See also: Model.newWithCheckpoints()\n\n" 35 "// incorrect usage - calling getCheckpoint() on a temporary object:\n" 36 "var c=Model.newWithCheckpoints(\"XXX\").getCheckpoint(1).genotype.geno;\n\n" 37 "// correct usage - keeping the parent Model reference in 'm':\n" 38 "var m=Model.newWithCheckpoints(\"XXX\");\n" 39 "var c=m.getCheckpoint(1).genotype.geno;\n" 40 }, 41 { "shape_type", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Shape type", "d 0 3 ~Unknown~Illegal~Ball-and-stick~Solids", GETONLY(shape_type) }, 42 { "solid_model", 0, PARAM_DONTSAVE | PARAM_NOSTATIC | PARAM_READONLY, "Solid shapes model", "oModel", GETONLY(solid_model), "Conversion of this Model to solid shapes. Note! Only available when this Model has shape_type==2 (Ball-and-stick)." }, 30 43 31 44 { 0, 0, 0, }, … … 57 70 } 58 71 72 void ModelObj::p_newwithcheckpoints(ExtValue *args, ExtValue *ret) 73 { 74 Model *m = NULL; 75 if (args[0].getType() == TString) 76 m = new Model(Geno(args[0].getString()), false, true); 77 else 78 { 79 Geno *g = GenoObj::fromObject(args[0].getObject(), false); 80 if (g) 81 m = new Model(*g, false, true); 82 else 83 logPrintf("Model", "newWithCheckpoints", LOG_ERROR, "Geno or string expected, %s found", args[0].typeDescription().c_str()); 84 } 85 86 if (m != NULL) 87 *ret = makeDynamicObject(m); 88 else 89 ret->setEmpty(); 90 } 91 59 92 Param& ModelObj::getStaticParam() 60 93 { 61 94 #ifdef __CODEGUARD__ 62 95 static ModelObj static_modelobj; 63 static Param static_modelparam(modelobj_paramtab, &static_modelobj);96 static Param static_modelparam(modelobj_paramtab, &static_modelobj); 64 97 #else 65 98 static Param static_modelparam(modelobj_paramtab); … … 131 164 *ret = Pt3D_Ext::makeDynamicObject(new Pt3D_Ext(size)); 132 165 } 166 167 void ModelObj::p_getcheckpoint(PARAMPROCARGS) 168 { 169 int i = args->getInt(); 170 if ((i < 0) || (i >= getCheckpointCount())) 171 { 172 ret->setEmpty(); 173 return; 174 } 175 ret->setObject(makeStaticObject(getCheckpoint(i))); 176 } 177 178 void ModelObj::get_solid_model(ExtValue *ret) 179 { 180 if (getShapeType() != Model::SHAPE_BALL_AND_STICK) 181 ret->setEmpty(); 182 Model *m = new Model; 183 m->open(); 184 m->buildUsingSolidShapeTypes(*this); 185 m->close(); 186 *ret = makeDynamicObject(m); 187 } 188 189 void ModelObj::get_shape_type(ExtValue *ret) 190 { 191 ret->setInt(getShapeType()); 192 } -
cpp/frams/model/modelobj.h
r722 r732 14 14 PARAMPROCDEF(p_newfromstring); 15 15 PARAMPROCDEF(p_newfromgeno); 16 PARAMPROCDEF(p_newwithcheckpoints); 16 17 17 18 #define GETDELEGATE(name,type,value) PARAMGETDEF(name) {arg1->set ## type (value);} … … 20 21 GETDELEGATE(numneurons, Int, getNeuroCount()) 21 22 GETDELEGATE(numconnections, Int, getConnectionCount()) 23 GETDELEGATE(numcheckpoints, Int, getCheckpointCount()) 22 24 #undef GETDELEGATE 23 25 … … 26 28 PARAMPROCDEF(p_getneuro); 27 29 PARAMGETDEF(bboxsize); 30 PARAMPROCDEF(p_getcheckpoint); 31 PARAMGETDEF(shape_type); 32 PARAMGETDEF(solid_model); 28 33 29 34 #undef STATRICKCLASS -
cpp/frams/neuro/neuroimpl.cpp
r720 r732 324 324 { "position_y", 0, PARAM_READONLY, "Position y", "f", GETONLY(position_y), }, 325 325 { "position_z", 0, PARAM_READONLY, "Position z", "f", GETONLY(position_z), }, 326 { "creature", 0, PARAM_READONLY, "Gets owner creature", "o 327 { "part", 0, PARAM_READONLY, "The Part object where this neuron is located", "o 328 { "joint", 0, PARAM_READONLY, "The Joint object where this neuron is located", "o 329 { "neuroproperties", 0, PARAM_READONLY, "Custom neuron fields", "o 326 { "creature", 0, PARAM_READONLY, "Gets owner creature", "oCreature", GETONLY(creature), }, 327 { "part", 0, PARAM_READONLY, "The Part object where this neuron is located", "oMechPart", GETONLY(part), }, 328 { "joint", 0, PARAM_READONLY, "The Joint object where this neuron is located", "oMechJoint", GETONLY(joint), }, 329 { "neuroproperties", 0, PARAM_READONLY, "Custom neuron fields", "oNeuroProperties", GETONLY(fields), 330 330 "Neurons can have different fields depending on their class. Script neurons have their fields defined using the \"property:\" syntax. If you develop a custom neuron script you should use the NeuroProperties object for accessing your own neuron fields. The Neuro.neuroproperties property is meant for accessing the neuron fields from the outside script.\n" 331 331 "Examples:\n" … … 341 341 "for(i=0;i<iobj.size;i++)\n" 342 342 " Simulator.print(iobj.getId(i)+\" (\"+iobj.getName(i)+\")\");", }, 343 { "def", 0, PARAM_READONLY, "Neuron definition from which this live neuron was built", "o 344 { "classObject", 0, PARAM_READONLY, "Neuron class for this neuron", "o 343 { "def", 0, PARAM_READONLY, "Neuron definition from which this live neuron was built", "oNeuroDef", GETONLY(neurodef), }, 344 { "classObject", 0, PARAM_READONLY, "Neuron class for this neuron", "oNeuroClass", GETONLY(classObject), }, 345 345 #ifdef NEURO_SIGNALS 346 { "signals", 0, PARAM_READONLY, "Signals", "o 346 { "signals", 0, PARAM_READONLY, "Signals", "oNeuroSignals", FIELD(sigs_obj), }, 347 347 #endif 348 348 -
cpp/frams/param/param.cpp
r720 r732 853 853 else 854 854 { 855 if ((t[0] == 'o') && (t[1] == ' ')) 856 { 857 err = "space after 'o'"; 858 } 855 859 if (!(pe->flags & (PARAM_READONLY | PARAM_DONTSAVE | PARAM_USERREADONLY | PARAM_CONST | PARAM_DONTLOAD | PARAM_LINECOMMENT | PARAM_OBJECTSET))) 856 860 { //write access … … 1287 1291 if (i >= 0) i++; 1288 1292 #ifdef __CODEGUARD__ 1289 if (next_field <end-1) t=next_field+1; else return fields_loaded;1293 if (next_field < end - 1) t = next_field + 1; else return fields_loaded; 1290 1294 #else 1291 1295 t = next_field + 1; -
cpp/frams/vm/classes/genoobj.cpp
r534 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 … … 11 11 ParamEntry geno_paramtab[] = 12 12 { 13 { "Geno", 1, 1 5, "Geno", "All information about a single genotype.\nThis is a genetics-only object which does not contain any performance data. See also: Genotype class" },13 { "Geno", 1, 16, "Geno", "All information about a single genotype.\nThis is a genetics-only object which does not contain any performance data. See also: Genotype class" }, 14 14 { "name", 0, PARAM_NOSTATIC, "Name", "s 0 40", GETSET(name), }, 15 15 { "rawgenotype", 0, PARAM_NOSTATIC | PARAM_READONLY, "Raw genotype", "s 1", GETONLY(genotype), "Genotype, excluding the format specifier" }, … … 23 23 "-1 = validity is not known. This is a transient state. The value of \"is_valid\" will never be -1 when read. It is safe to treat is_valid as boolean in statements like \"if (g.is_valid) ...\". Setting \"is_valid=-1\" will make it 0 or 1 again. This third state (-1) is only needed for loading Genotype objects from files where the \"is_valid\" field might not be present." 24 24 }, 25 { "getConverted", 0, PARAM_NOSTATIC, "get converted genotype", "p oGeno(s format)", PROCEDURE(p_getconvert), }, 25 { "getConverted", 0, PARAM_NOSTATIC, "Get converted genotype", "p oGeno(s format)", PROCEDURE(p_getconvert), }, 26 { "getConvertedWithCheckpoints", 0, PARAM_NOSTATIC, "Get converted genotype", "p oGeno(s format)", PROCEDURE(p_getconvert_ch), "See also Model.newWithCheckpoints()" }, 26 27 { "f0genotype", 0, PARAM_NOSTATIC | PARAM_READONLY, "f0 genotype", "s 1", GETONLY(f0genotype), "converted to f0 genotype", }, 27 28 { "new", 0, 0, "create new empty object", "p oGeno()", PROCEDURE(p_new), }, … … 85 86 void GenoObj::get_format(ExtValue *ret) 86 87 { 87 char format_as_string[2] ={getFormat(),0};88 char format_as_string[2] = { getFormat(), 0 }; 88 89 ret->setString(format_as_string); 89 90 } … … 102 103 char GenoObj::formatFromExtValue(ExtValue& v) 103 104 { 104 if (v.getType()==TInt)105 return v.getInt();106 if (v.getType()==TString)105 if (v.getType() == TInt) 106 return v.getInt(); 107 if (v.getType() == TString) 107 108 { 108 SString s=v.getString();109 if (s.len()==1)110 return s.charAt(0);109 SString s = v.getString(); 110 if (s.len() == 1) 111 return s.charAt(0); 111 112 } 112 return Geno::INVALID_FORMAT;113 return Geno::INVALID_FORMAT; 113 114 } 114 115 … … 116 117 { 117 118 *ret = makeDynamicObjectAndDecRef(new Geno(getConverted(formatFromExtValue(args[0])))); 119 } 120 121 void GenoObj::p_getconvert_ch(ExtValue *args, ExtValue *ret) 122 { 123 *ret = makeDynamicObjectAndDecRef(new Geno(getConverted(formatFromExtValue(args[0]), NULL, true))); 118 124 } 119 125 -
cpp/frams/vm/classes/genoobj.h
r516 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 … … 25 25 PARAMGETDEF(string); 26 26 PARAMPROCDEF(p_getconvert); 27 PARAMPROCDEF(p_getconvert_ch); 27 28 PARAMGETDEF(f0genotype); 28 29 PARAMPROCDEF(p_new);
Note: See TracChangeset
for help on using the changeset viewer.