Ignore:
Timestamp:
12/05/14 08:09:47 (9 years ago)
Author:
Maciej Komosinski
Message:

Added support for genetic mapping in f9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f9/conv_f9.cpp

    r197 r259  
    88#include <common/nonstd_stl.h> //ARRAY_LENGTH
    99
    10 #define APPLY_DETERMINISTIC_BODY_NOISE //this representation easily produces perfectly vertical sticks that would stay upright forever. In most cases such infinite perfection is not desired, so we make the construct less perfect by perturbing its coordinates.
     10#define APPLY_DETERMINISTIC_BODY_NOISE //this genetic representation easily produces perfectly vertical sticks that would stay upright forever in simulation. In most cases such infinite perfection is not desired, so we make the construct less perfect by perturbing its coordinates.
    1111
    1212GenoConv_f90::GenoConv_f90()
     
    1515        in_format = '9';
    1616        out_format = '0';
    17         mapsupport = 0; //would be easy and nice to add!
     17        mapsupport = 1;
    1818}
    1919
     
    3131        Model m;
    3232        m.open();
    33         int recently_added = addSegment(m, vertices, current, 0xDead);
     33        int recently_added = addSegment(m, 0, vertices, current, 0xDead);
    3434        for (int i = 0; i < in.len(); i++)
    3535        {
     
    4444                        (*(delta + axis)) += dir * 2 - 1; //+1 or -1 in the given axis
    4545                        current.add(delta);
    46                         recently_added = addSegment(m, vertices, current, recently_added);
     46                        recently_added = addSegment(m, i, vertices, current, recently_added);
    4747                }
    4848        }
     
    5454        if (m.getPartCount() < 2) //only one part <=> there were no valid turtle commands in the input genotype
    5555                return ""; //so we return an invalid f0 genotype
     56        if (map != NULL)
     57                m.getCurrentToF0Map(*map);
    5658        return m.getF0Geno().getGene();
    5759}
    5860
    59 int GenoConv_f90::addSegment(Model &m, vector<XYZ_LOC> &vertices, const XYZ_LOC &new_vertex, int recently_added)
     61int GenoConv_f90::addSegment(Model &m, int genenr, vector<XYZ_LOC> &vertices, const XYZ_LOC &new_vertex, int recently_added)
    6062{
    6163        if (vertices.size() < 1) //empty model?
     
    7274                Part *p1 = m.getPart(recently_added);
    7375                Part *p2 = m.getPart(vertex_here);
    74                 if (m.findJoint(p1, p2) < 0 && m.findJoint(p2, p1) < 0) //new Joint needed? should always be true if we just created a new Part (vertex_here was <0)
    75                 {
    76                         m.addNewJoint(p1, p2);
    77                 }
     76                p1->addMapping(MultiRange(genenr, genenr));
     77                p2->addMapping(MultiRange(genenr, genenr));
     78
     79                int j12 = m.findJoint(p1, p2);
     80                int j21 = m.findJoint(p2, p1);
     81                if (j12 >= 0)
     82                        m.getJoint(j12)->addMapping(MultiRange(genenr, genenr));
     83                else if (j21 >= 0)
     84                        m.getJoint(j21)->addMapping(MultiRange(genenr, genenr));
     85                else //both j12<0 and j21<0. New Joint needed. Should always happen if we just created a new Part (vertex_here was <0)
     86                        m.addNewJoint(p1, p2)->addMapping(MultiRange(genenr, genenr));
    7887                return vertex_here;
    7988        }
     
    134143        int parts_count = m.getPartCount();
    135144        SList jlist;
    136         for (int i = 0; i<parts_count; i++)
     145        for (int i = 0; i < parts_count; i++)
    137146        {
    138147                Part *p = m.getPart(i);
Note: See TracChangeset for help on using the changeset viewer.