Changeset 988


Ignore:
Timestamp:
07/09/20 00:13:20 (4 years ago)
Author:
Maciej Komosinski
Message:

Building a Model from Geno now fails when Model.shape is incompatible with Geno.format; renamed enum constants for genetic formats: xxx_FORMAT => FORMAT_xxx

Location:
cpp/frams
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/genman.cpp

    r977 r988  
    289289        GenoOperators *gf = getOper_f(format);
    290290        if (gf == NULL)
    291                 return Geno("", Geno::INVALID_FORMAT, "", SString::sprintf("GENOPER_NOOPER: Validate(): don't know how to handle genetic format %s", format.c_str()));
     291                return Geno("", Geno::FORMAT_INVALID, "", SString::sprintf("GENOPER_NOOPER: Validate(): don't know how to handle genetic format %s", format.c_str()));
    292292        char *g2 = strdup(geny.getGenes().c_str()); //copy for validation
    293293        int res = gf->validate(g2, geny.getName().c_str());
     
    297297                return Geno(sg2, format, geny.getName(), geny.getComment());
    298298        else
    299                 return Geno("", Geno::INVALID_FORMAT, "", SString::sprintf("GENOPER_NOOPER: validate() for format %s returned invalid value", format.c_str()));
     299                return Geno("", Geno::FORMAT_INVALID, "", SString::sprintf("GENOPER_NOOPER: validate() for format %s returned invalid value", format.c_str()));
    300300}
    301301
     
    307307        GenoOperators *gf = getOper_f(format);
    308308        if (gf == NULL)
    309                 return Geno("", Geno::INVALID_FORMAT, "", SString::sprintf("GENOPER_NOOPER: Mutate(): don't know how to handle genetic format %s", format.c_str()));
     309                return Geno("", Geno::FORMAT_INVALID, "", SString::sprintf("GENOPER_NOOPER: Mutate(): don't know how to handle genetic format %s", format.c_str()));
    310310        Geno gv = g;
    311311        bool canvalidate = true;
    312312        if (testValidity(gv, canvalidate) > 0 && canvalidate == false)
    313                 return Geno("", Geno::INVALID_FORMAT, "", "GENOPER_OPFAIL: Mutate(): cannot validate invalid source genotype");
     313                return Geno("", Geno::FORMAT_INVALID, "", "GENOPER_OPFAIL: Mutate(): cannot validate invalid source genotype");
    314314        bool ok = false;
    315315        int pcount = count;
     
    354354{
    355355        SString format = g1.getFormat();
    356         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()));
     356        if (format != g2.getFormat()) return Geno("", Geno::FORMAT_INVALID, "", SString::sprintf("GENOPER_NOOPER: CrossOver(): does not work for parents with differing genetic formats (%s and %s)", format.c_str(), g2.getFormat().c_str()));
    357357        GenoOperators *gf = getOper_f(format);
    358358        if (gf == NULL)
    359                 return Geno("", Geno::INVALID_FORMAT, "", SString::sprintf("GENOPER_NOOPER: CrossOver(): no operators found for genetic format %s", format.c_str()));
     359                return Geno("", Geno::FORMAT_INVALID, "", SString::sprintf("GENOPER_NOOPER: CrossOver(): no operators found for genetic format %s", format.c_str()));
    360360        Geno g1v = g1, g2v = g2;
    361361
     
    364364                bool canvalidate = true;
    365365                if (testValidity(g1v, canvalidate) > 0 && canvalidate == false)
    366                         return Geno("", Geno::INVALID_FORMAT, "", "GENOPER_OPFAIL: CrossOver(): cannot validate invalid source genotype #1");
     366                        return Geno("", Geno::FORMAT_INVALID, "", "GENOPER_OPFAIL: CrossOver(): cannot validate invalid source genotype #1");
    367367                canvalidate = true;
    368368                if (testValidity(g2v, canvalidate) > 0 && canvalidate == false)
    369                         return Geno("", Geno::INVALID_FORMAT, "", "GENOPER_OPFAIL: CrossOver(): cannot validate invalid source genotype #2");
     369                        return Geno("", Geno::FORMAT_INVALID, "", "GENOPER_OPFAIL: CrossOver(): cannot validate invalid source genotype #2");
    370370        }
    371371
     
    405405                {
    406406                        logPrintf("GenMan", "CrossOver", LOG_WARN, "Tried " GENMAN_REPEAT_FAILED_STR "x and failed: %s and %s", g1.getGenes().c_str(), g2.getGenes().c_str());
    407                         return Geno("", Geno::INVALID_FORMAT, "", "GENOPER_OPFAIL: CrossOver() tried " GENMAN_REPEAT_FAILED_STR "x and failed");
     407                        return Geno("", Geno::FORMAT_INVALID, "", "GENOPER_OPFAIL: CrossOver() tried " GENMAN_REPEAT_FAILED_STR "x and failed");
    408408                }
    409409        }
     
    428428{
    429429        SString format = G->getFormat();
    430         if (format == Geno::INVALID_FORMAT)
     430        if (format == Geno::FORMAT_INVALID)
    431431                return GENSTYLE_RGBS(64, 64, 64, 0); // gray & "valid" (unknown format so we don't know what is valid and what is not)
    432432        if ((pos = G->mapStringToGen(pos)) == -1) return GENSTYLE_COMMENT;
     
    445445{
    446446        SString format = G->getFormat();
    447         if (format == Geno::INVALID_FORMAT)
     447        if (format == Geno::FORMAT_INVALID)
    448448        {
    449449                for (unsigned int pos = 0; pos < strlen(g); pos++)
  • cpp/frams/genetics/geno.cpp

    r972 r988  
    3838}
    3939
    40 const SString Geno::INVALID_FORMAT = "invalid";
    41 const SString Geno::UNKNOWN_FORMAT = "";
     40const SString Geno::FORMAT_INVALID = "invalid";
     41const SString Geno::FORMAT_UNKNOWN = "";
    4242const SString Geno::F0_FORMAT_LIST = "0,0s";
    4343
     
    6868        SString format = trim(input);
    6969        if (format.length() == 0 || strContainsOneOf(format.c_str(), " \r\n\t"))
    70                 return Geno::INVALID_FORMAT;
     70                return Geno::FORMAT_INVALID;
    7171        return format;
    7272}
     
    7878        SString gencopy(genstring);
    7979        SString genformat = in_genformat;
    80         if (genformat == UNKNOWN_FORMAT)
     80        if (genformat == FORMAT_UNKNOWN)
    8181        { // unknown format
    8282                genformat = "1";
     
    118118                                break;
    119119                        }
    120                         if (genformat == INVALID_FORMAT)
     120                        if (genformat == FORMAT_INVALID)
    121121                        {
    122122                                SString cut;
     
    191191Geno::Geno(const SString& src)
    192192{
    193         init(src, UNKNOWN_FORMAT, SString::empty(), SString::empty());
     193        init(src, FORMAT_UNKNOWN, SString::empty(), SString::empty());
    194194}
    195195
     
    204204{
    205205        freeF0();
    206         init(g, UNKNOWN_FORMAT, SString::empty(), SString::empty());
     206        init(g, FORMAT_UNKNOWN, SString::empty(), SString::empty());
    207207}
    208208
     
    277277        if (isvalid >= 0) return;
    278278        if (gen.length() == 0) { isvalid = 0; return; }
    279         if (format == INVALID_FORMAT) { isvalid = 0; return; }
     279        if (format == FORMAT_INVALID) { isvalid = 0; return; }
    280280        Validators* vals = getValidators();
    281281        if (vals != NULL)
  • cpp/frams/genetics/geno.h

    r972 r988  
    5555
    5656public:
    57         static const SString INVALID_FORMAT;
    58         static const SString UNKNOWN_FORMAT;
     57        static const SString FORMAT_INVALID;
     58        static const SString FORMAT_UNKNOWN;
    5959        typedef SListTempl<GenoValidator*> Validators;
    6060
     
    9393
    9494        /** @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);
     95        void setGenesAndFormat(const SString& genstring, const SString& genformat = FORMAT_UNKNOWN);
    9696        /** g must be pure genes, without format. For the standard behavior use setGenesAndFormat() */
    9797        void setGenesAssumingSameFormat(const SString& g);
  • cpp/frams/genetics/genoconv.cpp

    r981 r988  
    107107        for (; gk = (GenoConverter*)converters(i); i++)
    108108        {
    109                 if ((in != Geno::UNKNOWN_FORMAT) && (in != gk->in_format)) continue;
    110                 if ((out != Geno::UNKNOWN_FORMAT) && (out != gk->out_format)) continue;
     109                if ((in != Geno::FORMAT_UNKNOWN) && (in != gk->in_format)) continue;
     110                if ((out != Geno::FORMAT_UNKNOWN) && (out != gk->out_format)) continue;
    111111                if ((enabled != -1) && (enabled != gk->enabled)) continue;
    112112                if ((name) && (strcmp(name, gk->name))) continue;
     
    168168        {
    169169                if (converter_missing) *converter_missing = false;
    170                 return Geno("", Geno::INVALID_FORMAT, "", "Invalid genotype cannot be converted");
     170                return Geno("", Geno::FORMAT_INVALID, "", "Invalid genotype cannot be converted");
    171171        }
    172172        int mapavail;
     
    176176        {
    177177                if (converter_missing) *converter_missing = true;
    178                 return Geno("", Geno::INVALID_FORMAT, "", "Converter not found");
     178                return Geno("", Geno::FORMAT_INVALID, "", "Converter not found");
    179179        }
    180180        if (converter_missing) *converter_missing = false;
     
    193193                {
    194194                        string t = ssprintf("f%s->f%s conversion failed (%s)", gk->in_format.c_str(), gk->out_format.c_str(), gk->name);
    195                         return Geno("", Geno::INVALID_FORMAT, "", t.c_str());
     195                        return Geno("", Geno::FORMAT_INVALID, "", t.c_str());
    196196                }
    197197                if (mapavail)
  • cpp/frams/genetics/genoconv.h

    r972 r988  
    5656        virtual ~GenoConverter() {}
    5757        /// Don't forget to set public fields in your constructor
    58         GenoConverter() :name(""), in_format(Geno::UNKNOWN_FORMAT), out_format("0"), enabled(1), mapsupport(0) {}
     58        GenoConverter() :name(""), in_format(Geno::FORMAT_UNKNOWN), out_format("0"), enabled(1), mapsupport(0) {}
    5959};
    6060
     
    8787        /// pass result=0 if you only need one result (by return value)
    8888        /// default criteria values mean "don't care", pass anything else to narrow your search
    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);
     89        GenoConverter *findConverters(SListTempl<GenoConverter*>* result = 0, const SString& in = Geno::FORMAT_UNKNOWN, const SString& out = Geno::FORMAT_UNKNOWN, int enabled = -1, char* name = 0);
    9090};
    9191
  • cpp/frams/model/model.cpp

    r975 r988  
    351351                return;
    352352        }
     353        if (declared_shape == SHAPE_UNKNOWN)
     354                declareShapeType(shapeTypeForGenoFormat(f0geno.getFormat()));
    353355        SString f0txt = f0geno.getGenes();
    354356        buildstatus = building; // was: open();
     
    447449        if ((buildstatus != valid) && (buildstatus != building))
    448450        {
    449                 g = Geno("", Geno::INVALID_FORMAT, "", "invalid model");
     451                g = Geno("", Geno::FORMAT_INVALID, "", "invalid model");
    450452                return;
    451453        }
     
    563565                return "0s";
    564566        default:
    565                 return Geno::INVALID_FORMAT;
     567                return Geno::FORMAT_INVALID;
    566568        }
    567569}
  • cpp/frams/vm/classes/genoobj.cpp

    r972 r988  
    111111                return v.getString();
    112112        }
    113         return Geno::INVALID_FORMAT;
     113        return Geno::FORMAT_INVALID;
    114114}
    115115
     
    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, Geno::UNKNOWN_FORMAT, n, c));
     200                *ret = makeDynamicObjectAndDecRef(new Geno(g, Geno::FORMAT_UNKNOWN, n, c));
    201201        }
    202202        else
Note: See TracChangeset for help on using the changeset viewer.