Changeset 716 for cpp/frams


Ignore:
Timestamp:
11/22/17 02:50:49 (3 years ago)
Author:
Maciej Komosinski
Message:

The f1 converter is now able to map more than one genotype character to the special, not-yet-known initial Part. This fixes the test case "(rX,rX)"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f1/conv_f1.cpp

    r672 r716  
    99#include <frams/util/multimap.h>
    1010#include <ctype.h>
     11#include <assert.h>
    1112
    1213//#define v1f1COMPATIBLE //as in ancient Framsticks 1.x
     
    1819{
    1920public:
    20         Builder(const char*g, int mapping = 0) :invalid(0), genbegin(g), usemapping(mapping), first_part_mapping(NULL), model_energy(0), model_energy_count(0) {}
    21         ~Builder() { SAFEDELETE(first_part_mapping); }
     21        Builder(const char*g, int mapping = 0) :invalid(0), genbegin(g), usemapping(mapping), first_part_mapping(NULL), own_first_part_mapping(true), model_energy(0), model_energy_count(0) {}
     22        ~Builder() { if (own_first_part_mapping) SAFEDELETE(first_part_mapping); }
    2223        char tmp[222];
    2324        bool invalid;
     
    3839        MultiRange range;
    3940        MultiRange *first_part_mapping;
     41        bool own_first_part_mapping;
    4042        double lastjoint_muscle_power;
    4143        double model_energy;
     
    125127        { //special case: mapping the part which is not yet created
    126128                if (first_part_mapping) first_part_mapping->add(*r);
    127                 else first_part_mapping = new MultiRange(*r);
     129                else { first_part_mapping = new MultiRange(*r); own_first_part_mapping = true; }
    128130        }
    129131        else
     
    199201                                        freshpart = 1;
    200202                                        if (first_part_mapping)
     203                                        {
     204                                                //mapping was defined before creating this initial Part -> put it into the Part
     205                                                assert(own_first_part_mapping);
    201206                                                model.getPart(part1)->setMapping(*first_part_mapping);
     207                                                delete first_part_mapping;
     208                                                //first_part_mapping can be still used later but from now on it references the internal Part mapping
     209                                                first_part_mapping = model.getPart(part1)->getMapping();
     210                                                own_first_part_mapping = false;
     211                                        }
    202212                                }
    203213                        }
     
    243253                        c.muscle_bend_range = 1.0 / count;
    244254                        for (i = 0; i < count; i++)
    245                                 grow(part1, (char*)ga(i), k + Pt3D(0, 0, -M_PI + (i + 1)*(2*M_PI / (count + 1))), c);
     255                                grow(part1, (char*)ga(i), k + Pt3D(0, 0, -M_PI + (i + 1)*(2 * M_PI / (count + 1))), c);
    246256                        return;
    247257                }
Note: See TracChangeset for help on using the changeset viewer.