Changeset 732 for cpp/frams/genetics
- Timestamp:
- 02/15/18 00:42:07 (7 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note: See TracChangeset
for help on using the changeset viewer.