Ignore:
Timestamp:
07/03/20 00:32:23 (4 years ago)
Author:
Maciej Komosinski
Message:
  • separate "0" and "0s" formats (for SHAPE_BALL_AND_STICK and SHAPE_SOLIDS, respectively)
  • converting to format list (Geno::F0_FORMAT_LIST = "0,0s")
  • (optional) declaring Model as SHAPE_BALL_AND_STICK or SHAPE_SOLIDS (or SHAPE_UNKNOWN)
File:
1 edited

Legend:

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

    r955 r972  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2016  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1212#include <common/loggers/loggertostdout.h>
    1313
    14 void save_as_f0(SString &gen,Model &m,bool omit_default_values)
     14void save_as_f0(SString &gen, Model &m, bool omit_default_values)
    1515{
    16 // copied from Model::makeGeno() (with small changes)
     16        // copied from Model::makeGeno() (with small changes)
    1717
    18 static Param modelparam(f0_model_paramtab);
    19 static Param partparam(f0_part_paramtab);
    20 static Param jointparam(f0_joint_paramtab);
    21 static Param neuroparam(f0_neuro_paramtab);
    22 static Param connparam(f0_neuroconn_paramtab);
     18        static Param modelparam(f0_model_paramtab);
     19        static Param partparam(f0_part_paramtab);
     20        static Param jointparam(f0_joint_paramtab);
     21        static Param neuroparam(f0_neuro_paramtab);
     22        static Param connparam(f0_neuroconn_paramtab);
    2323
    24 static Part defaultpart;
    25 static Joint defaultjoint;
    26 static Neuro defaultneuro;
    27 static Model defaultmodel;
    28 static NeuroConn defaultconn;
     24        static Part defaultpart;
     25        static Joint defaultjoint;
     26        static Neuro defaultneuro;
     27        static Model defaultmodel;
     28        static NeuroConn defaultconn;
    2929
    30 modelparam.select(&m);
    31 gen+="m:";
    32 modelparam.saveSingleLine(gen,omit_default_values ? &defaultmodel : NULL);
     30        modelparam.select(&m);
     31        gen += "m:";
     32        modelparam.saveSingleLine(gen, omit_default_values ? &defaultmodel : NULL);
    3333
    34 Part *p;
    35 Joint *j;
    36 Neuro *n;
     34        Part *p;
     35        Joint *j;
     36        Neuro *n;
    3737
    38 for (int i=0;p=(Part*)m.getPart(i);i++)
     38        for (int i = 0; p = (Part*)m.getPart(i); i++)
    3939        {
    40         partparam.select(p);
    41         gen+="p:";
    42         partparam.saveSingleLine(gen,omit_default_values ? &defaultpart : NULL);
     40                partparam.select(p);
     41                gen += "p:";
     42                partparam.saveSingleLine(gen, omit_default_values ? &defaultpart : NULL);
    4343        }
    44 for (int i=0;j=(Joint*)m.getJoint(i);i++)
     44        for (int i = 0; j = (Joint*)m.getJoint(i); i++)
    4545        {
    46         jointparam.select(j);
    47         jointparam.setParamTab(j->usedelta?f0_joint_paramtab:f0_nodeltajoint_paramtab);
    48         gen+="j:";
    49         jointparam.saveSingleLine(gen,omit_default_values ? &defaultjoint : NULL);
     46                jointparam.select(j);
     47                jointparam.setParamTab(j->usedelta ? f0_joint_paramtab : f0_nodeltajoint_paramtab);
     48                gen += "j:";
     49                jointparam.saveSingleLine(gen, omit_default_values ? &defaultjoint : NULL);
    5050        }
    51 for (int i=0;n=(Neuro*)m.getNeuro(i);i++)
     51        for (int i = 0; n = (Neuro*)m.getNeuro(i); i++)
    5252        {
    53         neuroparam.select(n);
    54         gen+="n:";
    55         neuroparam.saveSingleLine(gen,omit_default_values ? &defaultneuro : NULL);
     53                neuroparam.select(n);
     54                gen += "n:";
     55                neuroparam.saveSingleLine(gen, omit_default_values ? &defaultneuro : NULL);
    5656        }
    57 for (int a=0;n=(Neuro*)m.getNeuro(a);a++)
     57        for (int a = 0; n = (Neuro*)m.getNeuro(a); a++)
    5858        { // inputs
    59         for (int b=0;b<n->getInputCount();b++)
     59                for (int b = 0; b < n->getInputCount(); b++)
    6060                {
    61                 double w;
    62                 NeuroConn nc;
    63                 Neuro* n2=n->getInput(b,w);
    64                 nc.n1_refno=n->refno; nc.n2_refno=n2->refno;
    65                 nc.weight=w;
    66                 nc.info=n->getInputInfo(b);
    67                 connparam.select(&nc);
    68                 gen+="c:";
    69                 connparam.saveSingleLine(gen,omit_default_values ? &defaultconn : NULL);
     61                        double w;
     62                        NeuroConn nc;
     63                        Neuro* n2 = n->getInput(b, w);
     64                        nc.n1_refno = n->refno; nc.n2_refno = n2->refno;
     65                        nc.weight = w;
     66                        nc.info = n->getInputInfo(b);
     67                        connparam.select(&nc);
     68                        gen += "c:";
     69                        connparam.saveSingleLine(gen, omit_default_values ? &defaultconn : NULL);
    7070                }
    7171        }
    7272}
    7373
    74 int main(int argc,char*argv[])
     74int main(int argc, char*argv[])
    7575{
    76 LoggerToStdout messages_to_stdout(LoggerBase::Enable);
     76        LoggerToStdout messages_to_stdout(LoggerBase::Enable);
    7777
    78 //without converters the application would only handle "format 0" genotypes
    79 DefaultGenoConvManager gcm;
    80 gcm.addDefaultConverters();
    81 Geno::useConverters(&gcm);
     78        //without converters the application would only handle "format 0" genotypes
     79        DefaultGenoConvManager gcm;
     80        gcm.addDefaultConverters();
     81        Geno::useConverters(&gcm);
    8282
    83 Geno::Validators validators;
    84 Geno::useValidators(&validators);
    85 ModelGenoValidator model_validator;
    86 validators+=&model_validator; //This simple validator handles all cases where a converter for a particular format is available but there is no genetic operator. Converters may be less strict in detecting invalid genotypes but it is better than nothing
     83        Geno::Validators validators;
     84        Geno::useValidators(&validators);
     85        ModelGenoValidator model_validator;
     86        validators += &model_validator; //This simple validator handles all cases where a converter for a particular format is available but there is no genetic operator. Converters may be less strict in detecting invalid genotypes but it is better than nothing
    8787
    88 SString gen(argc>1?argv[1]:"X[|G:1.23]");
    89 if (!strcmp(gen.c_str(),"-"))
     88        SString gen(argc > 1 ? argv[1] : "X[|G:1.23]");
     89        if (!strcmp(gen.c_str(), "-"))
    9090        {
    91         gen=0;
    92         StdioFILEDontClose in(stdin);
    93         loadSString(&in,gen);
     91                gen = 0;
     92                StdioFILEDontClose in(stdin);
     93                loadSString(&in, gen);
    9494        }
    95 Geno g(gen);
    96 printf("\nSource genotype: '%s'\n",g.getGenes().c_str());
    97 printf("                  ( format %s %s)\n",
    98        g.getFormat().c_str(), g.getComment().c_str());
     95        Geno g(gen);
     96        printf("\nSource genotype: '%s'\n", g.getGenes().c_str());
     97        printf("                  ( format %s %s)\n",
     98                g.getFormat().c_str(), g.getComment().c_str());
    9999
    100 Model m(g);//.getConverted('0'));
     100        Model m(g, Model::SHAPE_UNKNOWN);//.getConverted('0'));
    101101
    102 if (!m.isValid())
     102        if (!m.isValid())
    103103        {
    104         printf("Cannot build Model from this genotype!\n");
    105         return 2;       
     104                printf("Cannot build Model from this genotype!\n");
     105                return 2;
    106106        }
    107107
    108 printf("\nthis example shows how to save a f0 genotype using low-level ParamInterface::saveSingleLine() calls\n");
     108        printf("\nthis example shows how to save a f0 genotype using low-level ParamInterface::saveSingleLine() calls\n");
    109109
    110 SString f0_skipping_defaults;
    111 SString f0_no_skipping_defaults;
     110        SString f0_skipping_defaults;
     111        SString f0_no_skipping_defaults;
    112112
    113 save_as_f0(f0_skipping_defaults,m,true);
    114 save_as_f0(f0_no_skipping_defaults,m,false);
     113        save_as_f0(f0_skipping_defaults, m, true);
     114        save_as_f0(f0_no_skipping_defaults, m, false);
    115115
    116 printf("\n==== with defdata (skips default values) ======\n%s\n",f0_skipping_defaults.c_str());
    117 printf("\n==== without defdata (saves all fields) ======\n%s\n",f0_no_skipping_defaults.c_str());
     116        printf("\n==== with defdata (skips default values) ======\n%s\n", f0_skipping_defaults.c_str());
     117        printf("\n==== without defdata (saves all fields) ======\n%s\n", f0_no_skipping_defaults.c_str());
    118118
    119 return 0;
     119        return 0;
    120120}
    121121
     
    123123
    124124Source genotype: 'X[|G:1.23]'
    125                   ( format 1 )
     125                                  ( format 1 )
    126126
    127127this example shows how to save a f0 genotype using low-level ParamInterface::saveSingleLine() calls
Note: See TracChangeset for help on using the changeset viewer.