source: cpp/frams/_demos/multiline_f0_test.cpp @ 112

Last change on this file since 112 was 109, checked in by sz, 11 years ago

source reorganization (see README)
new feature added: part/joint shapes (see frams/_demos/part_shapes.cpp)

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include <time.h>
4#include <frams/virtfile/stdiofile.h>
5
6#include <frams/model/model.h>
7#include <frams/genetic/defgenoconv.h>
8#include <frams/errmgr/stdouterr.h>
9#include <frams/virtfile/stringfile.h>
10
11StdoutErrorHandler err; //redirect model-related errors to stdout
12DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
13
14int main(int argc,char*argv[])
15{
16SString gen(argc>1?argv[1]:"X[|G:1.23]");
17if (!strcmp(gen,"-"))
18        {
19        gen=0;
20        StdioFILEDontClose in(stdin);
21        loadSString(&in,gen);
22        }
23Geno g(gen);
24printf("\nSource genotype: '%s'\n",(const char*)g.getGene());
25printf("                  ( format %c %s)\n",
26       g.getFormat(), (const char*)g.getComment());
27
28Model m(g);//.getConverted('0'));
29
30if (!m.isValid())
31        {
32        printf("Cannot build Model from this genotype!\n");
33        return 2;       
34        }
35printf("Converted to f0:\n%s\n",(const char*)m.getF0Geno().getGene());
36
37printf("\nusing Param::save() to create the \"expanded\" form of the f0 genotype...\n(MultiParamLoader should be able to load this)");
38
39StringFILE2 f;
40
41static Param modelparam(f0_model_paramtab);
42static Param partparam(f0_part_paramtab);
43static Param jointparam(f0_joint_paramtab);
44static Param neuroparam(f0_neuro_paramtab);
45static Param connparam(f0_neuroconn_paramtab);
46
47modelparam.select(&m);
48modelparam.save(&f,&SString("m"));
49
50Part *p;
51Joint *j;
52Neuro *n;
53
54for (int i=0;p=(Part*)m.getPart(i);i++)
55        {
56        partparam.select(p);
57        partparam.save(&f,&SString("p"));
58        }
59for (int i=0;j=(Joint*)m.getJoint(i);i++)
60        {
61        jointparam.select(j);
62        jointparam.setParamTab(j->usedelta?f0_joint_paramtab:f0_nodeltajoint_paramtab);
63        jointparam.save(&f,&SString("j"));
64        }
65for (int i=0;n=(Neuro*)m.getNeuro(i);i++)
66        {
67        neuroparam.select(n);
68        neuroparam.save(&f,&SString("n"));
69        }
70for (int a=0;n=(Neuro*)m.getNeuro(a);a++)
71        { // inputs
72        for (int b=0;b<n->getInputCount();b++)
73                {
74                double w;
75                NeuroConn nc;
76                Neuro* n2=n->getInput(b,w);
77                nc.n1_refno=n->refno; nc.n2_refno=n2->refno;
78                nc.weight=w;
79                nc.info=n->getInputInfo(b);
80                connparam.select(&nc);
81                connparam.save(&f,&SString("c"));
82                }
83        }
84
85printf("\n============================\n%s\n",(const char*)f.getString());
86
87return 0;
88}
89
90/*********************** EXAMPLE OUTPUT *********************************
91
92Source genotype: 'X[|G:1.23]'
93                  ( format 1 )
94Converted to f0:
95p:
96p:1
97j:0, 1, dx=1
98n:p=1
99n:j=0, d="|:p=0.25,r=1"
100n:j=0, d=G
101c:0, 2, 1.23
102c:1, 0
103
104
105using Param::save() to create the "expanded" form of the f0 genotype...
106(MultiParamLoader should be able to load this)
107============================
108m:
109se:1
110Vstyle:
111
112p:
113x:0
114y:0
115z:0
116m:1
117s:1
118dn:1
119fr:0.4
120ing:0.25
121as:0.25
122rx:0
123ry:0
124rz:0
125i:
126Vstyle:part
127
128p:
129x:1
130y:0
131z:0
132m:1
133s:1
134dn:1
135fr:0.4
136ing:0.25
137as:0.25
138rx:0
139ry:0
140rz:0
141i:
142Vstyle:part
143
144j:
145p1:0
146p2:1
147rx:0
148ry:0
149rz:0
150dx:1
151dy:0
152dz:0
153stif:1
154rotstif:1
155stam:0.25
156i:
157Vstyle:joint
158
159n:
160p:1
161j:-1
162d:N
163i:
164Vstyle:neuro
165
166n:
167p:-1
168j:0
169d:|:p=0.25,r=1
170i:
171Vstyle:neuro
172
173n:
174p:-1
175j:0
176d:G
177i:
178Vstyle:neuro
179
180c:
181n1:0
182n2:2
183w:1.23
184i:
185
186c:
187n1:1
188n2:0
189w:1
190i:
191
192
193*************************************************************************/
Note: See TracBrowser for help on using the repository browser.