Changeset 797 for cpp/frams/genetics/fH


Ignore:
Timestamp:
06/06/18 01:45:18 (6 years ago)
Author:
Maciej Komosinski
Message:

A more complete implementation of fB, fH, fL

Location:
cpp/frams/genetics/fH
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fH/fH_conv.cpp

    r780 r797  
     1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     3// See LICENSE.txt for details.
     4
    15#include "fH_conv.h"
    26
  • cpp/frams/genetics/fH/fH_conv.h

    r780 r797  
     1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     3// See LICENSE.txt for details.
     4
    15#ifndef _FH_CONV_H_
    26#define _FH_CONV_H_
  • cpp/frams/genetics/fH/fH_general.cpp

    r780 r797  
     1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     3// See LICENSE.txt for details.
     4
    15#include <string>
    26#include <limits>
     
    1317// Methods for loading handles
    1418
    15 const char *fH_part_names[PART_PROPS_COUNT] = { "dn", "fr", "ing", "as" };
    16 
    17 const char *fH_joint_names[JOINT_PROPS_COUNT] = { "stif", "rotstif", "stam" };
     19const char *fH_part_names[FH_PART_PROPS_COUNT] = { "dn", "fr", "ing", "as" };
     20
     21const char *fH_joint_names[FH_JOINT_PROPS_COUNT] = { "stif", "rotstif", "stam" };
    1822
    1923void fH_Handle::loadProperties(Param par)
     
    106110
    107111        Part p;
    108         for (int i = 0; i < PART_PROPS_COUNT; i++)
     112        for (int i = 0; i < FH_PART_PROPS_COUNT; i++)
    109113        {
    110114                stickmut.addProperty(&p.properties().getParamTab()[p.properties().findId(fH_part_names[i]) + p.properties().getGroupCount()], -1);
     
    112116
    113117        Joint j;
    114         for (int i = 0; i < JOINT_PROPS_COUNT; i++)
     118        for (int i = 0; i < FH_JOINT_PROPS_COUNT; i++)
    115119        {
    116120                stickmut.addProperty(&j.properties().getParamTab()[j.properties().findId(fH_joint_names[i]) + j.properties().getGroupCount()], -1);
     
    119123
    120124        Neuro n;
    121         neuronmut.addProperty(&n.properties().getParamTab()[n.properties().findId(PE_NEURO_DET) + n.properties().getGroupCount()], -1);
     125        neuronmut.addProperty(&n.properties().getParamTab()[n.properties().findId(FH_PE_NEURO_DET) + n.properties().getGroupCount()], -1);
    122126
    123127        Param tmp(f0_neuroconn_paramtab, NULL);
    124         connectionmut.addProperty(&tmp.getParamTab()[tmp.findId(PE_CONN_WEIGHT) + tmp.getGroupCount()], -1);
     128        connectionmut.addProperty(&tmp.getParamTab()[tmp.findId(FH_PE_CONN_WEIGHT) + tmp.getGroupCount()], -1);
    125129
    126130        stickparamtab = ParamObject::makeParamTab((ParamInterface *)&stickmut, 0, 0, stickmut.firstMutableIndex());
     
    343347{
    344348        Param par(tab, obj);
    345         double partprops[PART_PROPS_COUNT];
    346         for (int i = 0; i < PART_PROPS_COUNT; i++)
     349        double partprops[FH_PART_PROPS_COUNT];
     350        for (int i = 0; i < FH_PART_PROPS_COUNT; i++)
    347351        {
    348352                partprops[i] = par.getDouble(2 * getDimensions() + i);
     
    357361        {
    358362                par.select(child->obj);
    359                 for (int i = 0; i < PART_PROPS_COUNT; i++)
     363                for (int i = 0; i < FH_PART_PROPS_COUNT; i++)
    360364                {
    361365                        partprops[i] += par.getDouble(2 * getDimensions() + i);
     
    364368        }
    365369
    366         for (int i = 0; i < PART_PROPS_COUNT; i++)
     370        for (int i = 0; i < FH_PART_PROPS_COUNT; i++)
    367371        {
    368372                partprops[i] /= stickscount;
     
    522526                        msg += det + "\" does not exist";
    523527                        logMessage("fH_Builder", "developBrain", LOG_ERROR, msg.c_str());
     528                        delete currneu->neuron;
    524529                        return -1;
    525530                }
     
    601606                if (!beginneu)
    602607                {
    603                         logMessage("fH_Builder", "developBrain", LOG_WARN, "There are no available neurons with outputs, connection could not be established");
     608                        // due to often appearance of connection genes in fB encoding, this
     609                        // log message is commented
     610                        // logMessage("fH_Builder", "developBrain", LOG_DEBUG, "There are no available neurons with outputs, connection could not be established");
    604611                        continue;
    605612                }
     
    628635                if (!endneu)
    629636                {
    630                         logMessage("fH_Builder", "developBrain", LOG_WARN, "There are no available neurons with free inputs, connection could not be established");
     637                        // due to often appearance of connection genes in fB encoding, this
     638                        // log message is commented
     639                        // logMessage("fH_Builder", "developBrain", LOG_DEBUG, "There are no available neurons with free inputs, connection could not be established");
    631640                        continue;
    632641                }
  • cpp/frams/genetics/fH/fH_general.h

    r780 r797  
     1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     3// See LICENSE.txt for details.
     4
    15#ifndef _FH_GENERAL_H_
    26#define _FH_GENERAL_H_
     
    1418#define HANDLE_VECTOR_TYPE "f -1.0 1.0 0.0" ///<Vector values type definition
    1519#define STICKH_LENGTH_TYPE "f 0.001 1.999 1.0" ///<Length of stick handle. Minimum should not be equal to 0, because calculating direction of next part from current stick with length 0 would be impossible
    16 #define PART_PROPS_COUNT   4 ///<Count of part properties
    17 #define JOINT_PROPS_COUNT  3 ///<Count of joint properties
    18 #define PE_NEURO_DET       "d" ///<Id of details type definition in f0_neuro_paramtab
    19 #define PE_CONN_WEIGHT     "w" ///<Id of weight type definition in f0_neuroconn_paramtab
     20#define FH_PART_PROPS_COUNT   4 ///<Count of part properties
     21#define FH_JOINT_PROPS_COUNT  3 ///<Count of joint properties
     22#define FH_PE_NEURO_DET       "d" ///<Id of details type definition in f0_neuro_paramtab
     23#define FH_PE_CONN_WEIGHT     "w" ///<Id of weight type definition in f0_neuroconn_paramtab
    2024//@}
    2125
  • cpp/frams/genetics/fH/fH_oper.cpp

    r780 r797  
     1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     3// See LICENSE.txt for details.
     4
    15#include "fH_oper.h"
    26
     
    421425}
    422426
    423 void Geno_fH::mutateNeuronHandleProperties(fH_NeuronHandle *handle, ParamEntry *tab, bool userandomclass)
     427void Geno_fH::mutateNeuronProperties(SString &det)
    424428{
    425429        Neuro neu;
    426         Param hpar(tab, handle->obj);
    427         SString det = hpar.getStringById("d");
     430        det = det == "" ? "N" : det;
    428431        neu.setDetails(det == "" ? "N" : det);
    429         NeuroClass *nc = neu.getClass();
    430 
    431         if (userandomclass)
    432         {
    433                 nc = getRandomNeuroClass();
    434                 if (!nc) nc = Neuro::getClass("N");
    435         }
    436 
    437         det = nc->getName();
    438         neu.setDetails(det);
    439432
    440433        SyntParam par = neu.classProperties();
     
    455448                if (props != "")
    456449                {
     450                        det = neu.getClass()->name;
    457451                        det += ": ";
    458452                        det += props;
    459                         hpar.setStringById("d", det);
    460                 }
    461         }
    462 }
    463 
    464 uint32_t Geno_fH::style(const char *geno, int pos)
    465 {
    466         char ch = geno[pos];
    467         uint32_t style = GENSTYLE_CS(0, GENSTYLE_STRIKEOUT);
    468         if (pos == 0 || geno[pos - 1] == '\n' || ch == ':') // single-character handle type and all colons
    469         {
    470                 style = GENSTYLE_CS(GENCOLOR_TEXT, GENSTYLE_BOLD);
    471         }
    472         else if (isalpha(ch)) // properties name
    473         {
    474                 style = GENSTYLE_RGBS(0, 200, 0, GENSTYLE_BOLD);
    475         }
    476         else if (isdigit(ch) || strchr(",.=", ch)) // properties values
    477         {
    478                 style = GENSTYLE_CS(GENCOLOR_TEXT, GENSTYLE_NONE);
    479         }
    480         else if (ch == '\"')
    481         {
    482                 style = GENSTYLE_RGBS(200, 0, 0, GENSTYLE_BOLD);
    483         }
    484 
    485         return style;
    486 }
     453                }
     454        }
     455}
     456
     457void Geno_fH::mutateNeuronHandleProperties(fH_NeuronHandle *handle, ParamEntry *tab, bool userandomclass)
     458{
     459        Neuro neu;
     460        Param hpar(tab, handle->obj);
     461        SString det = hpar.getStringById("d");
     462        neu.setDetails(det == "" ? "N" : det);
     463        NeuroClass *nc = neu.getClass();
     464
     465        if (userandomclass)
     466        {
     467                nc = getRandomNeuroClass();
     468                if (!nc) nc = Neuro::getClass("N");
     469        }
     470
     471        det = nc->getName();
     472
     473        mutateNeuronProperties(det);
     474
     475        hpar.setStringById("d", det);
     476}
     477
     478//uint32_t Geno_fH::style(const char *geno, int pos)
     479//{
     480//      char ch = geno[pos];
     481//      uint32_t style = GENSTYLE_CS(0, GENSTYLE_STRIKEOUT);
     482//      if (pos == 0 || geno[pos - 1] == '\n' || ch == ':') // single-character handle type and all colons
     483//      {
     484//              style = GENSTYLE_CS(GENCOLOR_TEXT, GENSTYLE_BOLD);
     485//      }
     486//      else if (isalpha(ch)) // properties name
     487//      {
     488//              style = GENSTYLE_RGBS(0, 200, 0, GENSTYLE_BOLD);
     489//      }
     490//      else if (isdigit(ch) || strchr(",.=", ch)) // properties values
     491//      {
     492//              style = GENSTYLE_CS(GENCOLOR_TEXT, GENSTYLE_NONE);
     493//      }
     494//      else if (ch == '\"')
     495//      {
     496//              style = GENSTYLE_RGBS(200, 0, 0, GENSTYLE_BOLD);
     497//      }
     498//
     499//      return style;
     500//}
     501
     502uint32_t Geno_fH::style(const char *g, int pos)
     503{
     504   char ch=g[pos];
     505   uint32_t style=GENSTYLE_CS(0,GENSTYLE_NONE); //default, should be changed below
     506
     507   int pp=pos; //detect comment line
     508   while (pp>1 && g[pp-1]!='\n') pp--;
     509   if (g[pp]=='#') return GENSTYLE_RGBS(0,220,0,GENSTYLE_NONE); //comment line
     510
     511   if (pos==0 || g[pos-1]=='\n' || ch==':' || ch==',') style=GENSTYLE_CS(0,GENSTYLE_BOLD); else
     512     if (ch=='\"') style=GENSTYLE_RGBS(150,0,0,GENSTYLE_BOLD); else
     513     {
     514      int cudz=0,neuclass=1; //ile cudz. do poczatku linii; czy w nazwie neuroklasy?
     515      while (pos>0)
     516      {
     517         pos--;
     518         if (g[pos]=='\"') cudz++;
     519         if (cudz==0 && (g[pos]==':' || g[pos]==',')) neuclass=0;
     520         if (g[pos]=='\n') break;
     521      }
     522      if (cudz%2)
     523      {
     524         if (neuclass) style=GENSTYLE_RGBS(150,0,150,GENSTYLE_BOLD); else //neuroclass
     525           if (isalpha(ch)) style=GENSTYLE_RGBS(255,140,0,GENSTYLE_BOLD); else //property
     526             style=GENSTYLE_RGBS(200,0,0,GENSTYLE_NONE);
     527      } else
     528        if (isalpha(ch)) style=GENSTYLE_RGBS(0,0,200,GENSTYLE_BOLD);
     529     }
     530   return style;
     531}
  • cpp/frams/genetics/fH/fH_oper.h

    r780 r797  
     1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     3// See LICENSE.txt for details.
     4
    15#ifndef _FH_OPER_H_
    26#define _FH_OPER_H_
     
    8791        double addoperations[FH_ADD_OPCOUNT]; ///<relative probabilities of selecting mutation addition subtypes
    8892
     93        // TODO add to GenoOperators?
     94        /**
     95         * Mutates properties of neuron and returns full neuron class description.
     96         * @param det current neuron class definition with its parameters
     97         */
     98        static void mutateNeuronProperties(SString &det);
     99
    89100        Geno_fH();
    90101
Note: See TracChangeset for help on using the changeset viewer.