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

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