| [286] | 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. | 
|---|
| [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 |  | 
|---|
|  | 15 | int main(int argc,char*argv[]) | 
|---|
|  | 16 | { | 
|---|
| [375] | 17 | LoggerToStdout messages_to_stdout(LoggerBase::Enable); | 
|---|
| [145] | 18 | PreconfiguredGenetics genetics; | 
|---|
|  | 19 |  | 
|---|
| [109] | 20 | SString gen(argc>1?argv[1]:"X[|G:1.23]"); | 
|---|
| [348] | 21 | if (!strcmp(gen.c_str(),"-")) | 
|---|
| [109] | 22 | { | 
|---|
|  | 23 | gen=0; | 
|---|
|  | 24 | StdioFILEDontClose in(stdin); | 
|---|
|  | 25 | loadSString(&in,gen); | 
|---|
|  | 26 | } | 
|---|
|  | 27 | Geno g(gen); | 
|---|
| [348] | 28 | printf("\nSource genotype: '%s'\n",g.getGene().c_str()); | 
|---|
| [109] | 29 | printf("                  ( format %c %s)\n", | 
|---|
| [348] | 30 | g.getFormat(), g.getComment().c_str()); | 
|---|
| [109] | 31 |  | 
|---|
|  | 32 | Model m(g);//.getConverted('0')); | 
|---|
|  | 33 |  | 
|---|
|  | 34 | if (!m.isValid()) | 
|---|
|  | 35 | { | 
|---|
|  | 36 | printf("Cannot build Model from this genotype!\n"); | 
|---|
|  | 37 | return 2; | 
|---|
|  | 38 | } | 
|---|
| [348] | 39 | printf("Converted to f0:\n%s\n",m.getF0Geno().getGene().c_str()); | 
|---|
| [109] | 40 |  | 
|---|
|  | 41 | printf("\nusing Param::save() to create the \"expanded\" form of the f0 genotype...\n(MultiParamLoader should be able to load this)"); | 
|---|
|  | 42 |  | 
|---|
|  | 43 | StringFILE2 f; | 
|---|
|  | 44 |  | 
|---|
|  | 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); | 
|---|
|  | 50 |  | 
|---|
|  | 51 | modelparam.select(&m); | 
|---|
| [124] | 52 | modelparam.save(&f,"m"); | 
|---|
| [109] | 53 |  | 
|---|
|  | 54 | Part *p; | 
|---|
|  | 55 | Joint *j; | 
|---|
|  | 56 | Neuro *n; | 
|---|
|  | 57 |  | 
|---|
|  | 58 | for (int i=0;p=(Part*)m.getPart(i);i++) | 
|---|
|  | 59 | { | 
|---|
|  | 60 | partparam.select(p); | 
|---|
| [124] | 61 | partparam.save(&f,"p"); | 
|---|
| [109] | 62 | } | 
|---|
|  | 63 | for (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); | 
|---|
| [124] | 67 | jointparam.save(&f,"j"); | 
|---|
| [109] | 68 | } | 
|---|
|  | 69 | for (int i=0;n=(Neuro*)m.getNeuro(i);i++) | 
|---|
|  | 70 | { | 
|---|
|  | 71 | neuroparam.select(n); | 
|---|
| [124] | 72 | neuroparam.save(&f,"n"); | 
|---|
| [109] | 73 | } | 
|---|
|  | 74 | for (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); | 
|---|
| [124] | 85 | connparam.save(&f,"c"); | 
|---|
| [109] | 86 | } | 
|---|
|  | 87 | } | 
|---|
|  | 88 |  | 
|---|
| [348] | 89 | printf("\n============================\n%s\n",f.getString().c_str()); | 
|---|
| [109] | 90 |  | 
|---|
|  | 91 | return 0; | 
|---|
|  | 92 | } | 
|---|
|  | 93 |  | 
|---|
|  | 94 | /*********************** EXAMPLE OUTPUT ********************************* | 
|---|
|  | 95 |  | 
|---|
|  | 96 | Source genotype: 'X[|G:1.23]' | 
|---|
|  | 97 | ( format 1 ) | 
|---|
|  | 98 | Converted to f0: | 
|---|
|  | 99 | p: | 
|---|
|  | 100 | p:1 | 
|---|
|  | 101 | j:0, 1, dx=1 | 
|---|
|  | 102 | n:p=1 | 
|---|
|  | 103 | n:j=0, d="|:p=0.25,r=1" | 
|---|
|  | 104 | n:j=0, d=G | 
|---|
|  | 105 | c:0, 2, 1.23 | 
|---|
|  | 106 | c:1, 0 | 
|---|
|  | 107 |  | 
|---|
|  | 108 |  | 
|---|
|  | 109 | using Param::save() to create the "expanded" form of the f0 genotype... | 
|---|
|  | 110 | (MultiParamLoader should be able to load this) | 
|---|
|  | 111 | ============================ | 
|---|
|  | 112 | m: | 
|---|
|  | 113 | se:1 | 
|---|
|  | 114 | Vstyle: | 
|---|
|  | 115 |  | 
|---|
|  | 116 | p: | 
|---|
|  | 117 | x:0 | 
|---|
|  | 118 | y:0 | 
|---|
|  | 119 | z:0 | 
|---|
|  | 120 | m:1 | 
|---|
|  | 121 | s:1 | 
|---|
|  | 122 | dn:1 | 
|---|
|  | 123 | fr:0.4 | 
|---|
|  | 124 | ing:0.25 | 
|---|
|  | 125 | as:0.25 | 
|---|
|  | 126 | rx:0 | 
|---|
|  | 127 | ry:0 | 
|---|
|  | 128 | rz:0 | 
|---|
|  | 129 | i: | 
|---|
|  | 130 | Vstyle:part | 
|---|
|  | 131 |  | 
|---|
|  | 132 | p: | 
|---|
|  | 133 | x:1 | 
|---|
|  | 134 | y:0 | 
|---|
|  | 135 | z:0 | 
|---|
|  | 136 | m:1 | 
|---|
|  | 137 | s:1 | 
|---|
|  | 138 | dn:1 | 
|---|
|  | 139 | fr:0.4 | 
|---|
|  | 140 | ing:0.25 | 
|---|
|  | 141 | as:0.25 | 
|---|
|  | 142 | rx:0 | 
|---|
|  | 143 | ry:0 | 
|---|
|  | 144 | rz:0 | 
|---|
|  | 145 | i: | 
|---|
|  | 146 | Vstyle:part | 
|---|
|  | 147 |  | 
|---|
|  | 148 | j: | 
|---|
|  | 149 | p1:0 | 
|---|
|  | 150 | p2:1 | 
|---|
|  | 151 | rx:0 | 
|---|
|  | 152 | ry:0 | 
|---|
|  | 153 | rz:0 | 
|---|
|  | 154 | dx:1 | 
|---|
|  | 155 | dy:0 | 
|---|
|  | 156 | dz:0 | 
|---|
|  | 157 | stif:1 | 
|---|
|  | 158 | rotstif:1 | 
|---|
|  | 159 | stam:0.25 | 
|---|
|  | 160 | i: | 
|---|
|  | 161 | Vstyle:joint | 
|---|
|  | 162 |  | 
|---|
|  | 163 | n: | 
|---|
|  | 164 | p:1 | 
|---|
|  | 165 | j:-1 | 
|---|
|  | 166 | d:N | 
|---|
|  | 167 | i: | 
|---|
|  | 168 | Vstyle:neuro | 
|---|
|  | 169 |  | 
|---|
|  | 170 | n: | 
|---|
|  | 171 | p:-1 | 
|---|
|  | 172 | j:0 | 
|---|
|  | 173 | d:|:p=0.25,r=1 | 
|---|
|  | 174 | i: | 
|---|
|  | 175 | Vstyle:neuro | 
|---|
|  | 176 |  | 
|---|
|  | 177 | n: | 
|---|
|  | 178 | p:-1 | 
|---|
|  | 179 | j:0 | 
|---|
|  | 180 | d:G | 
|---|
|  | 181 | i: | 
|---|
|  | 182 | Vstyle:neuro | 
|---|
|  | 183 |  | 
|---|
|  | 184 | c: | 
|---|
|  | 185 | n1:0 | 
|---|
|  | 186 | n2:2 | 
|---|
|  | 187 | w:1.23 | 
|---|
|  | 188 | i: | 
|---|
|  | 189 |  | 
|---|
|  | 190 | c: | 
|---|
|  | 191 | n1:1 | 
|---|
|  | 192 | n2:0 | 
|---|
|  | 193 | w:1 | 
|---|
|  | 194 | i: | 
|---|
|  | 195 |  | 
|---|
|  | 196 |  | 
|---|
|  | 197 | *************************************************************************/ | 
|---|