Ignore:
Timestamp:
07/14/20 16:04:46 (4 years ago)
Author:
Maciej Komosinski
Message:

Improved the fS encoding

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fS/fS_general.cpp

    r1000 r1006  
    1717bool fS_Genotype::TURN_WITH_ROTATION = false;
    1818
    19 const std::map<string, double> defaultValues = {
    20                 {INGESTION,      0.5},//Model::getDefPart().ingest },
    21                 {FRICTION,       0.5},//Model::getDefPart().friction},
    22                 {STIFFNESS,              0.5},//Model::getDefJoint().stif},
    23                 {ROT_X,          0.0},
    24                 {ROT_Y,          0.0},
    25                 {ROT_Z,          0.0},
    26                 {RX,             0.0},
    27                 {RY,             0.0},
    28                 {RZ,             0.0},
    29                 {SIZE,           1.0},
    30                 {SIZE_X,         0.5},//Model::getDefPart().scale.x},
    31                 {SIZE_Y,         0.5},//Model::getDefPart().scale.y},
    32                 {SIZE_Z,         0.5}//Model::getDefPart().scale.z}
    33 };
     19void Node::prepareParams()
     20{
     21        defaultValues = {
     22                        {INGESTION, Model::getDefPart().ingest},
     23                        {FRICTION,  Model::getDefPart().friction},
     24                        {STIFFNESS, Model::getDefJoint().stif},
     25                        {ROT_X,     0.0},
     26                        {ROT_Y,     0.0},
     27                        {ROT_Z,     0.0},
     28                        {RX,        0.0},
     29                        {RY,        0.0},
     30                        {RZ,        0.0},
     31                        {SIZE,      1.0},
     32                        {SIZE_X,    Model::getDefPart().scale.x},
     33                        {SIZE_Y,    Model::getDefPart().scale.y},
     34                        {SIZE_Z,    Model::getDefPart().scale.z}
     35        };
     36}
    3437
    3538double fS_stod(const string&  str, int start, size_t* size)
     
    7679
    7780
    78 fS_Neuron::fS_Neuron(const char *str, int start, int length)
    79 {
     81fS_Neuron::fS_Neuron(const char *str, int _start, int length)
     82{
     83        start = _start + 1;
     84        end = start + length;
    8085        if (length == 0)
    8186                return;
     
    123128Node::Node(Substring &restOfGeno, Node *_parent, GenotypeParams _genotypeParams)
    124129{
     130        prepareParams();
    125131        partDescription = new Substring(restOfGeno);
    126132        genotypeParams = _genotypeParams;
     
    165171        for (int i = 0; i < restOfGenotype.len; i++)
    166172        {
    167                 if (GENE_TO_SHAPETYPE.find(restOfGenotype.at(i)) != GENE_TO_SHAPETYPE.end())
     173                if (GENE_TO_SHAPE.find(restOfGenotype.at(i)) != GENE_TO_SHAPE.end())
    168174                        return i;
    169175        }
     
    193199void Node::extractPartType(Substring &restOfGenotype)
    194200{
    195         auto itr = GENE_TO_SHAPETYPE.find(restOfGenotype.at(0));
    196         if (itr == GENE_TO_SHAPETYPE.end())
     201        auto itr = GENE_TO_SHAPE.find(restOfGenotype.at(0));
     202        if (itr == GENE_TO_SHAPE.end())
    197203                throw fS_Exception("Invalid part type", restOfGenotype.start);
    198204
     
    465471                Neuro *neuro = new Neuro(*neurons[i]);
    466472                model.addNeuro(neuro);
     473                neuro->addMapping(MultiRange(IRange(neurons[i]->start, neurons[i]->end)));
    467474                if (neuro->getClass()->preflocation == NeuroClass::PREFER_JOINT && parent != nullptr)
    468475                {
     
    536543                result += std::string(count, mod).c_str();
    537544        }
    538         result += SHAPETYPE_TO_GENE.at(partType);
     545        result += SHAPE_TO_GENE.at(partType);
    539546
    540547        if (!neurons.empty())
     
    649656}
    650657
    651 void fS_Genotype::buildModel(Model &model)
    652 {
     658Model fS_Genotype::buildModel(bool using_checkpoints)
     659{
     660
     661        Model model;
     662        model.open(using_checkpoints);
     663
    653664        getState();
    654665        startNode->buildModel(model, nullptr);
    655666        buildNeuroConnections(model);
     667
     668        model.close();
     669        return model;
    656670}
    657671
Note: See TracChangeset for help on using the changeset viewer.