[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. |
---|
[109] | 4 | |
---|
| 5 | #include <stdlib.h> |
---|
| 6 | #include <stdio.h> |
---|
| 7 | #include <time.h> |
---|
[382] | 8 | #include <common/virtfile/stdiofile.h> |
---|
[109] | 9 | |
---|
| 10 | #include <frams/model/model.h> |
---|
[391] | 11 | #include <common/loggers/loggertostdout.h> |
---|
[145] | 12 | #include <frams/genetics/preconfigured.h> |
---|
[109] | 13 | |
---|
| 14 | /** |
---|
| 15 | @file |
---|
| 16 | Sample code: Adding/removing default properties in f0 genotypes |
---|
| 17 | Usage: full_props [-r[everse]] [genotype_or_stdin] |
---|
| 18 | |
---|
| 19 | Calling examples: |
---|
| 20 | |
---|
| 21 | # convert f1 -> f0 + explicitly set all properties to their default values (the result is still valid f0) |
---|
| 22 | ./full_props "X[|]arX[-1:1,fo:0.2]" |
---|
| 23 | |
---|
| 24 | //0 |
---|
| 25 | p:x=0, y=0, z=0, m=1, s=1, dn=1, fr=0.4, ing=0.25, as=0.25, rx=0, ry=0, rz=0, i=, Vstyle=part, vs=0.2, vr=0.5, vg=0.5, vb=0.5 |
---|
| 26 | p:x=1, y=0, z=0, m=2, s=1, dn=1, fr=0.4, ing=0.25, as=0.25, rx=0, ry=0, rz=0, i=, Vstyle=part, vs=0.2, vr=0.5, vg=0.5, vb=0.5 |
---|
| 27 | p:x=2, y=0, z=0, m=1, s=1, dn=1, fr=0.4, ing=0.277778, as=0.166667, rx=0, ry=0, rz=0, i=, Vstyle=part, vs=0.2, vr=0.5, vg=0.5, vb=0.5 |
---|
| 28 | j:p1=0, p2=1, rx=0, ry=0, rz=0, dx=1, dy=0, dz=0, stif=1, rotstif=1, stam=0.25, i=, Vstyle=joint, vr=0.5, vg=0.5, vb=0.5 |
---|
| 29 | j:p1=1, p2=2, rx=-0.7853, ry=0, rz=0, dx=1, dy=0, dz=0, stif=1, rotstif=1, stam=0.277778, i=, Vstyle=joint, vr=0.5, vg=0.5, vb=0.5 |
---|
| 30 | n:p=-1, j=0, d="|:p=0.25, r=1", i=, Vstyle=neuro |
---|
| 31 | n:p=2, j=-1, d="N:in=0.8, fo=0.2, si=2, s=0", i=, Vstyle=neuro |
---|
| 32 | c:n1=1, n2=0, w=1, i= |
---|
| 33 | |
---|
| 34 | # convert the previous output to the regular f0 format (removing redundant default properties) |
---|
| 35 | ./full_props "X[|]arX[-1:1,fo:0.2]" | ./full_props -r |
---|
| 36 | |
---|
| 37 | //0 |
---|
| 38 | p: |
---|
| 39 | p:1, m=2 |
---|
| 40 | p:2, ing=0.277778, as=0.166667 |
---|
| 41 | j:0, 1, dx=1 |
---|
| 42 | j:1, 2, rx=-0.7853, dx=1, stam=0.277778 |
---|
| 43 | n:j=0, d=| |
---|
| 44 | n:p=2, d=N:fo=0.2 |
---|
| 45 | c:1, 0 |
---|
| 46 | |
---|
| 47 | */ |
---|
| 48 | |
---|
[972] | 49 | int main(int argc, char*argv[]) |
---|
[109] | 50 | { |
---|
[972] | 51 | StdioFILE::setStdio();//setup VirtFILE::Vstdin/out/err |
---|
| 52 | LoggerToStdout messages_to_stderr(LoggerBase::Enable | LoggerBase::DontBlock, VirtFILE::Vstderr); //errors -> stderr, don't interfere with stdout |
---|
[109] | 53 | |
---|
[972] | 54 | PreconfiguredGenetics genetics; |
---|
[145] | 55 | |
---|
[972] | 56 | bool reverse = false; |
---|
| 57 | char* gen_arg = 0; |
---|
| 58 | for (int i = 1; i < argc; i++) |
---|
[109] | 59 | { |
---|
[972] | 60 | char* ar = argv[i]; |
---|
| 61 | if (ar[0] == '-') |
---|
| 62 | switch (ar[1]) |
---|
[109] | 63 | { |
---|
[972] | 64 | case 'r': reverse = true; break; |
---|
[1009] | 65 | case 'h': puts("Usage: full_props [-r[everse]] [genotype_or_stdin]\n"); break; |
---|
[109] | 66 | } |
---|
[972] | 67 | else |
---|
| 68 | if (!gen_arg) |
---|
| 69 | gen_arg = ar; |
---|
| 70 | } |
---|
| 71 | SString gen; |
---|
| 72 | if (gen_arg) |
---|
| 73 | gen = gen_arg; |
---|
[109] | 74 | else |
---|
[972] | 75 | loadSString(VirtFILE::Vstdin, gen); |
---|
| 76 | Geno g(gen); |
---|
[999] | 77 | Model m(g, Model::SHAPETYPE_UNKNOWN); |
---|
[109] | 78 | |
---|
[972] | 79 | if (!m.isValid()) |
---|
[109] | 80 | { |
---|
[1009] | 81 | logPrintf("full_props", "main", LOG_ERROR, "Cannot build Model from the supplied genotype.\n"); |
---|
[972] | 82 | return 2; |
---|
[109] | 83 | } |
---|
| 84 | |
---|
[972] | 85 | m.open(); |
---|
| 86 | for (int i = 0; i < m.getNeuroCount(); i++) |
---|
[109] | 87 | { |
---|
[972] | 88 | Neuro *n = m.getNeuro(i); |
---|
| 89 | SyntParam p = n->classProperties(reverse); |
---|
[1009] | 90 | p.update();// ...so everyone reading the source can recognize that p was created to update the neuro d field; |
---|
| 91 | // but actually, calling update() here is not necessary, because the ~SyntParam() destructor would do it anyway. |
---|
[109] | 92 | } |
---|
[972] | 93 | m.close(); |
---|
[109] | 94 | |
---|
[1009] | 95 | // Normal f0 (omitting default values) would be retrieved using m.getF0Geno(). |
---|
| 96 | // The following form allows for more control: |
---|
[972] | 97 | Geno f0_g; |
---|
[1009] | 98 | m.makeGeno(f0_g, NULL, reverse);//The third argument is "handle_defaults" == whether f0 should omit default property values |
---|
[972] | 99 | puts(f0_g.getGenesAndFormat().c_str()); |
---|
[109] | 100 | |
---|
[972] | 101 | return 0; |
---|
[109] | 102 | } |
---|