Changeset 955


Ignore:
Timestamp:
06/25/20 00:34:29 (3 weeks ago)
Author:
Maciej Komosinski
Message:

Genetic format ID becomes a string (no longer limited to a single character)

Location:
cpp/frams
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/Makefile-SDK-files

    r928 r955  
    22
    33# ALL_DIRS is later expanded by the shell, no spaces/newlines allowed, or it breaks
    4 ALL_DIRS={common,PrintFloat,frams,frams/canvas,frams/config,common/loggers,frams/genetics,frams/genetics/f0,frams/genetics/f1,frams/genetics/f2,frams/genetics/f3,frams/genetics/f4,frams/genetics/f5,frams/genetics/f6,frams/genetics/f7,frams/genetics/f8,frams/genetics/f9,frams/genetics/fn,frams/genetics/fF,frams/genetics/fT,frams/genetics/fB,frams/genetics/fH,frams/genetics/fL,frams/model,frams/neuro,frams/neuro/impl,frams/param,frams/test,frams/util,frams/vm/classes,common/virtfile,frams/_demos,frams/model/geometry,frams/_demos/geometry,frams/model/similarity,frams/model/similarity/hungarian,frams/model/similarity/SVD}
     4ALL_DIRS={common,PrintFloat,frams,frams/canvas,frams/config,common/loggers,frams/genetics,frams/genetics/f0,frams/genetics/f1,frams/genetics/f2,frams/genetics/f3,frams/genetics/f4,frams/genetics/f5,frams/genetics/f6,frams/genetics/f7,frams/genetics/f8,frams/genetics/f9,frams/genetics/fn,frams/genetics/fF,frams/genetics/fT,frams/genetics/fB,frams/genetics/fH,frams/genetics/fL,frams/genetics/fS,frams/model,frams/neuro,frams/neuro/impl,frams/param,frams/test,frams/util,frams/vm/classes,common/virtfile,frams/_demos,frams/model/geometry,frams/_demos/geometry,frams/model/similarity,frams/model/similarity/hungarian,frams/model/similarity/SVD}
    55
    66GENMANF4=frams/genetics/f4/f4_oper.o
     
    1212GENMANFH=frams/genetics/fH/fH_oper.o frams/genetics/fH/fH_general.o
    1313GENMANFL=frams/genetics/fL/fL_oper.o frams/genetics/fL/fL_general.o frams/genetics/fL/fL_matheval.o
     14GENMANFS=frams/genetics/fS/fS_oper.o frams/genetics/fS/fS_general.o
    1415
    1516CONVF1=frams/genetics/f1/f1_conv.o frams/genetics/geneprops.o
     
    2122CONVFH=frams/genetics/fH/fH_conv.o frams/genetics/fH/fH_general.o frams/param/mutableparam.o
    2223CONVFL=frams/genetics/fL/fL_conv.o frams/genetics/fL/fL_general.o frams/genetics/fL/fL_matheval.o
     24CONVFS=frams/genetics/fS/fS_conv.o frams/genetics/fS/fS_general.o
    2325
    2426# $(sort - remove duplicates
    25 GENOCONV_SDK_OBJS=$(sort frams/genetics/defgenoconv.o frams/vm/classes/genoobj.o frams/model/autoname.o $(CONVF1) $(CONVF4) $(CONVF9) $(CONVFF) $(CONVFN) $(CONVFB) $(CONVFH) $(CONVFL))
    26 GENMAN_SDK_OBJS=$(GENMAN_COMMON_OBJS) $(GENMANF4) $(GENMANF9) $(GENMANFF) $(GENMANFT) $(GENMANFN) $(GENMANFB) $(GENMANFH) $(GENMANFL)
     27GENOCONV_SDK_OBJS=$(sort frams/genetics/defgenoconv.o frams/vm/classes/genoobj.o frams/model/autoname.o $(CONVF1) $(CONVF4) $(CONVF9) $(CONVFF) $(CONVFN) $(CONVFB) $(CONVFH) $(CONVFL) $(CONVFS))
     28GENMAN_SDK_OBJS=$(GENMAN_COMMON_OBJS) $(GENMANF4) $(GENMANF9) $(GENMANFF) $(GENMANFT) $(GENMANFN) $(GENMANFB) $(GENMANFH) $(GENMANFL) $(GENMANFS)
    2729GENOCONV_AND_GENMAN_SDK_OBJS=$(sort $(GENOCONV_SDK_OBJS) $(GENMAN_SDK_OBJS))
    2830
  • cpp/frams/_demos/f0_variants_test.cpp

    r720 r955  
    9595Geno g(gen);
    9696printf("\nSource genotype: '%s'\n",g.getGenes().c_str());
    97 printf("                  ( format %c %s)\n",
    98        g.getFormat(), g.getComment().c_str());
     97printf("                  ( format %s %s)\n",
     98       g.getFormat().c_str(), g.getComment().c_str());
    9999
    100100Model m(g);//.getConverted('0'));
  • cpp/frams/_demos/genoconv_test.cpp

    r739 r955  
    6666        {
    6767                name = "Test Converter #3";
    68                 in_format = 'z';
     68                in_format = "multiply";
    6969                out_format = '1';
    7070                mapsupport = 1;
     
    112112void printGen(Geno &g)
    113113{
    114         printf("Genotype:\n%s\nFormat: %c\nValid: %s\nComment: %s\n",
    115                 g.getGenes().c_str(), g.getFormat(), g.isValid() ? "yes" : "no", g.getComment().c_str());
    116 }
    117 
    118 static int goodWidthForFormat(int genotype_format)
    119 {
    120         return genotype_format == '0' ? 45 : 15; // more space for long f0 lines
     114        printf("Genotype:\n%s\nFormat: %s\nValid: %s\nComment: %s\n",
     115               g.getGenes().c_str(), g.getFormat().c_str(), g.isValid() ? "yes" : "no", g.getComment().c_str());
     116}
     117
     118static int goodWidthForFormat(const SString& genotype_format)
     119{
     120        return genotype_format == "0" ? 45 : 15; // more space for long f0 lines
    121121}
    122122
     
    154154        else
    155155                src = "X";
    156         char dst = (argc > 2) ? *argv[2] : '0';
     156        SString dst = (argc > 2) ? *argv[2] : '0';
    157157        bool using_checkpoints = (argc > 3) ? (strcmp(argv[3], "checkpoints") == 0) : false;
    158158
     
    162162        MultiMap m;
    163163        Geno g2 = g1.getConverted(dst, &m, using_checkpoints);
    164         printf("*** Converted to f%c:\n", dst);
     164        printf("*** Converted to f%s:\n", dst.c_str());
    165165        printGen(g2);
    166166
     
    168168        { // using Model with checkpoints
    169169                Model m1(g2, false, true);//true=using_checkpoints
    170                 printf("\nModel built from the converted f%c genotype has %d checkpoints\n", g2.getFormat(), m1.getCheckpointCount());
     170                printf("\nModel built from the converted f%s genotype has %d checkpoints\n", g2.getFormat().c_str(), m1.getCheckpointCount());
    171171                Model m2(g1, false, true);//true=using_checkpoints
    172                 printf("Model built from the source f%c genotype has %d checkpoints\n", g1.getFormat(), m2.getCheckpointCount());
     172                printf("Model built from the source f%s genotype has %d checkpoints\n", g1.getFormat().c_str(), m2.getCheckpointCount());
    173173                // accessing individual checkpoint models (if available)
    174174                if (m1.getCheckpointCount() > 0)
     
    196196
    197197                Model mod1(g1, 1);
    198                 printf("\nModel map for f%c genotype:\n", g1.getFormat());
     198                printf("\nModel map for f%s genotype:\n", g1.getFormat().c_str());
    199199                ModelDisplayMap dm1(mod1);
    200200                dm1.print(goodWidthForFormat(g1.getFormat()));
     
    203203                mod1combined.print();
    204204                Model mod2(g2, 1);
    205                 printf("\nModel map for f%c genotype:\n", g2.getFormat());
     205                printf("\nModel map for f%s genotype:\n", g2.getFormat().c_str());
    206206                ModelDisplayMap dm2(mod2);
    207207                dm2.print(goodWidthForFormat(g2.getFormat()));
  • cpp/frams/_demos/genomanipulation.cpp

    r896 r955  
    258258        if (gc) printf("found converter accepting f1: \"%s\"\n", gc->name);
    259259        SListTempl<GenoConverter*> found;
    260         Geno::getConverters()->findConverters(&found, -1, '0');
     260        Geno::getConverters()->findConverters(&found, Geno::UNKNOWN_FORMAT, '0');
    261261        printf("found %d converter(s) producing f0\n", found.size());
    262262}
     
    281281        Geno g(gen);
    282282        printf("\nSource genotype: '%s'\n", g.getGenes().c_str());
    283         printf("                  ( format %c %s)\n",
    284                 g.getFormat(), g.getComment().c_str());
     283        printf("                  ( format %s %s)\n",
     284                g.getFormat().c_str(), g.getComment().c_str());
    285285
    286286        Model m(g);//.getConverted('0'));
  • cpp/frams/_demos/genooper_test.cpp

    r534 r955  
    88void printGen(Geno &g)
    99{
    10         printf("Genotype: %s\nFormat: %c\nValid: %s\nComment: %s\n",
    11                 g.getGenes().c_str(), g.getFormat(), g.isValid() ? "yes" : "no", g.getComment().len() == 0 ? "(empty)" : g.getComment().c_str());
     10        printf("Genotype: %s\nFormat: %s\nValid: %s\nComment: %s\n",
     11                g.getGenes().c_str(), g.getFormat().c_str(), g.isValid() ? "yes" : "no", g.getComment().len() == 0 ? "(empty)" : g.getComment().c_str());
    1212}
    1313
     
    3030        Geno gsrc(src, -1, "First");
    3131        printGenAndTitle(gsrc, "source genotype (gsrc)");
    32         char format = gsrc.getFormat();
     32        SString format = gsrc.getFormat();
    3333
    3434        Geno gmut = genetics.genman.mutate(gsrc);
     
    4141        printGenAndTitle(gsimplest, "simplest");
    4242
    43         Geno ginvalid("IT'S REALLY WRONG", format);
     43        Geno ginvalid("IT'S REALLY WRONG", format.c_str());
    4444        printGenAndTitle(ginvalid, "invalid");
    4545
  • cpp/frams/_demos/multiline_f0_test.cpp

    r745 r955  
    2727Geno g(gen);
    2828printf("\nSource genotype: '%s'\n",g.getGenes().c_str());
    29 printf("                  ( format %c %s)\n",
    30        g.getFormat(), g.getComment().c_str());
     29printf("                  ( format %s %s)\n",
     30       g.getFormat().c_str(), g.getComment().c_str());
    3131
    3232Model m(g);//.getConverted('0'));
  • cpp/frams/genetics/f4/f4_general.cpp

    r896 r955  
    13041304        unsigned int len;
    13051305        // build in a SString, with initial size
    1306         SString out(strlen(buf) + 2000);
    1307         out = "";
     1306        SString out;
     1307        out.reserve(int(strlen(buf)) + 2000);
    13081308
    13091309        sprint(out);
  • cpp/frams/genetics/genman.cpp

    r896 r955  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    6868#ifdef USE_GENMAN_fL
    6969#include "fL/fL_oper.h"
     70#endif
     71#ifdef USE_GENMAN_fS
     72#include "fS/fS_oper.h"
    7073#endif
    7174
     
    177180        oper_fx_list.push_back(new Geno_fL);
    178181#endif
     182#ifdef USE_GENMAN_fS
     183        oper_fx_list.push_back(new GenoOper_fS);
     184#endif
    179185
    180186        seloper = new int[oper_fx_list.size()]; //may result in a little overhead if some of the operators on the oper_fx_list concern the same genetic format
     
    182188        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
    183189        {
    184                 if (operformats.find(oper_fx_list[i]->supported_format) != -1) continue;
     190                if (findOperFormatIndex(oper_fx_list[i]->supported_format) != -1) continue;
    185191                string type = string("~") + oper_fx_list[i]->name;
    186192                int dup = 0;
     
    188194                        if (oper_fx_list[i]->supported_format == oper_fx_list[j]->supported_format)
    189195                        {
    190                         type += "~";
    191                         type += oper_fx_list[j]->name;
    192                         dup++;
     196                                type += "~";
     197                                type += oper_fx_list[j]->name;
     198                                dup++;
    193199                        }
    194200                type = ssprintf("d 0 %d ", dup) + type;
    195                 string id = ssprintf("genoper_f%c", oper_fx_list[i]->supported_format);
    196                 string name = ssprintf("Operators for f%c", oper_fx_list[i]->supported_format);
     201                string id = ssprintf("genoper_f%s", oper_fx_list[i]->supported_format.c_str());
     202                string name = ssprintf("Operators for f%s", oper_fx_list[i]->supported_format.c_str());
    197203                seloper[selopercount] = 0;
    198                 operformats += oper_fx_list[i]->supported_format;
     204                operformats += &oper_fx_list[i]->supported_format;
    199205                //printf("%x %s %s %s\n",&seloper[selopercount],(const char*)id,(const char*)type,(const char*)name);
    200                 seloperpar.addProperty(&seloper[selopercount++], id.c_str(), type.c_str(), name.c_str(), "", PARAM_READONLY*(dup == 0));
     206                seloperpar.addProperty(&seloper[selopercount++], id.c_str(), type.c_str(), name.c_str(), "", PARAM_READONLY * (dup == 0));
    201207        }
    202208
     
    214220        for (unsigned int i = 0; i < oper_fx_list.size(); i++) delete oper_fx_list[i];
    215221        delete[] seloper;
     222}
     223
     224int GenMan::findOperFormatIndex(const SString& format)
     225{
     226        for (int i = 0; i < operformats.size(); i++)
     227                if (*operformats(i) == format)
     228                        return i;
     229        return -1;
    216230}
    217231
     
    265279Geno GenMan::validate(const Geno& geny)
    266280{
    267         char format = geny.getFormat();
     281        SString format = geny.getFormat();
    268282        GenoOperators *gf = getOper_f(format);
    269283        if (gf == NULL)
    270                 return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: Validate(): don't know how to handle genetic format %c", format));
     284                return Geno("", Geno::INVALID_FORMAT, "", SString::sprintf("GENOPER_NOOPER: Validate(): don't know how to handle genetic format %s", format.c_str()));
    271285        char *g2 = strdup(geny.getGenes().c_str()); //copy for validation
    272286        int res = gf->validate(g2, geny.getName().c_str());
     
    276290                return Geno(sg2, format, geny.getName(), geny.getComment());
    277291        else
    278                 return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: validate() for format %c returned invalid value", format));
     292                return Geno("", Geno::INVALID_FORMAT, "", SString::sprintf("GENOPER_NOOPER: validate() for format %s returned invalid value", format.c_str()));
    279293}
    280294
     
    283297        float chg; //how many changes
    284298        int method; //mutation method
    285         char format = g.getFormat();
     299        SString format = g.getFormat();
    286300        GenoOperators *gf = getOper_f(format);
    287301        if (gf == NULL)
    288                 return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: Mutate(): don't know how to handle genetic format %c", format));
     302                return Geno("", Geno::INVALID_FORMAT, "", SString::sprintf("GENOPER_NOOPER: Mutate(): don't know how to handle genetic format %s", format.c_str()));
    289303        Geno gv = g;
    290304        bool canvalidate = true;
    291305        if (testValidity(gv, canvalidate) > 0 && canvalidate == false)
    292                 return Geno("", -1, "", "GENOPER_OPFAIL: Mutate(): cannot validate invalid source genotype");
     306                return Geno("", Geno::INVALID_FORMAT, "", "GENOPER_OPFAIL: Mutate(): cannot validate invalid source genotype");
    293307        bool ok = false;
    294308        int pcount = count;
     
    307321                                if (res > 0 && canvalidate == false) invalid_m++; else
    308322                                {
    309                                 validated_m++; ok = true;
     323                                        validated_m++; ok = true;
    310324                                }
    311325                        if (ok) gv = G;
     
    316330                if (!ok && (count - pcount > GENMAN_REPEAT_FAILED))
    317331                {
    318                         logPrintf("GenMan", "Mutate", 2, "Tried " GENMAN_REPEAT_FAILED_STR "x and failed: %s", g.getGenes().c_str());
     332                        logPrintf("GenMan", "Mutate", LOG_WARN, "Tried " GENMAN_REPEAT_FAILED_STR "x and failed: %s", g.getGenes().c_str());
    319333                        return Geno("", -1, "", "GENOPER_OPFAIL: Mutate() tried " GENMAN_REPEAT_FAILED_STR "x and failed");
    320334                }
     
    332346Geno GenMan::crossOver(const Geno& g1, const Geno& g2)
    333347{
    334         char format = g1.getFormat();
    335         if (format != g2.getFormat()) return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: CrossOver(): does not work for parents with differing genetic formats (%c and %c)", format, g2.getFormat()));
     348        SString format = g1.getFormat();
     349        if (format != g2.getFormat()) return Geno("", Geno::INVALID_FORMAT, "", SString::sprintf("GENOPER_NOOPER: CrossOver(): does not work for parents with differing genetic formats (%s and %s)", format.c_str(), g2.getFormat().c_str()));
    336350        GenoOperators *gf = getOper_f(format);
    337351        if (gf == NULL)
    338                 return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: CrossOver(): no operators found for genetic format %c", format));
     352                return Geno("", Geno::INVALID_FORMAT, "", SString::sprintf("GENOPER_NOOPER: CrossOver(): no operators found for genetic format %s", format.c_str()));
    339353        Geno g1v = g1, g2v = g2;
    340354
     
    343357                bool canvalidate = true;
    344358                if (testValidity(g1v, canvalidate) > 0 && canvalidate == false)
    345                         return Geno("", -1, "", "GENOPER_OPFAIL: CrossOver(): cannot validate invalid source genotype #1");
     359                        return Geno("", Geno::INVALID_FORMAT, "", "GENOPER_OPFAIL: CrossOver(): cannot validate invalid source genotype #1");
    346360                canvalidate = true;
    347361                if (testValidity(g2v, canvalidate) > 0 && canvalidate == false)
    348                         return Geno("", -1, "", "GENOPER_OPFAIL: CrossOver(): cannot validate invalid source genotype #2");
     362                        return Geno("", Geno::INVALID_FORMAT, "", "GENOPER_OPFAIL: CrossOver(): cannot validate invalid source genotype #2");
    349363        }
    350364
     
    373387                                if (res > 0 && canvalidate == false) invalid_xo++; else
    374388                                {
    375                                 validated_xo++; ok = true;
     389                                        validated_xo++; ok = true;
    376390                                }
    377391                        if (ok) g1v = G;
     
    383397                if (!ok && (count - pcount > GENMAN_REPEAT_FAILED))
    384398                {
    385                         logPrintf("GenMan", "CrossOver", 2, "Tried " GENMAN_REPEAT_FAILED_STR "x and failed: %s and %s", g1.getGenes().c_str(), g2.getGenes().c_str());
    386                         return Geno("", -1, "", "GENOPER_OPFAIL: CrossOver() tried " GENMAN_REPEAT_FAILED_STR "x and failed");
     399                        logPrintf("GenMan", "CrossOver", LOG_WARN, "Tried " GENMAN_REPEAT_FAILED_STR "x and failed: %s and %s", g1.getGenes().c_str(), g2.getGenes().c_str());
     400                        return Geno("", Geno::INVALID_FORMAT, "", "GENOPER_OPFAIL: CrossOver() tried " GENMAN_REPEAT_FAILED_STR "x and failed");
    387401                }
    388402        }
     
    398412float GenMan::similarity(const Geno& g1, const Geno& g2)
    399413{
    400         char format = g1.getFormat();
     414        SString format = g1.getFormat();
    401415        if (format != g2.getFormat()) return GENOPER_NOOPER;
    402416        GenoOperators *gf = getOper_f(format);
     
    406420uint32_t GenMan::getStyle(const char *g, const Geno *G, int pos)
    407421{
    408         char format = G->getFormat();
     422        SString format = G->getFormat();
    409423        if (format == Geno::INVALID_FORMAT)
    410424                return GENSTYLE_RGBS(64, 64, 64, 0); // gray & "valid" (unknown format so we don't know what is valid and what is not)
     
    423437void GenMan::getFullStyle(const char *g, const Geno *G, uint32_t *styletab)
    424438{
    425         char format = G->getFormat();
     439        SString format = G->getFormat();
    426440        if (format == Geno::INVALID_FORMAT)
    427441        {
     
    438452                else if (!gf) styletab[pos] = GENSTYLE_CS(0, 0); //black & valid
    439453                else styletab[pos] = gf->style(geny.c_str(), posmapped);
    440                 //logPrintf("GenMan", "getFullStyle", 0, "%d  char='%c' (%d)  format=0x%08x", pos, g[pos], g[pos], styletab[pos]);
     454                //logPrintf("GenMan", "getFullStyle", LOG_INFO, "%d  char='%c' (%d)  format=0x%08x", pos, g[pos], g[pos], styletab[pos]);
    441455        }
    442456}
     
    473487                color = GENGETCOLOR(styletab[i]);
    474488                if ((i != 0 && (color != prevcolor))) html += "</font>";
    475                 if ((style&GENSTYLE_INVALID) != (prevstyle&GENSTYLE_INVALID))
    476                 {
    477                         html += "<"; if (!(style&GENSTYLE_INVALID)) html += "/"; html += "u>";
    478                 }
    479                 if ((style&GENSTYLE_BOLD) != (prevstyle&GENSTYLE_BOLD))
    480                 {
    481                         html += "<"; if (!(style&GENSTYLE_BOLD)) html += "/"; html += "b>";
    482                 }
    483                 if ((style&GENSTYLE_ITALIC) != (prevstyle&GENSTYLE_ITALIC))
    484                 {
    485                         html += "<"; if (!(style&GENSTYLE_ITALIC)) html += "/"; html += "i>";
     489                if ((style & GENSTYLE_INVALID) != (prevstyle & GENSTYLE_INVALID))
     490                {
     491                        html += "<"; if (!(style & GENSTYLE_INVALID)) html += "/"; html += "u>";
     492                }
     493                if ((style & GENSTYLE_BOLD) != (prevstyle & GENSTYLE_BOLD))
     494                {
     495                        html += "<"; if (!(style & GENSTYLE_BOLD)) html += "/"; html += "b>";
     496                }
     497                if ((style & GENSTYLE_ITALIC) != (prevstyle & GENSTYLE_ITALIC))
     498                {
     499                        html += "<"; if (!(style & GENSTYLE_ITALIC)) html += "/"; html += "i>";
    486500                }
    487501                if ((i == 0 || (color != prevcolor)))
     
    509523}
    510524
    511 Geno GenMan::getSimplest(char format)
     525Geno GenMan::getSimplest(const SString& format)
    512526{
    513527        GenoOperators *gf = getOper_f(format);
    514528        if (!gf) return Geno();
    515         string info = "The simplest genotype of format f"; info += format;
     529        string info = "The simplest genotype of format f"; info += format.c_str();
    516530        info += " for operators '"; info += gf->name; info += "'.";
    517531        return Geno(gf->getSimplest(), format, "Root", info.c_str());
     
    520534void GenMan::p_getsimplest(ExtValue *args, ExtValue *ret)
    521535{
    522         int format = GenoObj::formatFromExtValue(args[0]);
     536        SString format = GenoObj::formatFromExtValue(args[0]);
    523537        if (!getOper_f(format))
    524538                ret->setEmpty();
     
    527541}
    528542
    529 const char *GenMan::getOpName(char format)
     543const char *GenMan::getOpName(const SString& format)
    530544{
    531545        GenoOperators *gf = getOper_f(format);
     
    533547}
    534548
    535 GenoOperators* GenMan::getOper_f(char format)
    536 {
    537         int ind = operformats.find(format);
     549GenoOperators* GenMan::getOper_f(const SString& format)
     550{
     551        int ind = findOperFormatIndex(format);
    538552        if (ind == -1) return NULL;
    539553        int which_oper_of_format = seloper[ind];
     
    602616                }
    603617                //      if (oper_fx_list[i]->similarity("","")!=GENOPER_NOOPER) l+=" similarity";
    604                 logPrintf("GenMan", "Report", 0, "format f%c (%s):%s",
    605                         oper_fx_list[i]->supported_format, oper_fx_list[i]->name.c_str(), l.c_str());
     618                logPrintf("GenMan", "Report", LOG_INFO, "format f%s (%s):%s",
     619                        oper_fx_list[i]->supported_format.c_str(), oper_fx_list[i]->name.c_str(), l.c_str());
    606620        }
    607621}
  • cpp/frams/genetics/genman.h

    r779 r955  
    5252        string HTMLize(const char *g); //returns colored genotype in HTML.
    5353        string HTMLizeShort(const char *g); //returns colored genotype (abbreviated if needed) in HTML.
    54         Geno getSimplest(char format); ///<returns pointer to the simplest genotype of \e format or empty Geno()
    55         const char *getOpName(char format); ///<returns pointer to the active operator set for \e format
     54        Geno getSimplest(const SString& format); ///<returns pointer to the simplest genotype of \e format or empty Geno()
     55        const char *getOpName(const SString& format); ///<returns pointer to the active operator set for \e format
    5656        const vector<GenoOperators*>& GetOperators() const { return oper_fx_list; } ///<returns the list of available genetic operators
    5757private:
    5858        vector<GenoOperators*> oper_fx_list;
    5959        void saveLink(const string parent1, const string parent2, const string child, const float chg);
    60         GenoOperators* getOper_f(char format);
     60        GenoOperators* getOper_f(const SString& format);
    6161        string HTMLize(const char *g, bool shorten);
     62        int findOperFormatIndex(const SString& format);
    6263public:
    6364        vector<GenoLink> GenoLinkList;
     
    6869        int valid_m, valid_xo, validated_m, validated_xo, invalid_m, invalid_xo, failed_m, failed_xo;
    6970        double mutchg, xochg;
    70         SListTempl<char> operformats; //the list of supported_format, in the same order as in seloperpar
     71        SListTempl<SString*> operformats; //the list of supported_format, in the same order as in seloperpar (raw SString* taken from oper_fx_list, not owned by operformats)
    7172        int* seloper; //fields for seloperpar
    7273        Param localpar, localstats;
  • cpp/frams/genetics/geno.cpp

    r841 r955  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    2424}
    2525
    26 void Geno::init(const SString& genstring, char genformat, const SString& genname, const SString& comment)
     26const SString Geno::INVALID_FORMAT = "invalid";
     27const SString Geno::UNKNOWN_FORMAT = "";
     28
     29void Geno::init(const SString& genstring, const SString& genformat, const SString& genname, const SString& comment)
    2730{
    2831        refcount = 1;
     
    3538}
    3639
    37 void Geno::setGenesAndFormat(const SString& genstring, char genformat)
     40static SString trimAndValidateFormat(const SString& input) //the new requirement for genotype format name: no whitespace
     41{
     42        SString format = trim(input);
     43        if (format.len() == 0 || strContainsOneOf(format.c_str(), " \r\n\t"))
     44                return Geno::INVALID_FORMAT;
     45        return format;
     46}
     47
     48void Geno::setGenesAndFormat(const SString& genstring, const SString& in_genformat)
    3849{
    3950        mapinshift = 0;
    4051        mapoutshift = 0;
    4152        SString gencopy(genstring);
    42         if (genformat == -1)
     53        SString genformat = in_genformat;
     54        if (genformat == UNKNOWN_FORMAT)
    4355        { // unknown format
    44                 genformat = '1';
     56                genformat = "1";
    4557                if (genstring.charAt(0) == '/')
    4658                {
     
    4961                        {
    5062                        case '/':
    51                                 genformat = genstring.charAt(2);
    5263                                if ((end = genstring.indexOf('\n')) >= 0)
    5364                                {
     65                                        genformat = trimAndValidateFormat(genstring.substr(2, end - 2));
    5466                                        mapinshift = end + 1;
    5567                                        gencopy = genstring.substr(end + 1);
    5668                                        if ((end > 0) && (genstring[end - 1] == '\r')) end--;
    5769                                        error_end = end;
    58                                         if (end != 3) genformat = INVALID_FORMAT;
    5970                                }
    6071                                else
    6172                                {
    62                                         if (genstring.len() != 3) genformat = INVALID_FORMAT;
    63                                         gencopy = 0;
     73                                        genformat = trimAndValidateFormat(genstring.substr(2));
     74                                        gencopy = "";
    6475                                        mapinshift = genstring.len();
    6576                                }
    6677                                break;
    6778                        case '*':
    68                                 genformat = genstring.charAt(2);
    6979                                if ((end = genstring.indexOf("*/")) >= 0)
    7080                                {
     81                                        genformat = trimAndValidateFormat(genstring.substr(2, end - 2));
    7182                                        error_end = end + 2;
    72                                         if (end != 3) genformat = INVALID_FORMAT;
    7383                                        gencopy = genstring.substr(end + 2);
    7484                                        mapinshift = end + 2;
     
    7686                                else
    7787                                {
    78                                         if (genstring.len() != 5) genformat = INVALID_FORMAT;
    79                                         gencopy = 0;
     88                                        genformat = trimAndValidateFormat(genstring.substr(2));
     89                                        gencopy = "";
    8090                                        mapinshift = genstring.len();
    8191                                }
    8292                                break;
    8393                        }
    84                         if (!isalnum(genformat)) genformat = INVALID_FORMAT;
    8594                        if (genformat == INVALID_FORMAT)
    8695                        {
    8796                                SString cut;
    88                                 if (error_end<0) error_end = genstring.len();
     97                                if (error_end < 0) error_end = genstring.len();
    8998                                static const int MAX_ERROR = 20;
    90                                 if (error_end>MAX_ERROR)
     99                                if (error_end > MAX_ERROR)
    91100                                        cut = genstring.substr(0, MAX_ERROR) + "...";
    92101                                else
     
    113122}
    114123
     124Geno::Geno(const char *genstring, const char* genformat, const char *genname, const char *comment)
     125{
     126        init(SString(genstring), SString(genformat), SString(genname), SString(comment));
     127}
     128
    115129Geno::Geno(const char *genstring, char genformat, const char *genname, const char *comment)
    116130{
    117         init(SString(genstring), genformat, SString(genname), SString(comment));
    118 }
    119 
    120 Geno::Geno(const SString& genstring, char genformat, const SString& genname, const SString& comment)
     131        SString genformat_string;
     132        if (genformat > 0)
     133                genformat_string = SString(&genformat, 1);
     134        init(genstring, genformat_string, genname, comment);
     135}
     136
     137Geno::Geno(const SString& genstring, const SString& genformat, const SString& genname, const SString& comment)
    121138{
    122139        init(genstring, genformat, genname, comment);
     
    148165Geno::Geno(const SString& src)
    149166{
    150         init(src, -1, SString::empty(), SString::empty());
     167        init(src, UNKNOWN_FORMAT, SString::empty(), SString::empty());
    151168}
    152169
     
    161178{
    162179        freeF0();
    163         init(g, -1, SString::empty(), SString::empty());
     180        init(g, UNKNOWN_FORMAT, SString::empty(), SString::empty());
    164181}
    165182
     
    177194{
    178195        SString out;
    179         if (format != '1')
     196        if (format != "1")
    180197        {
    181198                if (multiline)
     
    183200                else
    184201                        out += "/*";
    185                 if (format == 0)
    186                         out += "invalid";
    187                 else
    188                         out += format;
     202                out += format;
    189203                if (multiline)
    190204                        out += "\n";
     
    213227SString Geno::getGenes(void) const { return gen; }
    214228SString Geno::getName(void) const { return name; }
    215 char Geno::getFormat(void) const { return format; }
     229SString Geno::getFormat(void) const { return format; }
    216230SString Geno::getComment(void) const { return txt; }
    217231
    218232int ModelGenoValidator::testGenoValidity(Geno& g)
    219233{
    220         if (g.getFormat() == '0')
     234        if (g.getFormat() == "0")
    221235        {
    222236                Model mod(g);
     
    226240        {
    227241                bool converter_missing;
    228                 Geno f0geno = g.getConverted('0', NULL, false, &converter_missing);
     242                Geno f0geno = g.getConverted("0", NULL, false, &converter_missing);
    229243                if (converter_missing)
    230244                        return -1;//no result
     
    243257#ifdef WARN_VALIDATION_INCONSISTENCY
    244258                vector<int> results;
    245                 int first_result=-1;
     259                int first_result = -1;
    246260                FOREACH(GenoValidator*, v, (*vals))
    247261                {
    248                         int r=v->testGenoValidity(*this);
    249                         if (first_result<0) first_result=r;
     262                        int r = v->testGenoValidity(*this);
     263                        if (first_result < 0) first_result = r;
    250264                        results.push_back(r);
    251265                }
    252                 int N=vals->size();
    253                 for(int i=1;i<N;i++)
    254                         if (results[i]!=results[0])
     266                int N = vals->size();
     267                for (int i = 1; i < N; i++)
     268                        if (results[i] != results[0])
    255269                        {
    256                         SString txt="Inconsistent validation results";
    257                         for(int i=0;i<N;i++)
    258                                 txt+=SString::sprintf(" %d",results[i]);
    259                         txt+=" for genotype '";
    260                         txt+=getGene();
    261                         txt+="'";
    262                         logPrintf("Geno","validate",LOG_WARN,txt.c_str());
    263                         break;
     270                                SString txt = "Inconsistent validation results";
     271                                for (int i = 0; i < N; i++)
     272                                        txt += SString::sprintf(" %d", results[i]);
     273                                txt += " for genotype '";
     274                                txt += getGene();
     275                                txt += "'";
     276                                logPrintf("Geno", "validate", LOG_WARN, txt.c_str());
     277                                break;
    264278                        }
    265                 isvalid=first_result;
    266                 if (isvalid>=0)
     279                isvalid = first_result;
     280                if (isvalid >= 0)
    267281                        return;
    268282#else
     
    273287        }
    274288        isvalid = 0;
    275         logPrintf("Geno", "validate", LOG_WARN, "Wrong configuration? No genotype validators defined for genetic format 'f%c'.", format);
     289        logPrintf("Geno", "validate", LOG_WARN, "Wrong configuration? No genotype validators defined for genetic format 'f%s'.", format.c_str());
    276290}
    277291
     
    295309}
    296310
    297 Geno Geno::getConverted(char otherformat, MultiMap *m, bool using_checkpoints, bool *converter_missing)
     311Geno Geno::getConverted(SString otherformat, MultiMap *m, bool using_checkpoints, bool *converter_missing)
    298312{
    299313        if (otherformat == getFormat()) { if (converter_missing) *converter_missing = false; return *this; }
     
    302316        if (converters)
    303317        {
    304                 if ((otherformat == '0') && (!m) && (!using_checkpoints))
     318                if ((otherformat == "0") && (!m) && (!using_checkpoints))
    305319                {
    306320                        if (!f0gen)
     
    317331#endif
    318332        if (converter_missing) *converter_missing = true;
    319         return (otherformat == getFormat()) ? *this : Geno(0, 0, 0, "GenConvManager not available");
     333        return (otherformat == getFormat()) ? *this : Geno("", "", "", "GenConvManager not available");
    320334}
    321335
  • cpp/frams/genetics/geno.h

    r732 r955  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    3434        SString gen;
    3535        SString name;
    36         char format;
     36        SString format;
    3737        SString txt;
    3838        int isvalid; ///< <0 -> unknown   >=0 -> value for "isValid"
     
    4444        int multiline;
    4545
    46         void init(const SString& genstring, char genformat, const SString& genname, const SString& comment);
     46        void init(const SString& genstring, const SString& genformat, const SString& genname, const SString& comment);
    4747        void validate(void);
    4848
     
    5555
    5656public:
    57         static const char INVALID_FORMAT = '!';
     57        static const SString INVALID_FORMAT;
     58        static const SString UNKNOWN_FORMAT;
    5859        typedef SListTempl<GenoValidator*> Validators;
    5960
     
    6263        /// @param genformat genotype format
    6364        /// @param comment information about genotype (for genetic operators and "history")
    64         Geno(const char *genstring = 0, char genformat = -1, const char *genname = 0, const char *comment = 0);
     65        Geno(const char *genstring = 0, const char* genformat = 0, const char *genname = 0, const char *comment = 0);
     66
     67        Geno(const char *genstring, char genformat, const char *genname = 0, const char *comment = 0); //old style Geno, accepts char genoformat
    6568
    6669        /// create a genotype object from primitives
     
    6972        /// @param name genotype name, new name will generated if needed
    7073        /// @param comment information about genotype (for genetic operators and "history")
    71         Geno(const SString& genstring, char genformat, const SString& genname, const SString& comment);
     74        Geno(const SString& genstring, const SString& genformat, const SString& genname, const SString& comment);
    7275
    7376        /// create object from full string, containing optional format and comment information
     
    8992        void setString(const SString& genewithcomments);
    9093
    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);
     94        /** @param genformat="" -> detect genotype format from genstring comment (like the constructor does), else specify the valid format in genformat and pure genes in genstring. */
     95        void setGenesAndFormat(const SString& genstring, const SString& genformat = UNKNOWN_FORMAT);
    9396        /** g must be pure genes, without format. For the standard behavior use setGenesAndFormat() */
    9497        void setGenesAssumingSameFormat(const SString& g);
     
    97100        SString getName(void) const;
    98101        void setName(const SString&);
    99         char getFormat(void) const;
     102        SString getFormat(void) const;
    100103
    101104        SString getComment(void) const;
     
    107110        /// make converted version of the genotype.
    108111        /// @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 using_checkpoints = false, bool *converter_missing = NULL);
     112        Geno getConverted(SString otherformat, MultiMap *m = 0, bool using_checkpoints = false, bool *converter_missing = NULL);
    110113
    111114        /// @return -1 = before first char in the string
  • cpp/frams/genetics/genoconv.cpp

    r841 r955  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    5757                pe->flags = 0;
    5858                std::string descr = "f";
    59                 descr += gk->in_format;
     59                descr += gk->in_format.c_str();
    6060                descr += " --> f";
    61                 descr += gk->out_format;
     61                descr += gk->out_format.c_str();
    6262                descr += "  :  ";
    6363                descr += gk->name;
     
    101101}
    102102
    103 GenoConverter *GenoConvManager::findConverters(SListTempl<GenoConverter*>* result, char in, char out, int enabled, char* name)
     103GenoConverter *GenoConvManager::findConverters(SListTempl<GenoConverter*>* result, const SString& in, const SString& out, int enabled, char* name)
    104104{
    105105        GenoConverter *gk, *retval = 0;
     
    107107        for (; gk = (GenoConverter*)converters(i); i++)
    108108        {
    109                 if ((in != -1) && (in != gk->in_format)) continue;
    110                 if ((out != -1) && (out != gk->out_format)) continue;
     109                if ((in != Geno::UNKNOWN_FORMAT) && (in != gk->in_format)) continue;
     110                if ((out != Geno::UNKNOWN_FORMAT) && (out != gk->out_format)) continue;
    111111                if ((enabled != -1) && (enabled != gk->enabled)) continue;
    112112                if ((name) && (strcmp(name, gk->name))) continue;
     
    123123/// (can be NULL if you don't need this information)
    124124
    125 char *GenoConvManager::getPath(char in, char out, char *path, int maxlen, int *mapavailable)
     125GenoConverter **GenoConvManager::getPath(const SString& in, const SString& out, GenoConverter **path, int maxlen, int *mapavailable)
    126126{
    127127        if (!maxlen) return 0;
     
    132132                if ((gk->enabled) && (gk->in_format == in))
    133133                {
    134                         *path = (char)i;
     134                        *path = gk;
    135135                        if (gk->out_format == out)
    136136                        {
     
    142142                        {
    143143                                int mapavail;
    144                                 char *ret = getPath(gk->out_format, out, path + 1, maxlen - 1, &mapavail);
     144                                GenoConverter **ret = getPath(gk->out_format, out, path + 1, maxlen - 1, &mapavail);
    145145                                if (ret)
    146146                                {
     
    155155}
    156156
    157 char *GenoConvManager::getFormatPath(char in, char out, char *path, int maxlen, int *mapavailable)
    158 {
    159         char *ret = getPath(in, out, path, maxlen, mapavailable);
    160         if (ret)
    161         {
    162                 for (char*t = path; t <= ret; t++)
    163                         *t = ((GenoConverter*)converters(*t))->out_format;
    164         }
    165         return ret;
    166 }
    167 
    168 Geno GenoConvManager::convert(Geno &in, char format, MultiMap *map, bool using_checkpoints, bool *converter_missing)
     157Geno GenoConvManager::convert(Geno &in, SString format, MultiMap *map, bool using_checkpoints, bool *converter_missing)
    169158{
    170159        if (in.getFormat() == format) { if (converter_missing) *converter_missing = false; return in; }
    171         char path[10];
     160        GenoConverter *path[10];
    172161        int dep;
    173         char *ret;
    174         if (in.isInvalid()) { if (converter_missing) *converter_missing = false; return Geno("", 0, "", "invalid genotype cannot be converted"); }
     162        GenoConverter **ret;
     163        if (in.isInvalid()) { if (converter_missing) *converter_missing = false; return Geno("", Geno::INVALID_FORMAT, "", "invalid genotype cannot be converted"); }
    175164        int mapavail;
    176165        for (dep = 1; dep < (int)sizeof(path); dep++) //iterative deepening
    177166                if (ret = getPath(in.getFormat(), format, path, dep, &mapavail)) break;
    178         if (!ret) { if (converter_missing) *converter_missing = true; return Geno("", 0, "", "converter not found"); }
     167        if (!ret) { if (converter_missing) *converter_missing = true; return Geno("", Geno::INVALID_FORMAT, "", "converter not found"); }
    179168        if (converter_missing) *converter_missing = false;
    180169        if (!map) mapavail = 0;
    181         char *t = path;
     170        GenoConverter **t = path;
    182171        SString tmp;
    183172        tmp = in.getGenes();
     
    186175        for (; t <= ret; t++)
    187176        {
    188                 GenoConverter *gk = (GenoConverter*)converters(*t);
     177                GenoConverter *gk = *t;
    189178                tmp = gk->convert(tmp, mapavail ? &tmpmap : 0, using_checkpoints);
    190179                if (!tmp.len())
    191180                {
    192                         string t = ssprintf("f%c->f%c conversion failed (%s)", gk->in_format, gk->out_format, gk->name);
    193                         return Geno(0, 0, 0, t.c_str());
     181                        string t = ssprintf("f%s->f%s conversion failed (%s)", gk->in_format.c_str(), gk->out_format.c_str(), gk->name);
     182                        return Geno("", Geno::INVALID_FORMAT, "", t.c_str());
    194183                }
    195184                if (mapavail)
  • cpp/frams/genetics/genoconv.h

    r783 r955  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    4343public:
    4444        const char *name;       //< converter name (short)
    45         char in_format,         //< input format, eg. '1'
    46                 out_format;     //< output format, eg. '0'
     45        SString in_format,      //< input format, eg. "1"
     46                out_format;     //< output format, eg. "0"
    4747        paInt enabled;  //< don't touch this! (used by configuration module)
    4848        paInt mapsupport; //< set to 1 if your converter supports genotype mapping
     
    5656        virtual ~GenoConverter() {}
    5757        /// Don't forget to set public fields in your constructor
    58         GenoConverter() :name(""), in_format(-1), out_format('0'), enabled(1), mapsupport(0) {}
     58        GenoConverter() :name(""), in_format(Geno::UNKNOWN_FORMAT), out_format("0"), enabled(1), mapsupport(0) {}
    5959};
    6060
     
    7777        /// make a genotype in other format. genotype will be invalid
    7878        /// if GenoConvManager cannot convert it.
    79         Geno convert(Geno &in, char format, MultiMap *map = 0, bool using_checkpoints = false, bool *converter_missing = NULL);
     79        Geno convert(Geno &in, SString format, MultiMap *map = 0, bool using_checkpoints = false, bool *converter_missing = NULL);
    8080        /// register GenoConverter, the added object will be automatically deleted when GenoConvManager is destructed (call removeConverter() if this is not desirable)
    8181        void addConverter(GenoConverter *conv);
     
    8383        void removeConverter(GenoConverter *conv);
    8484
    85         char *getPath(char in, char out, char *path, int maxlen, int *mapavailable = 0);
    86         char *getFormatPath(char in, char out, char *path, int maxlen, int *mapavailable = 0);
     85        GenoConverter **getPath(const SString& in, const SString& out, GenoConverter **path, int maxlen, int *mapavailable = 0);
    8786        /// returns the list of converters meeting the specified criteria
    8887        /// pass result=0 if you only need one result (by return value)
    8988        /// default criteria values mean "don't care", pass anything else to narrow your search
    90         GenoConverter *findConverters(SListTempl<GenoConverter*>* result = 0, char in = -1, char out = -1, int enabled = -1, char* name = 0);
     89        GenoConverter *findConverters(SListTempl<GenoConverter*>* result = 0, const SString& in = Geno::UNKNOWN_FORMAT, const SString& out = Geno::UNKNOWN_FORMAT, int enabled = -1, char* name = 0);
    9190};
    9291
  • cpp/frams/genetics/genooperators.cpp

    r935 r955  
    7676}
    7777
    78 int GenoOperators::selectRandomProperty(Neuro *n)
     78int GenoOperators::selectRandomNeuProperty(Neuro *n)
    7979{
    8080        int neuext = n->extraProperties().getPropCount(),
  • cpp/frams/genetics/genooperators.h

    r935 r955  
    8181public:
    8282        Param par;
    83         char supported_format; ///<genotype format which is supported by this class ('6' for GenoOper_f6, 'F' for GenoOper_fF, etc.). Must be initialized in constructor
    84         string name; ///<name of this set of genetic operators
     83        SString supported_format; ///<genotype format which is supported by this class ("6" for GenoOper_f6, "Latent" for GenoOper_fLatent, etc.). Must be initialized in constructor.
     84        string name; ///<short human-friendly name of this genetic representation/set of genetic operators
    8585        const char **mutation_method_names; ///<array of names for mutation methods. If initialized (by new const char*[]), must have entries for each method index returned by mutate(geno,chg,METHOD).  If initialized, it is automatically freed by this destructor.
    86         GenoOperators() : par(empty_paramtab) { supported_format = 'x'; name = "Default"; mutation_method_names = NULL; setDefaults(); }
     86        GenoOperators() : par(empty_paramtab) { supported_format = "x"; name = "Default"; mutation_method_names = NULL; setDefaults(); }
    8787
    8888        /**Used to perform initializations of Param parameters that are not handled by the Param itself
     
    182182        static int roulette(const double *probtab, const int count);    ///<returns random index according to probabilities in the \e probtab table or -1 if all probs are zero. \e count is the number of elements in \e probtab.
    183183        static bool getMinMaxDef(ParamInterface *p, int propindex, double &mn, double &mx, double &def); ///<perhaps a more useful (higher-level) way to obtain min/max/def info for integer and double properties. Returns true if min/max/def was really available (otherwise it is just invented).
    184         static int selectRandomProperty(Neuro* n); ///<selects random property (either 0-based extraproperty of Neuro or 100-based property of its NeuroClass). -1 if Neuro has no properties.
     184        static int selectRandomNeuProperty(Neuro* n); ///<selects random property (either 0-based extraproperty of Neuro or 100-based property of its NeuroClass). -1 if Neuro has no properties.
    185185        static double mutateNeuProperty(double current, Neuro *n, int propindex); ///<returns value \e current mutated for the property \e propindex of NeuroClass \e nc or for extraproperty (\e propindex - 100) of Neuro. Neuro is used as read-only. Give \e propindex == -1 to mutate connection weight (\e nc is then ignored).
    186186        static bool mutatePropertyNaive(ParamInterface &p, int propindex); ///<creep-mutate selected property. Returns true when success. mutateProperty() should be used instead of this function.
  • cpp/frams/model/model.cpp

    r952 r955  
    333333        f0warnposition = -1;
    334334        MultiMap *convmap = autobuildmaps ? new MultiMap() : NULL;
    335         f0geno = (geno.getFormat() == '0') ? geno : geno.getConverted('0', convmap, using_checkpoints);
     335        f0geno = (geno.getFormat() == "0") ? geno : geno.getConverted("0", convmap, using_checkpoints);
    336336        f0genoknown = 1;
    337337        if (f0geno.isInvalid())
     
    437437        if ((buildstatus != valid) && (buildstatus != building))
    438438        {
    439                 g = Geno(0, 0, 0, "invalid model");
     439                g = Geno("", Geno::INVALID_FORMAT, "", "invalid model");
    440440                return;
    441441        }
  • cpp/frams/util/sstring-simple.cpp

    r897 r955  
    2222}
    2323
    24 SString::SString(int x)
    25 {
    26         initEmpty();
    27         if (x)
    28                 ensureSize(x + 1);
    29 }
    30 
    3124SString::SString(const char *t, int t_len)
    3225{
     
    4639        txt = from.txt; size = from.size; used = from.used;
    4740        from.txt = NULL; from.size = 0; from.used = 0;
     41}
     42
     43SString::SString(char in)
     44{
     45        initEmpty();
     46        append(&in, 1);
    4847}
    4948
     
    117116SString SString::operator+(const SString& s) const
    118117{
    119         SString ret(len() + s.len());
     118        SString ret;
     119        ret.reserve(len() + s.len());
    120120        ret = *this;
    121121        ret += s;
  • cpp/frams/util/sstring-simple.h

    r793 r955  
    2727        SString(); ///< make an empty string
    2828        SString(const char*t, int t_len = -1); ///< make a string from char*
    29         SString(int x); ///< string with initial buffer allocated for x characters
     29        SString(int x) = delete; ///< disallow the former 'int' constructor (so the new 'char' version is not used through implicit conversion)
    3030        SString(const SString& from); ///< duplicate string
    3131        SString(SString&& from);///< move
     32        SString(char in);
    3233        ~SString();
    3334
    3435        void copyFrom(const char* ch, int chlen = -1); ///< copy string, length of -1 == unknown
    35 
     36       
    3637        void* operator new(size_t s, void* mem){ return mem; }
    3738#ifdef _MSC_VER
     
    4344        int len() const { return used; } ///< get string length
    4445        void shrink(); ///< free unnecessary buffer
     46        void reserve(int needed) { ensureSize(needed); } ///< like in std::string
    4547
    4648        /// after this call, you can modify sstring directly.
  • cpp/frams/util/sstring.cpp

    r897 r955  
    127127}
    128128
    129 SString::SString(int x)
    130 {
    131         buf = new SBuf(x);
    132 }
    133 
    134129SString::SString(const char *t, int t_len)
    135130{
     
    157152                REF_UNLOCK;
    158153        }
     154}
     155
     156SString::SString(char in)
     157{
     158        initEmpty();
     159        copyFrom(&in, 1);
    159160}
    160161
  • cpp/frams/util/sstring.h

    r889 r955  
    7070        SString(); ///< make an empty string
    7171        SString(const char*t, int t_len = -1); ///< make a string from char*
    72         SString(int x); ///< string with initial buffer size
     72        SString(int x) = delete; ///< disallow the former 'int' constructor (so the new 'char' version is not used through implicit conversion)
    7373        SString(const SString& from); ///< duplicate string
    7474        SString(SString&& from); ///< move
     75        SString(char in);
    7576        ~SString();
    7677
     
    8687        int len() const { return buf->used; } ///< get string length
    8788        void shrink(); ///< free unnecessary buffer
     89        void reserve(int needed) { ensureSize(needed); } ///< like in std::string
    8890
    8991        /// after this call, you can modify sstring directly.
  • cpp/frams/vm/classes/genoobj.cpp

    r732 r955  
    8686void GenoObj::get_format(ExtValue *ret)
    8787{
    88         char format_as_string[2] = { getFormat(), 0 };
    89         ret->setString(format_as_string);
     88        ret->setString(getFormat());
    9089}
    9190
     
    101100}
    102101
    103 char GenoObj::formatFromExtValue(ExtValue& v)
     102SString GenoObj::formatFromExtValue(ExtValue& v)
    104103{
    105104        if (v.getType() == TInt)
    106                 return v.getInt();
     105        {
     106                char ch = v.getInt();
     107                return SString(&ch,1);
     108        }
    107109        if (v.getType() == TString)
    108110        {
    109                 SString s = v.getString();
    110                 if (s.len() == 1)
    111                         return s.charAt(0);
     111                return v.getString();
    112112        }
    113113        return Geno::INVALID_FORMAT;
     
    198198                SString n = vec->get(1) ? vec->get(1)->getString() : SString::empty();
    199199                SString c = vec->get(2) ? vec->get(2)->getString() : SString::empty();
    200                 *ret = makeDynamicObjectAndDecRef(new Geno(g, -1, n, c));
     200                *ret = makeDynamicObjectAndDecRef(new Geno(g, Geno::UNKNOWN_FORMAT, n, c));
    201201        }
    202202        else
  • cpp/frams/vm/classes/genoobj.h

    r732 r955  
    3939        static Geno* fromObject(const ExtValue& v, bool warn = true);
    4040        static ParamInterface* getInterface();
    41         static char formatFromExtValue(ExtValue& v);
     41        static SString formatFromExtValue(ExtValue& v);
    4242
    4343        static Param& getStaticParam();
  • cpp/frams/vm/framscript.l

    r950 r955  
    117117{
    118118int len=src.len();
    119 SString ret((len*11)/10+10);
     119SString ret;
     120ret.reserve((len*11)/10+10);
    120121const char*t=src.c_str();
    121122while(len>0)
  • cpp/frams/vm/framscript.y

    r863 r955  
    15141514SString s=val.getString();
    15151515int len=s.len();
    1516 SString ret((len*11)/10+10);
     1516SString ret;
     1517ret.reserve((len*11)/10+10);
    15171518ret+='\"';
    15181519const char*t=s.c_str();
Note: See TracChangeset for help on using the changeset viewer.