Changeset 732 for cpp/frams/genetics


Ignore:
Timestamp:
02/15/18 00:42:07 (2 years ago)
Author:
Maciej Komosinski
Message:

Added support for "checkpoints" (intermediate phases of development of the Model when converting between genetic encodings). See Model.checkpoint() and conv_f1.cpp for an example.

Location:
cpp/frams/genetics
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f1/conv_f1.cpp

    r726 r732  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2017  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1414
    1515F1Props stdprops = { 1, 0, 1, 0.4, 0.25, 0.25, 0.25, 0.25, 0.0, 1.0, 1.0, 1,
    16         0.2, 0.5, 0.5, 0.5 };
     160.2, 0.5, 0.5, 0.5 };
    1717
    1818class Builder
     
    106106
    107107/** main conversion function - with conversion map support */
    108 SString GenoConv_f1::convert(SString &i, MultiMap *map)
     108SString GenoConv_f1::convert(SString &i, MultiMap *map, bool using_checkpoints)
    109109{
    110110        const char* g = i.c_str();
    111111        Builder builder(g, map ? 1 : 0);
    112         builder.model.open();
     112        builder.model.open(using_checkpoints);
    113113        builder.grow(-1, g, Pt3D_0, stdprops, -1); // uses Model::addFromString() to create model elements
    114114        if (builder.invalid) return SString();
     
    242242
    243243                        if (c.muscle_reset_range) c.muscle_bend_range = 1.0; else c.muscle_reset_range = true;
     244                        model.checkpoint();
    244245                        grow(part2, g + 1, Pt3D_0, c, branching_part);
    245246                        return;
  • cpp/frams/genetics/f1/conv_f1.h

    r671 r732  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2017  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    6969                mapsupport = 1;
    7070        }
    71         SString convert(SString &i, MultiMap *map);
     71        SString convert(SString &i, MultiMap *map, bool using_checkpoints);
    7272        ~GenoConv_f1() {}
    7373};
  • cpp/frams/genetics/geno.cpp

    r534 r732  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    3232        name = genname;
    3333        txt = comment;
    34         setGenesAndFormat(genstring,genformat);
     34        setGenesAndFormat(genstring, genformat);
    3535}
    3636
     
    5454                                        mapinshift = end + 1;
    5555                                        gencopy = genstring.substr(end + 1);
    56                                         if ((end>0) && (genstring[end-1]=='\r')) end--;
     56                                        if ((end > 0) && (genstring[end - 1] == '\r')) end--;
    5757                                        error_end = end;
    5858                                        if (end != 3) genformat = INVALID_FORMAT;
     
    8282                                break;
    8383                        }
    84                         if (!isalnum(genformat)) genformat=INVALID_FORMAT;
     84                        if (!isalnum(genformat)) genformat = INVALID_FORMAT;
    8585                        if (genformat == INVALID_FORMAT)
    8686                        {
     
    9393                                        cut = genstring.substr(0, error_end);
    9494                                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); }
    9696                                sstringQuote(cut);
    9797                                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() : "");
     
    226226        {
    227227                bool converter_missing;
    228                 Geno f0geno = g.getConverted('0', NULL, &converter_missing);
     228                Geno f0geno = g.getConverted('0', NULL, false, &converter_missing);
    229229                if (converter_missing)
    230230                        return -1;//no result
     
    295295}
    296296
    297 Geno Geno::getConverted(char otherformat, MultiMap *m, bool *converter_missing)
     297Geno Geno::getConverted(char otherformat, MultiMap *m, bool using_checkpoints, bool *converter_missing)
    298298{
    299299        if (otherformat == getFormat()) { if (converter_missing) *converter_missing = false; return *this; }
     
    302302        if (converters)
    303303        {
    304                 if ((otherformat == '0') && (!m))
     304                if ((otherformat == '0') && (!m) && (!using_checkpoints))
    305305                {
    306306                        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));
    308308                        else
    309309                        {
     
    313313                }
    314314                else
    315                         return converters->convert(*this, otherformat, m, converter_missing);
     315                        return converters->convert(*this, otherformat, m, using_checkpoints, converter_missing);
    316316        }
    317317#endif
  • cpp/frams/genetics/geno.h

    r534 r732  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2016  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    9090
    9191        /** @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);
    9393        /** g must be pure genes, without format. For the standard behavior use setGenesAndFormat() */
    9494        void setGenesAssumingSameFormat(const SString& g);
     
    107107        /// make converted version of the genotype.
    108108        /// @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);
    110110
    111111        /// @return -1 = before first char in the string
  • cpp/frams/genetics/genoconv.cpp

    r534 r732  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    8181
    8282GenoConvManager::GenoConvManager()
    83 :param(this)
     83        :param(this)
    8484{
    8585}
     
    166166}
    167167
    168 Geno GenoConvManager::convert(Geno &in, char format, MultiMap *map, bool *converter_missing)
     168Geno GenoConvManager::convert(Geno &in, char format, MultiMap *map, bool using_checkpoints, bool *converter_missing)
    169169{
    170170        if (in.getFormat() == format) { if (converter_missing) *converter_missing = false; return in; }
     
    187187        {
    188188                GenoConverter *gk = (GenoConverter*)converters(*t);
    189                 tmp = gk->convert(tmp, mapavail ? &tmpmap : 0);
     189                tmp = gk->convert(tmp, mapavail ? &tmpmap : 0, using_checkpoints);
    190190                if (!tmp.len())
    191191                {
    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);
    193193                        return Geno(0, 0, 0, t.c_str());
    194194                }
  • cpp/frams/genetics/genoconv.h

    r513 r732  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    5353        /// Any other return value is assumed to be output genotype.
    5454        /// @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(); }
    5656
    5757        virtual ~GenoConverter() {}
     
    7878        /// make a genotype in other format. genotype will be invalid
    7979        /// 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);
    8181        /// register GenoConverter, the added object will be automatically deleted when GenoConvManager is destructed (call removeConverter() if this is not desirable)
    8282        void addConverter(GenoConverter *conv);
Note: See TracChangeset for help on using the changeset viewer.