Ignore:
Timestamp:
02/15/18 00:42:07 (6 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.

File:
1 edited

Legend:

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

    r727 r732  
    2727                in_format = 'x';
    2828        }
    29         SString convert(SString &i, MultiMap *map) { return SString("after conversion..."); }
     29        SString convert(SString &i, MultiMap *map, bool using_checkpoints) { return SString("after conversion..."); }
    3030        ~GenoConv_Test() {}
    3131};
     
    4242        }
    4343
    44         SString convert(SString &i, MultiMap *map)
     44        SString convert(SString &i, MultiMap *map, bool using_checkpoints)
    4545        {
    4646                Model mod;
     
    5353                return mod.getF0Geno().getGenes();
    5454        }
    55        
     55
    5656        ~GenoConv_Test2() {}
    5757};
     
    7070                mapsupport = 1;
    7171        }
    72         SString convert(SString &in, MultiMap *map);
     72        SString convert(SString &in, MultiMap *map, bool using_checkpoints);
    7373        ~GenoConv_Test3() {}
    7474};
    7575
    7676/** main converting routine - most important: direct conversion map example */
    77 SString GenoConv_Test3::convert(SString &in, MultiMap *map)
     77SString GenoConv_Test3::convert(SString &in, MultiMap *map, bool using_checkpoints)
    7878{
    7979        SString dst;
     
    116116}
    117117
     118// arguments:
     119//     genotype (or - meaning "read from stdin") [default: X]
     120//     target format [default: 0]
     121//     "checkpoints" (just write this exact word) [default: not using checkpoints]
    118122int main(int argc, char *argv[])
    119123{
     
    146150                src = "X";
    147151        char dst = (argc > 2) ? *argv[2] : '0';
     152        bool using_checkpoints = (argc > 3) ? (strcmp(argv[3], "checkpoints") == 0) : false;
    148153
    149154        printf("*** Source genotype:\n");
     
    151156        printGen(g1);
    152157        MultiMap m;
    153         Geno g2 = g1.getConverted(dst, &m);
     158        Geno g2 = g1.getConverted(dst, &m, using_checkpoints);
    154159        printf("*** Converted to f%c:\n", dst);
    155160        printGen(g2);
    156         if (m.isEmpty())
    157                 printf("(conversion map not available)\n");
     161
     162        if (using_checkpoints)
     163        { // using Model with checkpoints
     164                Model m1(g2, false, true);//true=using_checkpoints
     165                printf("\nModel built from the converted f%c genotype has %d checkpoints\n", g2.getFormat(), m1.getCheckpointCount());
     166                Model m2(g1, false, true);//true=using_checkpoints
     167                printf("Model built from the source f%c genotype has %d checkpoints\n", g1.getFormat(), m2.getCheckpointCount());
     168                // accessing individual checkpoint models (if available)
     169                if (m1.getCheckpointCount() > 0)
     170                {
     171                        int c = m1.getCheckpointCount() / 2;
     172                        Model *cm = m1.getCheckpoint(c);
     173                        printf("Checkpoint #%d (%d parts, %d joint, %d neurons)\n%s", c, cm->getPartCount(), cm->getJointCount(), cm->getNeuroCount(), cm->getF0Geno().getGenesAndFormat().c_str());
     174                }
     175        }
    158176        else
    159         {
    160                 printf("Conversion map:\n");
    161                 m.print();
    162                 printConvMap(g1.getGenes(), g2.getGenes(), m);
    163                 printf("Reverse conversion map:\n");
    164                 MultiMap rm;
    165                 rm.addReversed(m);
    166                 rm.print();
    167                 printConvMap(g2.getGenes(), g1.getGenes(), rm);
    168         }
    169 
    170         Model mod1(g1, 1);
    171         printf("\nModel map for f%c genotype:\n", g1.getFormat());
    172         printModelMap(g1.getGenes(), mod1.getMap());
    173         mod1.getMap().print();
    174         Model mod2(g2, 1);
    175         printf("\nModel map for f%c genotype:\n", g2.getFormat());
    176         printModelMap(g2.getGenes(), mod2.getMap());
    177         mod2.getMap().print();
     177        { // there is no mapping for checkpoints so it's nothing interesting to see here in the checkpoints mode
     178                if (m.isEmpty())
     179                        printf("(conversion map not available)\n");
     180                else
     181                {
     182                        printf("Conversion map:\n");
     183                        m.print();
     184                        printConvMap(g1.getGenes(), g2.getGenes(), m);
     185                        printf("Reverse conversion map:\n");
     186                        MultiMap rm;
     187                        rm.addReversed(m);
     188                        rm.print();
     189                        printConvMap(g2.getGenes(), g1.getGenes(), rm);
     190                }
     191
     192                Model mod1(g1, 1);
     193                printf("\nModel map for f%c genotype:\n", g1.getFormat());
     194                printModelMap(g1.getGenes(), mod1.getMap());
     195                MultiMap mod1combined;
     196                mod1combined.addCombined(mod1.getMap(), getModelDisplayMap());
     197                mod1combined.print();
     198                Model mod2(g2, 1);
     199                printf("\nModel map for f%c genotype:\n", g2.getFormat());
     200                printModelMap(g2.getGenes(), mod2.getMap());
     201                MultiMap mod2combined;
     202                mod2combined.addCombined(mod2.getMap(), getModelDisplayMap());
     203                mod2combined.print();
     204        }
    178205        return 0;
    179206}
Note: See TracChangeset for help on using the changeset viewer.