source: cpp/frams/_demos/full_props.cpp @ 284

Last change on this file since 284 was 283, checked in by Maciej Komosinski, 10 years ago

Clarified "normal f0" comment and removed another misleading comment

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include <stdlib.h>
6#include <stdio.h>
7#include <time.h>
8#include <frams/virtfile/stdiofile.h>
9
10#include <frams/model/model.h>
11#include <frams/errmgr/stdouterr.h>
12#include <frams/genetics/preconfigured.h>
13
14/**
15 @file
16 Sample code: Adding/removing default properties in f0 genotypes
17 Usage: full_props [-r[everse]] [genotype_or_stdin]
18
19 Calling examples:
20
21 # convert f1 -> f0 + explicitly set all properties to their default values  (the result is still valid f0)
22 ./full_props "X[|]arX[-1:1,fo:0.2]"
23
24   //0
25   p:x=0, y=0, z=0, m=1, s=1, dn=1, fr=0.4, ing=0.25, as=0.25, rx=0, ry=0, rz=0, i=, Vstyle=part, vs=0.2, vr=0.5, vg=0.5, vb=0.5
26   p:x=1, y=0, z=0, m=2, s=1, dn=1, fr=0.4, ing=0.25, as=0.25, rx=0, ry=0, rz=0, i=, Vstyle=part, vs=0.2, vr=0.5, vg=0.5, vb=0.5
27   p:x=2, y=0, z=0, m=1, s=1, dn=1, fr=0.4, ing=0.277778, as=0.166667, rx=0, ry=0, rz=0, i=, Vstyle=part, vs=0.2, vr=0.5, vg=0.5, vb=0.5
28   j:p1=0, p2=1, rx=0, ry=0, rz=0, dx=1, dy=0, dz=0, stif=1, rotstif=1, stam=0.25, i=, Vstyle=joint, vr=0.5, vg=0.5, vb=0.5
29   j:p1=1, p2=2, rx=-0.7853, ry=0, rz=0, dx=1, dy=0, dz=0, stif=1, rotstif=1, stam=0.277778, i=, Vstyle=joint, vr=0.5, vg=0.5, vb=0.5
30   n:p=-1, j=0, d="|:p=0.25, r=1", i=, Vstyle=neuro
31   n:p=2, j=-1, d="N:in=0.8, fo=0.2, si=2, s=0", i=, Vstyle=neuro
32   c:n1=1, n2=0, w=1, i=
33
34 # convert the previous output to the regular f0 format (removing redundant default properties)
35 ./full_props "X[|]arX[-1:1,fo:0.2]" | ./full_props -r
36
37   //0
38   p:
39   p:1, m=2
40   p:2, ing=0.277778, as=0.166667
41   j:0, 1, dx=1
42   j:1, 2, rx=-0.7853, dx=1, stam=0.277778
43   n:j=0, d=|
44   n:p=2, d=N:fo=0.2
45   c:1, 0
46
47*/
48
49int main(int argc,char*argv[])
50{
51StdioFILE::setStdio();//setup VirtFILE::Vstdin/out/err
52StdoutErrorHandler err(ErrorHandlerBase::DontBlock,VirtFILE::Vstderr); //errors -> stderr, don't interfere with stdout
53
54PreconfiguredGenetics genetics;
55
56bool reverse=false;
57char* gen_arg=0;
58for(int i=1;i<argc;i++)
59        {
60        char* ar=argv[i];
61        if (ar[0]=='-')
62                switch(ar[1])
63                        {
64                        case 'r': reverse=true; break;
65                        case 'h': puts("usage: full_props [-r[everse]] [genotype_or_stdin]\n"); break;
66                        }
67        else
68                if (!gen_arg)
69                        gen_arg=ar;
70        }
71SString gen;
72if (gen_arg)
73        gen=gen_arg;
74else
75        loadSString(VirtFILE::Vstdin,gen);
76Geno g(gen);
77Model m(g);
78
79if (!m.isValid())
80        {
81        FMprintf("","full_props",FMLV_ERROR,"Cannot build Model from the supplied genotype\n");
82        return 2;       
83        }
84
85m.open();
86for(int i=0;i<m.getNeuroCount();i++)
87        {
88        Neuro *n=m.getNeuro(i);
89        SyntParam p=n->classProperties(reverse);
90        p.update();// ...so everyone reading the source can recognize that p was created to update the neuro d field
91        // but actually, calling update() here is not necessary, because ~SyntParam() would do it anyway
92        }
93m.close();
94
95// normal f0 (omitting default values) would be retrieved using m.getF0Geno()
96// the following form allows for more control:
97Geno f0_g;
98m.makeGeno(f0_g,NULL,reverse);//third arg is "handle_defaults" == whether f0 should omit default property values
99puts((const char*)f0_g.toString());
100
101return 0;
102}
103
Note: See TracBrowser for help on using the repository browser.