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

Last change on this file since 999 was 999, checked in by Maciej Komosinski, 4 years ago

More consistent usage of "shapetype" (vs. "shape")

  • Property svn:eol-style set to native
File size: 3.3 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[972]2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
[286]3// See LICENSE.txt for details.
[121]4
[109]5#include <stdlib.h>
6#include <stdio.h>
7#include <time.h>
[382]8#include <common/virtfile/stdiofile.h>
[109]9
[145]10#include <frams/genetics/preconfigured.h>
[109]11#include <frams/model/model.h>
[391]12#include <common/loggers/loggertostdout.h>
[382]13#include <common/virtfile/stringfile.h>
[109]14
[972]15int main(int argc, char*argv[])
[109]16{
[972]17        LoggerToStdout messages_to_stdout(LoggerBase::Enable);
18        PreconfiguredGenetics genetics;
[145]19
[972]20        SString gen(argc > 1 ? argv[1] : "X[|G:1.23]");
21        if (!strcmp(gen.c_str(), "-"))
[109]22        {
[972]23                gen = 0;
24                StdioFILEDontClose in(stdin);
25                loadSString(&in, gen);
[109]26        }
[972]27        Geno g(gen);
28        printf("\nSource genotype: '%s'\n", g.getGenes().c_str());
29        printf("                  ( format %s %s)\n",
30                g.getFormat().c_str(), g.getComment().c_str());
[109]31
[999]32        Model m(g, Model::SHAPETYPE_UNKNOWN);//.getConverted('0'));
[109]33
[972]34        if (!m.isValid())
[109]35        {
[972]36                printf("Cannot build Model from this genotype!\n");
37                return 2;
[109]38        }
[972]39        printf("Converted to f0:\n%s\n", m.getF0Geno().getGenes().c_str());
[109]40
[986]41        printf("\nUsing Param::saveMultiLine() to create the \"expanded\" form of the f0 genotype...\n(MultiParamLoader should be able to load this)");
[109]42
[972]43        StringFILE2 f;
[109]44
[972]45        static Param modelparam(f0_model_paramtab);
46        static Param partparam(f0_part_paramtab);
47        static Param jointparam(f0_joint_paramtab);
48        static Param neuroparam(f0_neuro_paramtab);
49        static Param connparam(f0_neuroconn_paramtab);
[109]50
[972]51        modelparam.select(&m);
52        modelparam.saveMultiLine(&f, "m");
[109]53
[972]54        Part *p;
55        Joint *j;
56        Neuro *n;
[109]57
[972]58        for (int i = 0; p = (Part*)m.getPart(i); i++)
[109]59        {
[972]60                partparam.select(p);
61                partparam.saveMultiLine(&f, "p");
[109]62        }
[972]63        for (int i = 0; j = (Joint*)m.getJoint(i); i++)
[109]64        {
[972]65                jointparam.select(j);
66                jointparam.setParamTab(j->usedelta ? f0_joint_paramtab : f0_nodeltajoint_paramtab);
67                jointparam.saveMultiLine(&f, "j");
[109]68        }
[972]69        for (int i = 0; n = (Neuro*)m.getNeuro(i); i++)
[109]70        {
[972]71                neuroparam.select(n);
72                neuroparam.saveMultiLine(&f, "n");
[109]73        }
[972]74        for (int a = 0; n = (Neuro*)m.getNeuro(a); a++)
[109]75        { // inputs
[972]76                for (int b = 0; b < n->getInputCount(); b++)
[109]77                {
[972]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.saveMultiLine(&f, "c");
[109]86                }
87        }
88
[972]89        printf("\n============================\n%s\n", f.getString().c_str());
[109]90
[972]91        return 0;
[109]92}
93
94/*********************** EXAMPLE OUTPUT *********************************
95
96Source genotype: 'X[|G:1.23]'
[972]97                                  ( format 1 )
[109]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
[986]109Using Param::saveMultiLine() to create the "expanded" form of the f0 genotype...
[109]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.