Changeset 732 for cpp/frams/_demos


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.

Location:
cpp/frams/_demos
Files:
2 added
10 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}
  • cpp/frams/_demos/genotypeloader.cpp

    r639 r732  
    55#include "genotypeloader.h"
    66
    7 #define FIELDSTRUCT MiniGenotype
    8 ParamEntry minigenotype_paramtab[] =
    9 {
    10         { "Genotype", 1, 29, "org", },
    117
    12         { "name", 0, 0, "Name", "s 0 40", FIELD(name), },
    13         { "genotype", 0, 0, "Genotype", "s 1", FIELD(genotype), "Genes as a string of characters.", },
     8GenotypeMiniLoader::GenotypeMiniLoader() :genotype_param(genotypemini_paramtab, &genotype_object) { init(); }
     9GenotypeMiniLoader::GenotypeMiniLoader(VirtFILE *f) : MultiParamLoader(f), genotype_param(genotypemini_paramtab, &genotype_object) { init(); }
     10GenotypeMiniLoader::GenotypeMiniLoader(const char* filename) : MultiParamLoader(filename), genotype_param(genotypemini_paramtab, &genotype_object) { init(); }
    1411
    15         { "info_timestamp", 1, 0, "Last modified", "ft 0 -1 0", FIELD(info_timestamp), },
    16         { "info_author", 1, 0, "Author name", "s 0 100", FIELD(info_author), },
    17         { "info_author_ispublic", 1, 0, "Author name is public", "d 0 1 1", FIELD(info_author_ispublic), },
    18         { "info_email", 1, 0, "Author email", "s 0 100", FIELD(info_email), },
    19         { "info_email_ispublic", 1, 0, "Author email is public", "d 0 1 0", FIELD(info_email_ispublic), },
    20         { "info", 1, 0, "Description", "s 1 1000", FIELD(info), "Short description of key features of this creature.", },
    21         { "info_origin", 1, 0, "Origin", "d 0 4 0 ~Unspecified~Designed~Designed and evolved~Evolved under various conditions~Evolved using single, constant setup", FIELD(info_origin), "Declaration of how this genotype originated." },
    22         { "info_how_created", 1, 0, "How created", "s 1 1000", FIELD(info_how_created), "Description of the process of designing and/or evolving this genotype." },
    23         { "info_performance", 1, 0, "Performance notes", "s 1 1000", FIELD(info_performance), "Description of why this genotype is special/interesting and how it performs." },
    24 
    25         { "energy0", 0, 0, "Starting energy", "f 0 -1 0", FIELD(energy0), },
    26         { "numparts", 0, 0, "Body parts", "d", FIELD(numparts), },
    27         { "numjoints", 0, 0, "Body joints", "d", FIELD(numjoints), },
    28         { "numneurons", 0, 0, "Brain size", "d", FIELD(numneurons), },
    29         { "numconnections", 0, 0, "Brain connections", "d", FIELD(numconnections), },
    30 
    31         { "num", 0, 0, "Ordinal number", "d", FIELD(ordnumber), },
    32         { "gnum", 0, 0, "Generation", "d", FIELD(generation), },
    33 
    34         { "instances", 0, 0, "Instances", "d", FIELD(instances), "Copies of this genotype", },
    35 
    36         { "lifespan", 0, 0, "Life span", "f", FIELD(lifespan), "Average life span", },
    37         { "velocity", 0, 0, "Velocity", "f", FIELD(velocity), "Average velocity", },
    38         { "distance", 0, 0, "Distance", "f", FIELD(distance), },
    39         { "vertvel", 0, 0, "Vertical velocity", "f", FIELD(vertvel), },
    40         { "vertpos", 0, 0, "Vertical position", "f", FIELD(vertpos), },
    41 
    42         { "user1", 0, 0, "User field 1", "x", FIELD(user1), },
    43         { "user2", 0, 0, "User field 2", "x", FIELD(user2), },
    44         { "user3", 0, 0, "User field 3", "x", FIELD(user3), },
    45 
    46         { "is_valid", 0, 0, "Validity", "d -1 1 -1", FIELD(is_valid),
    47         "0 = invalid genotype\n"
    48         "1 = valid genotype\n"
    49         "-1 = validity is not known." },
    50 
    51         { "uid", 0, 0, "#", "s", FIELD(uid), "Unique identifier" },
    52 
    53         { 0, 0, 0, },
    54 };
    55 #undef FIELDSTRUCT
    56 
    57 MiniGenotypeLoader::MiniGenotypeLoader() :genotype_param(minigenotype_paramtab, &genotype_object) { init(); }
    58 MiniGenotypeLoader::MiniGenotypeLoader(VirtFILE *f) : MultiParamLoader(f), genotype_param(minigenotype_paramtab, &genotype_object) { init(); }
    59 MiniGenotypeLoader::MiniGenotypeLoader(const char* filename) : MultiParamLoader(filename), genotype_param(minigenotype_paramtab, &genotype_object) { init(); }
    60 
    61 void MiniGenotypeLoader::init()
     12void GenotypeMiniLoader::init()
    6213{
    6314        addObject(&genotype_param);
     
    6516}
    6617
    67 MiniGenotype* MiniGenotypeLoader::loadNextGenotype()
     18GenotypeMini* GenotypeMiniLoader::loadNextGenotype()
    6819{
    6920        genotype_object.clear();
  • cpp/frams/_demos/genotypeloader.h

    r635 r732  
    88#include <frams/util/sstring.h>
    99#include <frams/param/multiparamload.h>
    10 
    11 /** Defines the association between "org:" object (found in genotype files)
    12         and the MiniGenotype fields. MiniGenotypeLoader uses this definition
    13         but you can also use it to make MultiParamLoader load genotype
    14         */
    15 extern ParamEntry minigenotype_paramtab[];
    16 
    17 /** Helper class, mostly useful with MultiParamLoader
    18         or its specialized version: MiniGenotypeLoader.
    19         MiniGenotype stores the subset of Genotype fields (the ones normally saved in .gen files)
    20         */
    21 class MiniGenotype
    22 {
    23 public:
    24         SString name, genotype, info, uid;
    25         double info_timestamp;
    26         SString info_author, info_email;
    27         paInt info_author_ispublic, info_email_ispublic, info_origin;
    28         SString info_how_created, info_performance;
    29         double energy0, lifespan, velocity, distance, vertvel, vertpos;
    30         paInt numparts, numjoints, numneurons, numconnections, ordnumber, generation, instances, is_valid;
    31         ExtValue user1, user2, user3;
    32         void clear() { Param p(minigenotype_paramtab, this); p.setDefault(); }
    33 };
     10#include "genotypemini.h"
    3411
    3512/** In most simple cases this is the class you would use to load a series of genotypes from
     
    4825        methods, or you can use it as a guide for creating your own specialized class.
    4926        */
    50 class MiniGenotypeLoader : public MultiParamLoader
     27class GenotypeMiniLoader : public MultiParamLoader
    5128{
    52         MiniGenotype genotype_object;
     29        GenotypeMini genotype_object;
    5330        Param genotype_param;
    5431        bool initialized;
    5532        void init();
    5633public:
    57         MiniGenotypeLoader();
    58         MiniGenotypeLoader(VirtFILE *f);
    59         MiniGenotypeLoader(const char* filename);
     34        GenotypeMiniLoader();
     35        GenotypeMiniLoader(VirtFILE *f);
     36        GenotypeMiniLoader(const char* filename);
    6037
    6138        /** @returns genotype object if one was loaded or NULL otherwise.
    6239
    63                 Returned MiniGenotype pointer always references the the same object (MiniGenotypeLoader::genotype_object)
     40                Returned GenotypeMini pointer always references the the same object (GenotypeMiniLoader::genotype_object)
    6441                which means you may need to copy the data from it before calling loadNextGenotype() again.
    65                 In the default configuration (simple MiniGenotypeLoader) NULL is always final and should be used
     42                In the default configuration (simple GenotypeMiniLoader) NULL is always final and should be used
    6643                to finish processing.
    6744
     
    7047                MultiParamLoader::finished() and other methods to determine the real cause of NULL.
    7148                */
    72         MiniGenotype* loadNextGenotype();
     49        GenotypeMini* loadNextGenotype();
    7350};
    7451
  • cpp/frams/_demos/geometry/geometrytestutils.cpp

    r662 r732  
    1818        long count = 0;
    1919        long totalSize = 0;
    20         MiniGenotypeLoader loader(file);
    21         MiniGenotype *genotype;
    22        
     20        GenotypeMiniLoader loader(file);
     21        GenotypeMini *genotype;
     22
    2323        while (genotype = loader.loadNextGenotype())
    2424        {
    2525                count++;
    2626                totalSize += genotype->genotype.len();
    27                
     27
    2828                fprintf(stderr, "%d. (%6d chars) %s\n", count, genotype->genotype.len(),
    2929                        genotype->name.c_str());
    3030        }
    31        
    32         if (loader.getStatus() == MiniGenotypeLoader::OnError)
     31
     32        if (loader.getStatus() == GenotypeMiniLoader::OnError)
    3333        {
    3434                fprintf(stderr, "Error: %s\n", loader.getError().c_str());
     
    4444class TestInvoker
    4545{
    46         public:
    47                 virtual void operator()(Model &model) = 0;
     46public:
     47        virtual void operator()(Model &model) = 0;
    4848};
    4949
     
    5353        const int genoIndex = isdigit(genoId[0]) ? atol(genoId) : 0;
    5454        long count = 0;
    55         MiniGenotypeLoader loader(file);
    56         MiniGenotype *genotype;
    57        
     55        GenotypeMiniLoader loader(file);
     56        GenotypeMini *genotype;
     57
    5858        while (genotype = loader.loadNextGenotype())
    5959        {
    6060                count++;
    61                
     61
    6262                if ((genoIndex == count) || (strcmp(genotype->name.c_str(), genoName) == 0))
    6363                {
    6464                        Model model(genotype->genotype);
    65                        
     65
    6666                        if (!model.isValid())
    6767                        {
     
    7474                }
    7575        }
    76        
    77         if (loader.getStatus() == MiniGenotypeLoader::OnError)
     76
     77        if (loader.getStatus() == GenotypeMiniLoader::OnError)
    7878        {
    7979                fprintf(stderr, "Error: %s\n", loader.getError().c_str());
     
    9494        if ((shape < 1) || (shape > 3))
    9595        {
    96                 shape = (rand()%3) + 1;
     96                shape = (rand() % 3) + 1;
    9797        }
    9898
     
    106106}
    107107
    108 class ModelBasedTestInvoker: public TestInvoker
    109 {
    110         private:
    111                 void (*test)(Model &);
    112         public:
    113                 ModelBasedTestInvoker(void (*_test)(Model &)):
    114                         test(_test)
    115                 {}
    116                 void operator()(Model &model)
    117                 {
    118                         test(model);
    119                 }
     108class ModelBasedTestInvoker : public TestInvoker
     109{
     110private:
     111        void(*test)(Model &);
     112public:
     113        ModelBasedTestInvoker(void(*_test)(Model &)) :
     114                test(_test)
     115        {}
     116        void operator()(Model &model)
     117        {
     118                test(model);
     119        }
    120120};
    121121
    122 int GeometryTestUtils::execute(const SString header, int argc, char *argv[], void (*test)(Model &))
     122int GeometryTestUtils::execute(const SString header, int argc, char *argv[], void(*test)(Model &))
    123123{
    124124        LoggerToStdout messages_to_stdout(LoggerBase::Enable); //comment this object out to mute error/warning messages
    125125        StdioFileSystem_autoselect stdiofilesys;
    126126        PreconfiguredGenetics genetics;
    127        
     127
    128128        srand(time(NULL));
    129129
     
    132132                return printGenotypesList(argv[2]);
    133133        }
    134        
     134
    135135        if ((argc == 4) && (strcmp("-l", argv[1]) == 0))
    136136        {
     
    138138                return executeTestUsingLoadedModel(argv[2], argv[3], invoker);
    139139        }
    140        
     140
    141141        if ((argc == 2) && (strcmp("-c", argv[1]) == 0))
    142142        {
     
    144144                return executeTestUsingRandomModel(-1, invoker);
    145145        }
    146        
     146
    147147        if ((argc == 3) && (strcmp("-c", argv[1]) == 0) && isdigit(argv[2][0]))
    148148        {
     
    151151                return executeTestUsingRandomModel(shape, invoker);
    152152        }
    153        
     153
    154154        fprintf(stderr,
    155155                "%s\n\n"
     
    165165}
    166166
    167 class ModelAndDensityBasedTestInvoker: public TestInvoker
    168 {
    169         private:
    170                 void (*test)(Model &, const double);
    171                 double density;
    172         public:
    173                 ModelAndDensityBasedTestInvoker(void (*_test)(Model &, const double), double _density):
    174                         test(_test),
    175                         density(_density)
    176                 {}
    177                
    178                 void operator()(Model &model)
    179                 {
    180                         test(model, density);
    181                 }
     167class ModelAndDensityBasedTestInvoker : public TestInvoker
     168{
     169private:
     170        void(*test)(Model &, const double);
     171        double density;
     172public:
     173        ModelAndDensityBasedTestInvoker(void(*_test)(Model &, const double), double _density) :
     174                test(_test),
     175                density(_density)
     176        {}
     177
     178        void operator()(Model &model)
     179        {
     180                test(model, density);
     181        }
    182182};
    183183
    184184int GeometryTestUtils::execute(const SString header, int argc, char *argv[],
    185         void (*test)(Model &, const double))
     185        void(*test)(Model &, const double))
    186186{
    187187        LoggerToStdout messages_to_stdout(LoggerBase::Enable); //comment this object out to mute error/warning messages
    188188        StdioFileSystem_autoselect stdiofilesys;
    189189        PreconfiguredGenetics genetics;
    190        
     190
    191191        srand(time(NULL));
    192192
     
    202202                return executeTestUsingLoadedModel(argv[2], argv[3], invoker);
    203203        }
    204        
     204
    205205        if ((argc == 3) && (strcmp("-c", argv[1]) == 0) && isdigit(argv[2][0]))
    206206        {
     
    209209                return executeTestUsingRandomModel(-1, invoker);
    210210        }
    211        
     211
    212212        if ((argc == 4) && (strcmp("-c", argv[1]) == 0) && isdigit(argv[2][0]) && isdigit(argv[3][0]))
    213213        {
     
    217217                return executeTestUsingRandomModel(shape, invoker);
    218218        }
    219        
     219
    220220        fprintf(stderr,
    221221                "%s\n\n"
     
    235235{
    236236        Part *part = model.addNewPart(Part::SHAPE_ELLIPSOID);
    237        
     237
    238238        part->p = Pt3D(0);
    239239        part->scale = Pt3D(0.1);
    240240        part->vcolor = Pt3D(1.0, 0.0, 1.0);
    241        
     241
    242242        addAxesToModel(Pt3D(0.5), Orient(Orient_1), Pt3D(0.0), model);
    243243}
     
    247247        Part *anchor = model.getPart(0);
    248248        Part *part = model.addNewPart(Part::SHAPE_ELLIPSOID);
    249        
     249
    250250        part->p = Pt3D(markerLocation);
    251251        part->scale = Pt3D(0.05);
    252252        part->vcolor = Pt3D(1.0, 1.0, 0.0);
    253        
     253
    254254        model.addNewJoint(anchor, part, Joint::SHAPE_FIXED);
    255255}
     
    260260        Part *anchor = model.getPart(0);
    261261        Part *part;
    262        
     262
    263263        part = model.addNewPart(Part::SHAPE_CUBOID);
    264264        part->scale = Pt3D(sizes.x, 0.05, 0.05);
     
    267267        part->vcolor = Pt3D(1.0, 0.0, 0.0);
    268268        model.addNewJoint(anchor, part, Joint::SHAPE_FIXED);
    269        
     269
    270270        part = model.addNewPart(Part::SHAPE_CUBOID);
    271271        part->scale = Pt3D(0.05, sizes.y, 0.05);
     
    274274        part->vcolor = Pt3D(0.0, 1.0, 0.0);
    275275        model.addNewJoint(anchor, part, Joint::SHAPE_FIXED);
    276        
     276
    277277        part = model.addNewPart(Part::SHAPE_CUBOID);
    278278        part->scale = Pt3D(0.05, 0.05, sizes.z);
     
    287287        Part *targetAnchor = target.getPart(0);
    288288        Part *sourceAnchor = source.getPart(0);
    289        
     289
    290290        target.moveElementsFrom(source);
    291        
     291
    292292        target.addNewJoint(targetAnchor, sourceAnchor, Joint::SHAPE_FIXED);
    293293}
     
    295295double frand(double from, double width)
    296296{
    297         return from + width * ((rand()%10000) / 10000.0);
     297        return from + width * ((rand() % 10000) / 10000.0);
    298298}
    299299
  • cpp/frams/_demos/loader_test_geno.cpp

    r520 r732  
    2626        long count = 0, totalsize = 0;
    2727        StdioFileSystem_autoselect stdiofilesys;
    28         MiniGenotypeLoader loader(argv[1]);
     28        GenotypeMiniLoader loader(argv[1]);
    2929        const char* selected = (argc < 3) ? NULL : argv[2];
    3030        const char* field_name = (argc < 4) ? NULL : argv[3];
    3131        int selected_index = (selected&&isdigit(selected[0])) ? atol(selected) : 0;
    3232        // using char* constructor (passing the file name to open)
    33         MiniGenotype *loaded;
     33        GenotypeMini *loaded;
    3434        while (loaded = loader.loadNextGenotype())
    3535        { // if loaded != NULL then the "org:" object data was
     
    5151                        if (field_name)
    5252                        {
    53                                 Param p(minigenotype_paramtab, loaded);
     53                                Param p(genotypemini_paramtab, loaded);
    5454                                int field_index = p.findId(field_name);
    5555                                if (field_index < 0)
     
    6868        }
    6969        // the loop repeats until loaded==NULL, which could be beacause of error
    70         if (loader.getStatus() == MiniGenotypeLoader::OnError)
     70        if (loader.getStatus() == GenotypeMiniLoader::OnError)
    7171                fprintf(stderr, "Error: %s", loader.getError().c_str());
    7272        // (otherwise it was the end of the file)
  • cpp/frams/_demos/paramtree_paramlist_test.cpp

    r730 r732  
    2222        PreconfiguredGenetics genetics;
    2323
    24         Param minigenotype_param(minigenotype_paramtab);
     24        Param genotypemini_param(genotypemini_paramtab);
    2525        NeuroFactory neurofac;
    2626        neurofac.setStandardImplementation();
     
    3636        combined += &Pt3D_Ext::getStaticParam();
    3737        combined += &Orient_Ext::getStaticParam();
    38         combined += &minigenotype_param;
     38        combined += &genotypemini_param;
    3939        combined += &nn_config.par;
    4040        combined += &modelgeo.par;
  • cpp/frams/_demos/printconvmap.cpp

    r348 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
     
    66#include <stdio.h>
    77#include <frams/util/multimap.h>
     8#include <frams/model/model.h>
    89
    910#define GEN1MAX 15
    1011
    11 void printN(const char* t,int maxlen)
     12void printN(const char* t, int maxlen)
    1213{
    13 while(maxlen-- > 0)
    14         if (*t) putchar(*(t++));
    15         else putchar(' ');
     14        while (maxlen-- > 0)
     15                if (*t) putchar(*(t++));
     16                else putchar(' ');
    1617}
    1718
    18 void printN(char t,int maxlen)
     19void printN(char t, int maxlen)
    1920{
    20 while(maxlen-- > 0) putchar(t);
     21        while (maxlen-- > 0) putchar(t);
    2122}
    2223
    23 void printmapping(const char* gen1, int len1,const MultiRange &mr,const char* gen2,int len2)
     24void printmapping(const char* gen1, int len1, const MultiRange &mr, const char* gen2, int len2)
    2425{
    25 printN(' ',GEN1MAX-len1);
    26 printN(gen1,len1);
    27 printf(" : ");
    28 int i;
    29 for(i=0;i<len2;i++)
    30         if (mr.contains(i))
    31                 putchar(gen2[i]);
    32         else
    33                 putchar('.');
    34 putchar('\n');
     26        printN(' ', GEN1MAX - len1);
     27        printN(gen1, len1);
     28        printf(" : ");
     29        int i;
     30        for (i = 0; i < len2; i++)
     31                if (mr.contains(i))
     32                        putchar(gen2[i]);
     33                else
     34                        putchar('.');
     35        putchar('\n');
    3536}
    3637
    3738void stripstring(SString &str)
    3839{
    39 char *t=str.directWrite();
    40 for(;*t;t++)
    41         if (strchr("\n\r\t",*t)) *t=' ';
     40        char *t = str.directWrite();
     41        for (; *t; t++)
     42                if (strchr("\n\r\t", *t)) *t = ' ';
    4243}
    4344
    44 void printConvMap(const SString& gen1,const SString& gen2,const MultiMap& map)
     45void printConvMap(const SString& gen1, const SString& gen2, const MultiMap& map)
    4546{
    46 int y,y2,len1;
    47 int id=0;
    48 if (map.isEmpty())
     47        int y, y2, len1;
     48        int id = 0;
     49        if (map.isEmpty())
    4950        {
    50         printf("{ empty }\n");
    51         return;
     51                printf("{ empty }\n");
     52                return;
    5253        }
    53 len1=gen1.len();
    54 SString g1=gen1;
    55 stripstring(g1);
    56 SString g2=gen2;
    57 stripstring(g2);
    58 const char* g=g1.c_str();
    59 y=0;
    60 MultiRange *mr;
    61 MultiRange emptyrange;
    62 printN(' ',GEN1MAX);
    63 printf("   %s\n",g2.c_str());
    64 int begin=map.getBegin();
    65 int end=map.getEnd();
    66 while(y<len1)
     54        len1 = gen1.len();
     55        SString g1 = gen1;
     56        stripstring(g1);
     57        SString g2 = gen2;
     58        stripstring(g2);
     59        const char* g = g1.c_str();
     60        y = 0;
     61        MultiRange *mr;
     62        MultiRange emptyrange;
     63        printN(' ', GEN1MAX);
     64        printf("   %s\n", g2.c_str());
     65        int begin = map.getBegin();
     66        int end = map.getEnd();
     67        while (y < len1)
    6768        {
    68         if (y<begin)
     69                if (y < begin)
    6970                {
    70                 mr=&emptyrange;
    71                 y2=begin;
     71                        mr = &emptyrange;
     72                        y2 = begin;
    7273                }
    73         else if (y>end)
     74                else if (y > end)
    7475                {
    75                 mr=&emptyrange;
    76                 y2=len1;
     76                        mr = &emptyrange;
     77                        y2 = len1;
    7778                }
    78         else    {
    79                 id=map.findMappingId(y);
    80                 mr=&map.getMapping(id)->to;
    81                 y2=map.getMapping(id+1)->begin;
     79                else    {
     80                        id = map.findMappingId(y);
     81                        mr = &map.getMapping(id)->to;
     82                        y2 = map.getMapping(id + 1)->begin;
    8283                }
    83         if ((y2-y) > GEN1MAX) y2=y+GEN1MAX;
    84         if (y2>(y+len1)) y2=y+len1;
    85         printmapping(g+y,y2-y,*mr,g2.c_str(),g2.len());
    86         y=y2;
     84                if ((y2 - y) > GEN1MAX) y2 = y + GEN1MAX;
     85                if (y2 > (y + len1)) y2 = y + len1;
     86                printmapping(g + y, y2 - y, *mr, g2.c_str(), g2.len());
     87                y = y2;
    8788        }
    8889}
    8990
    90 void printModelMap(const SString& gen1,const MultiMap& map)
     91const MultiMap & getModelDisplayMap()
    9192{
    92 SString g2("012345678901234567890123456789");
    93 printN(' ',GEN1MAX);
    94 printf("   Parts     Joints    Neurons\n");
    95 printConvMap(gen1,g2,map);
     93        static MultiMap display_map;
     94        if (display_map.isEmpty())
     95        {
     96                for (int i = 0; i < 10; i++)
     97                {
     98                        display_map.add(Model::partToMap(i), Model::partToMap(i), i, i);
     99                        display_map.add(Model::jointToMap(i), Model::jointToMap(i), 10 + i, 10 + i);
     100                        display_map.add(Model::neuroToMap(i), Model::neuroToMap(i), 20 + i, 20 + i);
     101                }
     102        }
     103        return display_map;
    96104}
     105
     106void printModelMap(const SString& gen1, const MultiMap& map)
     107{
     108        MultiMap combined_map;
     109        combined_map.addCombined(map, getModelDisplayMap());
     110        SString g2("012345678901234567890123456789");
     111        printN(' ', GEN1MAX);
     112        printf("   Parts     Joints    Neurons\n");
     113        printConvMap(gen1, g2, combined_map);
     114}
  • cpp/frams/_demos/printconvmap.h

    r286 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
     
    1010class MultiMap;
    1111
    12 void printConvMap(const SString& gen1,const SString& gen2,const MultiMap& map);
    13 void printModelMap(const SString& gen1,const MultiMap& map);
     12void printConvMap(const SString& gen1, const SString& gen2, const MultiMap& map);
     13void printModelMap(const SString& gen1, const MultiMap& map); //automaticaly combines the map with the ModelDisplayMap
     14const MultiMap & getModelDisplayMap(); // mapping: true model -> display (so the regular map printing/debugging tools can be used for model maps, avoiding invonveniently huge numbers)
    1415
    1516#endif
  • cpp/frams/_demos/saver_test_geno.cpp

    r520 r732  
    2828        {
    2929                int N = atoi(argv[2]);
    30                 MiniGenotype g;
    31                 Param p(minigenotype_paramtab, &g);
     30                GenotypeMini g;
     31                Param p(genotypemini_paramtab, &g);
    3232                g.clear();
    3333                printf("Saving %d genotypes to %s\n", N, argv[1]);
  • cpp/frams/_demos/simil_test.cpp

    r612 r732  
    125125
    126126        long count = 0, totalsize = 0;
    127         MiniGenotypeLoader loader(szFileName);
    128         MiniGenotype *loaded;
     127        GenotypeMiniLoader loader(szFileName);
     128        GenotypeMini *loaded;
    129129        while (loaded = loader.loadNextGenotype())
    130130        {
     
    147147                }
    148148        }
    149         if (loader.getStatus() == MiniGenotypeLoader::OnError)
     149        if (loader.getStatus() == GenotypeMiniLoader::OnError)
    150150        {
    151151                printf("Error: %s", loader.getError().c_str());
Note: See TracChangeset for help on using the changeset viewer.