[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] | 15 | int 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 | |
---|
[972] | 32 | Model m(g, Model::SHAPE_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 | |
---|
[972] | 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 | |
---|
| 96 | Source genotype: 'X[|G:1.23]' |
---|
[972] | 97 | ( format 1 ) |
---|
[109] | 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 | |
---|
[745] | 109 | using Param::saveMultiLine() to create the "expanded" form of the f0 genotype... |
---|
[109] | 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 | *************************************************************************/ |
---|