Changeset 975 for cpp/frams/_demos


Ignore:
Timestamp:
07/06/20 23:32:03 (4 years ago)
Author:
Maciej Komosinski
Message:

Added NeuroClass::getSupportedJointTypes() and NeuroClass::isJointTypeSupported() for use in genetic operators

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/genoconv_test.cpp

    r972 r975  
    107107}
    108108
     109/// Sample Geno converter producing "f0s" genotype from the textual list of shapes, eg. "/*shapes*/ball,cube,cube"
     110class GenoConv_Test4 : public GenoConverter
     111{
     112public:
     113        GenoConv_Test4()
     114        {
     115                name = "Test Converter #4";
     116                in_format = "shapes";
     117                out_format = "0s";
     118                mapsupport = 1;
     119        }
     120        SString convert(SString &in, MultiMap *map, bool using_checkpoints);
     121        ~GenoConv_Test4() {}
     122};
     123
     124SString GenoConv_Test4::convert(SString &in, MultiMap *map, bool using_checkpoints)
     125{
     126        SString result;
     127        int numparts=0;
     128        int input_pos=0, prev_input_pos=0; SString word;
     129        while(in.getNextToken(input_pos,word,','))
     130                {
     131                Part::Shape sh;
     132                if (word=="cube")
     133                        sh = Part::SHAPE_CUBOID;
     134                else if (word=="ball")
     135                        sh = Part::SHAPE_ELLIPSOID;
     136                else if (word=="cylinder")
     137                        sh = Part::SHAPE_CYLINDER;
     138                else
     139                        return "";
     140                SString add;
     141                add+=SString::sprintf("p:x=%g,sh=%d\n",numparts*2.0f,sh);
     142                if (numparts>0)
     143                        add+=SString::sprintf("j:p1=%d,p2=%d,sh=1\n",numparts-1,numparts);
     144                if (map) // fill in the map only if requested
     145                        map->add(prev_input_pos, prev_input_pos+word.length()-1, result.length(),result.length()+add.length()-1);
     146                result+=add;
     147                numparts++;
     148                prev_input_pos = input_pos;
     149                }
     150        return result;
     151}
     152
    109153
    110154///////////////////////////////////////////////
     
    118162static int goodWidthForFormat(const SString& genotype_format)
    119163{
    120         return genotype_format == "0" ? 45 : 15; // more space for long f0 lines
     164        return Geno::formatIsOneOf(genotype_format, Geno::F0_FORMAT_LIST) ? 45 : 15; // more space for long f0 lines
    121165}
    122166
     
    134178        gcm.addConverter(new GenoConv_Test2());
    135179        gcm.addConverter(new GenoConv_Test3());
     180        gcm.addConverter(new GenoConv_Test4());
    136181        Geno::useConverters(&gcm);
    137182
     
    154199        else
    155200                src = "X";
    156         SString dst = (argc > 2) ? *argv[2] : '0';
     201        SString dst = (argc > 2) ? argv[2] : Geno::F0_FORMAT_LIST;
    157202        bool using_checkpoints = (argc > 3) ? (strcmp(argv[3], "checkpoints") == 0) : false;
    158203
     
    162207        MultiMap m;
    163208        Geno g2 = g1.getConverted(dst, &m, using_checkpoints);
    164         printf("*** Converted to f%s:\n", dst.c_str());
     209        printf("*** Converted:\n");
    165210        printGen(g2);
    166211
Note: See TracChangeset for help on using the changeset viewer.