Changeset 473 for cpp/frams


Ignore:
Timestamp:
02/18/16 02:32:57 (9 years ago)
Author:
sz
Message:
  • MiniGenotype? extended to handle all Genotype fields contained in .gen files
  • loader_test now displays any MiniGenotype? field instead of the raw genotype when given the field name
  • MiniGenotypeLoader? and stdiofile.o included in SDK_LIB_OBJS
Location:
cpp/frams
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/Makefile-SDK-files

    r456 r473  
    2525STDOUT_LOGGER_OBJS=common/virtfile/virtfile.o common/loggers/loggertostdout.o common/console.o
    2626
    27 SDK_LIB_OBJS= $(STDOUT_LOGGER_OBJS) $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GENMAN_SDK_OBJS) $(GEOMETRY_OBJS)
     27GENOTYPE_LOADER_OBJS=frams/_demos/genotypeloader.o frams/param/multiparamload.o
     28SDK_LIB_OBJS= $(STDOUT_LOGGER_OBJS) $(SDK_OBJS) $(GENOCONV_SDK_OBJS) $(GENMAN_SDK_OBJS) $(GEOMETRY_OBJS) $(GENOTYPE_LOADER_OBJS) common/virtfile/stdiofile.o
    2829
    2930#### sdk_tests
  • cpp/frams/_demos/genotypeloader.cpp

    r286 r473  
    88ParamEntry minigenotype_paramtab[]=
    99 {
    10  {"Genotype",1,3,"org",},
     10 {"Genotype",1,21,"org",},
     11
    1112 {"name",0,0,"Name","s 0 40",FIELD(name),},
    1213 {"genotype",0,0,"Genotype","s 1",FIELD(genotype),},
    1314 {"info",0,0,"Info","s 1",FIELD(info),},
     15
     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),},
     21
     22 {"num",0,0,"Ordinal number","d",FIELD(ordnumber),},
     23 {"gnum",0,0,"Generation","d",FIELD(generation),},
     24
     25 {"instances",0,0,"Instances","d",FIELD(instances),"Copies of this genotype",},
     26
     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),},
     32
     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
     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."},
     41
     42 {"uid",0,0,"#","s",FIELD(uid),"Unique identifier"},
     43
    1444 {0,0,0,},
    1545};
  • cpp/frams/_demos/genotypeloader.h

    r286 r473  
    99#include <frams/param/multiparamload.h>
    1010
    11 /** Helper class, mostly useful with MultiParamLoader
    12     or its specialized version: MiniGenotypeLoader.
    13     MiniGenotype stores 3 essential fields of the Genotype (name, gene and info)
    14  */
    15 class MiniGenotype
    16 {
    17 public:
    18 SString name,genotype,info;
    19 void clear() {name=""; genotype=""; info="";}
    20 };
    21 
    22 
    2311/** Defines the association between "org:" object (found in genotype files)
    2412    and the MiniGenotype fields. MiniGenotypeLoader uses this definition
     
    2715extern ParamEntry minigenotype_paramtab[];
    2816
     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 */
     21class MiniGenotype
     22{
     23public:
     24SString name,genotype,info,uid;
     25double energy0,lifespan,velocity,distance,vertvel,vertpos;
     26paInt numparts,numjoints,numneurons,numconnections,ordnumber,generation,instances,is_valid;
     27ExtValue user1,user2,user3;
     28void clear() {Param p(minigenotype_paramtab,this); p.setDefault();}
     29};
    2930
    3031/** In most simple cases this is the class you would use to load a series of genotypes from
  • cpp/frams/_demos/loader_test.cpp

    r382 r473  
    1717if (argc<2)
    1818        {
    19         fprintf(stderr,"Arguments: filename [optional: genotype name or index (1-based)]\n"
    20              "If a genotype is indicated (by providing the optional genotype identifier), the program will output the raw genotype, suitable for Framsticks Theater's genotype viewer mode. If the second optional argument is not given, the genotype names from the file will be listed.\n"
     19        fprintf(stderr,"Arguments: filename [genotype name or index (1-based) [field name]]\n"
     20             "If a genotype is indicated (by providing the optional genotype identifier), the program will output the raw genotype, suitable for Framsticks Theater's genotype viewer mode. If a genotype and a field name is given, the field value (instead of the raw genotype) is printed. If the second argument is not given, the genotype names from the file will be listed.\n"
    2121             "Example: loader_test walking.gen \"Basic Quadruped\" | theater -g -\n"
    2222                );
     
    2828MiniGenotypeLoader loader(argv[1]);
    2929const char* selected=(argc<3)?NULL:argv[2];
     30const char* field_name=(argc<4)?NULL:argv[3];
    3031int selected_index=(selected&&isdigit(selected[0]))?atol(selected):0;
    3132// using char* constructor (passing the file name to open)
     
    4849                                continue;
    4950                        }
    50                 puts(loaded->genotype.c_str());
     51                if (field_name)
     52                        {
     53                        Param p(minigenotype_paramtab,loaded);
     54                        int field_index=p.findId(field_name);
     55                        if (field_index<0)
     56                                {
     57                                printf("Field '%s' not found\n",field_name);
     58                                return 3;
     59                                }
     60                        else
     61                                puts(p.get(field_index).c_str());
     62                                }
     63                        else
     64                                puts(loaded->genotype.c_str());
    5165                return 0;
    5266                }
Note: See TracChangeset for help on using the changeset viewer.