Changeset 635


Ignore:
Timestamp:
12/03/16 01:47:15 (8 years ago)
Author:
Maciej Komosinski
Message:

Introduced specialized info_* fields in (Mini)Genotype that match FEC fields

Location:
cpp/frams/_demos
Files:
2 edited

Legend:

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

    r473 r635  
    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-2016  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    66
    77#define FIELDSTRUCT MiniGenotype
    8 ParamEntry minigenotype_paramtab[]=
    9  {
    10  {"Genotype",1,21,"org",},
     8ParamEntry minigenotype_paramtab[] =
     9{
     10        { "Genotype", 1, 29, "org", },
    1111
    12  {"name",0,0,"Name","s 0 40",FIELD(name),},
    13  {"genotype",0,0,"Genotype","s 1",FIELD(genotype),},
    14  {"info",0,0,"Info","s 1",FIELD(info),},
     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.", },
    1514
    16  {"energy0",0,0,"Starting energy","f 0 -1 0",FIELD(energy0),},
    17  {"numparts",0,0,"Body parts","d",FIELD(numparts),},
    18  {"numjoints",0,0,"Body joints","d",FIELD(numjoints),},
    19  {"numneurons",0,0,"Brain size","d",FIELD(numneurons),},
    20  {"numconnections",0,0,"Brain connections","d",FIELD(numconnections),},
     15        { "info_timestamp", 1, 0, "Creation time", "fd 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." },
    2124
    22  {"num",0,0,"Ordinal number","d",FIELD(ordnumber),},
    23  {"gnum",0,0,"Generation","d",FIELD(generation),},
     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), },
    2430
    25  {"instances",0,0,"Instances","d",FIELD(instances),"Copies of this genotype",},
     31        { "num", 0, 0, "Ordinal number", "d", FIELD(ordnumber), },
     32        { "gnum", 0, 0, "Generation", "d", FIELD(generation), },
    2633
    27  {"lifespan",0,0,"Life span","f",FIELD(lifespan),"Average life span",},
    28  {"velocity",0,0,"Velocity","f",FIELD(velocity),"Average velocity",},
    29  {"distance",0,0,"Distance","f",FIELD(distance),},
    30  {"vertvel",0,0,"Vertical velocity","f",FIELD(vertvel),},
    31  {"vertpos",0,0,"Vertical position","f",FIELD(vertpos),},
     34        { "instances", 0, 0, "Instances", "d", FIELD(instances), "Copies of this genotype", },
    3235
    33  {"user1",0,0,"User field 1","x",FIELD(user1),},
    34  {"user2",0,0,"User field 2","x",FIELD(user2),},
    35  {"user3",0,0,"User field 3","x",FIELD(user3),},
     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), },
    3641
    37  {"is_valid",0,0,"Validity","d -1 1 -1",FIELD(is_valid),
    38  "0 = invalid genotype\n"
    39  "1 = valid genotype\n"
    40   "-1 = validity is not known."},
     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), },
    4145
    42  {"uid",0,0,"#","s",FIELD(uid),"Unique identifier"},
     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." },
    4350
    44  {0,0,0,},
     51        { "uid", 0, 0, "#", "s", FIELD(uid), "Unique identifier" },
     52
     53        { 0, 0, 0, },
    4554};
    4655#undef FIELDSTRUCT
    4756
    48 MiniGenotypeLoader::MiniGenotypeLoader():genotype_param(minigenotype_paramtab,&genotype_object) {init();}
    49 MiniGenotypeLoader::MiniGenotypeLoader(VirtFILE *f):MultiParamLoader(f),genotype_param(minigenotype_paramtab,&genotype_object) {init();}
    50 MiniGenotypeLoader::MiniGenotypeLoader(const char* filename):MultiParamLoader(filename),genotype_param(minigenotype_paramtab,&genotype_object) {init();}
     57MiniGenotypeLoader::MiniGenotypeLoader() :genotype_param(minigenotype_paramtab, &genotype_object) { init(); }
     58MiniGenotypeLoader::MiniGenotypeLoader(VirtFILE *f) : MultiParamLoader(f), genotype_param(minigenotype_paramtab, &genotype_object) { init(); }
     59MiniGenotypeLoader::MiniGenotypeLoader(const char* filename) : MultiParamLoader(filename), genotype_param(minigenotype_paramtab, &genotype_object) { init(); }
    5160
    5261void MiniGenotypeLoader::init()
    5362{
    54 addObject(&genotype_param);
    55 breakOn(MultiParamLoader::OnError + MultiParamLoader::AfterObject);
     63        addObject(&genotype_param);
     64        breakOn(MultiParamLoader::OnError + MultiParamLoader::AfterObject);
    5665}
    5766
    5867MiniGenotype* MiniGenotypeLoader::loadNextGenotype()
    5968{
    60 genotype_object.clear();
    61 if ((go()==AfterObject)&&(getObject().matchesInterfaceName(&genotype_param)))
    62         return &genotype_object;
    63 else
    64         return 0;
     69        genotype_object.clear();
     70        if ((go() == AfterObject) && (getObject().matchesInterfaceName(&genotype_param)))
     71                return &genotype_object;
     72        else
     73                return 0;
    6574}
  • cpp/frams/_demos/genotypeloader.h

    r517 r635  
    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-2016  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1010
    1111/** 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  */
     12        and the MiniGenotype fields. MiniGenotypeLoader uses this definition
     13        but you can also use it to make MultiParamLoader load genotype
     14        */
    1515extern ParamEntry minigenotype_paramtab[];
    1616
    1717/** 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  */
     18        or its specialized version: MiniGenotypeLoader.
     19        MiniGenotype stores the subset of Genotype fields (the ones normally saved in .gen files)
     20        */
    2121class MiniGenotype
    2222{
    2323public:
    24 SString name,genotype,info,uid;
    25 double energy0,lifespan,velocity,distance,vertvel,vertpos;
    26 paInt numparts,numjoints,numneurons,numconnections,ordnumber,generation,instances,is_valid;
    27 ExtValue user1,user2,user3;
    28 void clear() {Param p(minigenotype_paramtab,this); p.setDefault();}
     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(); }
    2933};
    3034
    3135/** In most simple cases this is the class you would use to load a series of genotypes from
    32     the Framsticks genotype file.
     36        the Framsticks genotype file.
    3337
    34     Usage pattern: (see loader_test_geno.cpp for the working code)
     38        Usage pattern: (see loader_test_geno.cpp for the working code)
    3539
    36     1.Initialize
     40        1.Initialize
    3741
    38     2.while(genotype=loadNextGenotype()) doSomethingWith(genotype);
     42        2.while(genotype=loadNextGenotype()) doSomethingWith(genotype);
    3943
    40     3.Done!
     44        3.Done!
    4145
    42     MiniGenotypeLoader is simply the MultiParamLoader configured to load one kind of data: "org:" objects.
    43     The instance of this class can also be reconfigured to recognize more objects by using MultiParamLoader
    44     methods, or you can use it as a guide for creating your own specialized class.
    45  */
    46 class MiniGenotypeLoader: public MultiParamLoader
     46        MiniGenotypeLoader is simply the MultiParamLoader configured to load one kind of data: "org:" objects.
     47        The instance of this class can also be reconfigured to recognize more objects by using MultiParamLoader
     48        methods, or you can use it as a guide for creating your own specialized class.
     49        */
     50class MiniGenotypeLoader : public MultiParamLoader
    4751{
    48 MiniGenotype genotype_object;
    49 Param genotype_param;
    50 bool initialized;
    51 void init();
     52        MiniGenotype genotype_object;
     53        Param genotype_param;
     54        bool initialized;
     55        void init();
    5256public:
    53 MiniGenotypeLoader();
    54 MiniGenotypeLoader(VirtFILE *f);
    55 MiniGenotypeLoader(const char* filename);
     57        MiniGenotypeLoader();
     58        MiniGenotypeLoader(VirtFILE *f);
     59        MiniGenotypeLoader(const char* filename);
    5660
    57 /** @returns genotype object if one was loaded or NULL otherwise.
     61        /** @returns genotype object if one was loaded or NULL otherwise.
    5862
    59     Returned MiniGenotype pointer always references the the same object (MiniGenotypeLoader::genotype_object)
    60     which means you may need to copy the data from it before calling loadNextGenotype() again.
    61     In the default configuration (simple MiniGenotypeLoader) NULL is always final and should be used
    62     to finish processing.
     63                Returned MiniGenotype pointer always references the the same object (MiniGenotypeLoader::genotype_object)
     64                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
     66                to finish processing.
    6367
    64     If the loader is configured to load other objects or stop on other conditions, NULL will also mean
    65     every condition other than "GenotypeLoaded". In such cases you need MultiParamLoader::getStatus(),
    66     MultiParamLoader::finished() and other methods to determine the real cause of NULL.
    67  */
    68 MiniGenotype* loadNextGenotype();
     68                If the loader is configured to load other objects or stop on other conditions, NULL will also mean
     69                every condition other than "GenotypeLoaded". In such cases you need MultiParamLoader::getStatus(),
     70                MultiParamLoader::finished() and other methods to determine the real cause of NULL.
     71                */
     72        MiniGenotype* loadNextGenotype();
    6973};
    7074
Note: See TracChangeset for help on using the changeset viewer.