Changeset 774


Ignore:
Timestamp:
04/11/18 01:16:08 (6 years ago)
Author:
Maciej Komosinski
Message:

Removed unused "state" field (issue number 19), improved docs (issues number 20,21,23), code formatting (issue number 24) [closes #62]

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

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/conv_f4.cpp

    r760 r774  
    2525
    2626
    27 SString GenoConv_f40::convert(SString &in, MultiMap * map, bool using_checkpoints)
     27SString GenoConv_f40::convert(SString &in, MultiMap *map, bool using_checkpoints)
    2828{
    2929        int res;
    30         f4_Model * model = new f4_Model();
     30        f4_Model *model = new f4_Model();
    3131        res = model->buildFromF4(in, using_checkpoints);
    3232        if (GENOPER_OK != res) return SString();  // oops
     
    5050
    5151
    52 SString GenoConv_F41_TestOnly::convert(SString &in, MultiMap * map, bool using_checkpoints)
     52SString GenoConv_F41_TestOnly::convert(SString &in, MultiMap *map, bool using_checkpoints)
    5353{
    5454        int res;
    55         f4_Model * model = new f4_Model();
     55        f4_Model *model = new f4_Model();
    5656        res = model->buildFromF4(in, using_checkpoints);
    5757        if (GENOPER_OK != res) return SString();  // oops
     
    126126
    127127
    128 f4_Cell * f4_Model::getStick(f4_Cell * C)
     128f4_Cell* f4_Model::getStick(f4_Cell *C)
    129129{
    130130        if (T_STICK4 == C->type) return C;
     
    142142
    143143/// updated by Macko to follow new SDK standards (no more neuroitems)
    144 int f4_Model::buildModelRec(f4_Cell * C)
     144int f4_Model::buildModelRec(f4_Cell *C)
    145145{
    146146        int partidx;
     
    192192                        // adjust mass/vol of first endpoint
    193193                        jj_p1_refno = C->dadlink->p2_refno;
    194                         Part * p1 = getPart(jj_p1_refno);
     194                        Part *p1 = getPart(jj_p1_refno);
    195195                        p1->mass += 1.0;
    196196                        //      p1->volume += 1.0/C->P.mass;
     
    230230        if (C->type == T_NEURON4) ///<this case was updated by MacKo
    231231        {
    232                 const char * nclass = C->neuclass->name.c_str();
     232                const char* nclass = C->neuclass->name.c_str();
    233233                int partno, jointno;
    234234                if (C->neuclass->getPreferredLocation() == 0)
     
    298298                        if (C->links[j]->from == NULL)
    299299                        {
    300                                 const char * nclass = C->links[j]->t.c_str();
    301                                 char * temp = (char*)C->links[j]->t.c_str();
    302                                 NeuroClass * sensortest = GenoOperators::parseNeuroClass(temp);
     300                                const char* nclass = C->links[j]->t.c_str();
     301                                char* temp = (char*)C->links[j]->t.c_str();
     302                                NeuroClass *sensortest = GenoOperators::parseNeuroClass(temp);
    303303                                //backward compatibility for G*TS
    304304                                if (C->links[j]->t == "*" || C->links[j]->t == "S" || C->links[j]->t == "T")
  • cpp/frams/genetics/f4/conv_f4.h

    r760 r774  
    3232         * @return generated f0 genotype
    3333         */
    34         SString convert(SString &in, MultiMap * map, bool using_checkpoints);
     34        SString convert(SString &in, MultiMap *map, bool using_checkpoints);
    3535};
    3636
     
    5757         * @return generated approximate f1 genotype
    5858         */
    59         SString convert(SString &in, MultiMap * map, bool using_checkpoints);
     59        SString convert(SString &in, MultiMap *map, bool using_checkpoints);
    6060};
    6161
     
    8282        void     toF1Geno(SString &out);       // output to f1 format, approximation
    8383private:
    84         f4_Cells * cells;
    85         int        buildModelRec(f4_Cell * ndad);
     84        f4_Cells *cells;
     85        int        buildModelRec(f4_Cell *ndad);
    8686        /**
    8787         * Get a cell which is a stick, by traversing dadlinks.
    8888         */
    89         f4_Cell *  getStick(f4_Cell * C);
     89        f4_Cell* getStick(f4_Cell *C);
    9090        int        error;
    9191        int        errorpos;
  • cpp/frams/genetics/f4/f4_general.cpp

    r770 r774  
    1717#endif
    1818
    19 void rolling_dec(double * v)
     19void rolling_dec(double *v)
    2020{
    2121        *v -= 0.7853;  // 0.7853981  45 degrees
    2222}
    2323
    24 void rolling_inc(double * v)
     24void rolling_inc(double *v)
    2525{
    2626        *v += 0.7853;  // 0.7853981  45 degrees
    2727}
    2828
    29 int scanrec(const char * s, unsigned int slen, char stopchar)
     29int scanrec(const char* s, unsigned int slen, char stopchar)
    3030{
    3131        unsigned int i = 0;
     
    6363
    6464f4_Cell::f4_Cell(int nname,
    65         f4_Cell * ndad, int nangle, GeneProps newP)
     65        f4_Cell *ndad, int nangle, GeneProps newP)
    6666{
    6767        name = nname;
     
    8484        //OM = Orient_1;
    8585        ctrl = 0;
    86         state = 0;
    8786        inertia = 0.8;
    8887        force = 0.04;
     
    102101                if (T_NEURON4 == ndad->type)
    103102                {
    104                         state = ndad->state;
    105103                        inertia = ndad->inertia;
    106104                        force = ndad->force;
     
    114112
    115113
    116 f4_Cell::f4_Cell(f4_Cells * nO, int nname, f4_node * ngeno, f4_node * ngcur, f4_Cell * ndad, int nangle, GeneProps newP)
     114f4_Cell::f4_Cell(f4_Cells *nO, int nname, f4_node *ngeno, f4_node *ngcur, f4_Cell *ndad, int nangle, GeneProps newP)
    117115{
    118116        name = nname;
     
    138136        //OM = Orient_1;
    139137        ctrl = 0;
    140         state = 0;
    141138        inertia = 0.8;
    142139        force = 0.04;
     
    156153                if (T_NEURON4 == ndad->type)
    157154                {
    158                         state = ndad->state;
    159155                        inertia = ndad->inertia;
    160156                        force = ndad->force;
     
    228224                                        GeneProps newP = P;
    229225                                        newP.propagateAlong(false);
    230                                         f4_Cell * tmp = new f4_Cell(org, org->nc, genot, gcur->child2, this, commacount, newP);
     226                                        f4_Cell *tmp = new f4_Cell(org, org->nc, genot, gcur->child2, this, commacount, newP);
    231227                                        tmp->repeat = repeat;
    232228                                        repeat.clear();
     
    246242                                        tmp->neuclass = neuclass;
    247243                                        // duplicate links
    248                                         f4_CellLink * ll;
     244                                        f4_CellLink *ll;
    249245                                        for (int i = 0; i < nolink; i++)
    250246                                        {
     
    640636
    641637
    642 int f4_Cell::addlink(f4_Cell * nfrom, double nw, string nt)
     638int f4_Cell::addlink(f4_Cell *nfrom, double nw, string nt)
    643639{
    644640        // if incoming neuron does not produce output, return error
     
    725721
    726722
    727 f4_CellLink::f4_CellLink(f4_Cell * nfrom, double nw, string nt)
     723f4_CellLink::f4_CellLink(f4_Cell *nfrom, double nw, string nt)
    728724{
    729725        from = nfrom;
     
    734730
    735731
    736 f4_Cells::f4_Cells(f4_node * genome, int nrepair)
     732f4_Cells::f4_Cells(f4_node *genome, int nrepair)
    737733{
    738734        // create ancestor cell
     
    862858
    863859
    864 void f4_Cells::addCell(f4_Cell * newcell)
     860void f4_Cells::addCell(f4_Cell *newcell)
    865861{
    866862        if (nc >= MAX4CELLS - 1)
     
    880876}
    881877
    882 void f4_Cells::setRepairRemove(int nerrpos, f4_node * rem)
     878void f4_Cells::setRepairRemove(int nerrpos, f4_node *rem)
    883879{
    884880        if (!repair)
     
    896892}
    897893
    898 int f4_Cells::setRepairInsert(int nerrpos, f4_node * parent, f4_node * insert)
     894int f4_Cells::setRepairInsert(int nerrpos, f4_node *parent, f4_node *insert)
    899895{
    900896        if (!repair)
     
    915911}
    916912
    917 void f4_Cells::repairGeno(f4_node * geno, int whichchild)
     913void f4_Cells::repairGeno(f4_node *geno, int whichchild)
    918914{
    919915        // assemble repaired geno, if the case
     
    921917        if ((NULL == repair_remove) && (NULL == repair_insert)) return;
    922918        // traverse genotype tree, remove / insert node
    923         f4_node * g2;
     919        f4_node *g2;
    924920        if (1 == whichchild) g2 = geno->child;
    925921        else             g2 = geno->child2;
     
    928924        if (g2 == repair_remove)
    929925        {
    930                 f4_node * oldgeno;
     926                f4_node *oldgeno;
    931927                geno->removeChild(g2);
    932928                if (g2->child)
     
    973969{
    974970        int i, j, ccount;
    975         f4_Cell * thisti;
    976         f4_Cell * thneu;
     971        f4_Cell *thisti;
     972        f4_Cell *thneu;
    977973        char buf[200];
    978974
     
    11171113}
    11181114
    1119 f4_node::f4_node(char nname, f4_node * nparent, int npos)
     1115f4_node::f4_node(char nname, f4_node *nparent, int npos)
    11201116{
    11211117        name = nname;
     
    11381134}
    11391135
    1140 int f4_node::addChild(f4_node * nchi)
     1136int f4_node::addChild(f4_node *nchi)
    11411137{
    11421138        if (NULL == child)
     
    11531149}
    11541150
    1155 int f4_node::removeChild(f4_node * nchi)
     1151int f4_node::removeChild(f4_node *nchi)
    11561152{
    11571153        if (nchi == child2)
     
    11901186}
    11911187
    1192 f4_node * f4_node::ordNode(int n)
     1188f4_node* f4_node::ordNode(int n)
    11931189{
    11941190        int n1;
     
    12101206}
    12111207
    1212 f4_node * f4_node::randomNode()
     1208f4_node* f4_node::randomNode()
    12131209{
    12141210        int n = count();
     
    12171213}
    12181214
    1219 f4_node * f4_node::randomNodeWithSize(int mn, int mx)
     1215f4_node* f4_node::randomNodeWithSize(int mn, int mx)
    12201216{
    12211217        // try random nodes, and accept if size in range
    12221218        // limit to maxlim tries
    12231219        int i, n, maxlim;
    1224         f4_node * nod = NULL;
     1220        f4_node *nod = NULL;
    12251221        maxlim = count();
    12261222        for (i = 0; i < maxlim; i++)
     
    12851281                {
    12861282                        char *temp = (char*)name.c_str();
    1287                         NeuroClass * nc = GenoOperators::parseNeuroClass(temp);
     1283                        NeuroClass *nc = GenoOperators::parseNeuroClass(temp);
    12881284                        if (nc != NULL)
    12891285                        {
     
    13261322}
    13271323
    1328 f4_node * f4_node::duplicate()
    1329 {
    1330         f4_node * copy;
     1324f4_node* f4_node::duplicate()
     1325{
     1326        f4_node *copy;
    13311327        copy = new f4_node(*this);
    13321328        copy->parent = NULL;  // set later
     
    13561352// scan genotype string and build tree
    13571353// return >1 for error (errorpos)
    1358 int f4_processrec(const char * genot, unsigned pos0, f4_node * parent)
     1354int f4_processrec(const char* genot, unsigned pos0, f4_node *parent)
    13591355{
    13601356        int i, j, res, t;
     
    13631359        double w;
    13641360        unsigned gpos, oldpos;
    1365         f4_node * node1, *par;
     1361        f4_node *node1, *par;
    13661362        unsigned beginindex;
    13671363        string neutype = "";
     
    14091405                        // repetition marker, 1 by default
    14101406                        ExtValue val;
    1411                         const char * end = val.parseNumber(genot + gpos + 1, ExtPType::TInt);
     1407                        const char* end = val.parseNumber(genot + gpos + 1, ExtPType::TInt);
    14121408                        if (end == NULL) i = 1;
    14131409                        else i = val.getInt();
     
    14991495                        gpos += 2; //skipping "N:"
    15001496                        beginindex = gpos;
    1501                         char * end = (char*)genot + beginindex;
     1497                        char* end = (char*)genot + beginindex;
    15021498                        GenoOperators::parseNeuroClass(end);
    15031499                        gpos += end - genot - beginindex;
     
    16021598        if (*parser != '[') return NULL;
    16031599        parser++;
    1604         char * p = (char*)parser;
     1600        char* p = (char*)parser;
    16051601        if (GenoOperators::parseNeuroClass(p) == NULL) return NULL;
    16061602        neutype = string(parser, (const char *)p);
     
    16171613}
    16181614
    1619 f4_node * f4_processtree(const char * geno)
    1620 {
    1621         f4_node * root;
     1615f4_node* f4_processtree(const char* geno)
     1616{
     1617        f4_node *root;
    16221618        int res;
    16231619        root = new f4_node();
     
    16281624                if (root->child)
    16291625                {
    1630                 char * buf = (char*)malloc(300);
     1626                char* buf = (char*)malloc(300);
    16311627                DB(printf("(%d) ", root->child->count());)
    16321628                        buf[0] = 0;
  • cpp/frams/genetics/f4/f4_general.h

    r767 r774  
    2121 * @param v pointer to the decremented value
    2222 */
    23 void rolling_dec(double * v);
     23void rolling_dec(double *v);
    2424
    2525/**
     
    2727 * @param v pointer to the incremented value
    2828 */
    29 void rolling_inc(double * v);
     29void rolling_inc(double *v);
    3030
    3131class f4_node;   // later
     
    5151 * @return 1 if end of string was reached, or position of found character in sequence
    5252 */
    53 int scanrec(const char * s, unsigned int slen, char stopchar);
     53int scanrec(const char* s, unsigned int slen, char stopchar);
    5454
    5555
     
    221221
    222222        int          ctrl;             ///<neuron type
    223         double       state;            ///<state of neuron
    224223        double       inertia;          ///<inertia of neuron
    225224        double       force;            ///<force of neuron
     
    253252
    254253
    255 // a collection of cells, like Organism, for developmental encoding
    256254/**
    257255 * A class representing a collection of cells. It is equivalent to an organism.
     
    295293         * Performs a single step of organism development. It runs each active cell
    296294         * in the organism.
    297          * @return 0 if all cells are developed, 1 otherwise
     295         * @return 0 if all cells are developed, or 1 otherwise
    298296         */
    299297        int  onestep();
     
    336334         * @param parent the parent of a new element
    337335         * @param insert the element to be inserted
    338          * @return 0 if repair can be performed, -1 otherwise (the repair flag wasn't set in constructor)
     336         * @return 0 if repair can be performed, or -1 otherwise because the repair flag wasn't set in the constructor
    339337         */
    340338        int  setRepairInsert(int nerrpos, f4_node *parent, f4_node *insert);
     
    432430         * @return pointer to the nth subnode or NULL if not found
    433431         */
    434         f4_node * ordNode(int n);
     432        f4_node* ordNode(int n);
    435433
    436434        /**
     
    438436         * @return random subnode
    439437         */
    440         f4_node * randomNode();
     438        f4_node* randomNode();
    441439
    442440        /**
     
    446444         * @return a random subnode with a given size or NULL
    447445         */
    448         f4_node * randomNodeWithSize(int min, int max);
     446        f4_node* randomNodeWithSize(int min, int max);
    449447
    450448        /**
     
    458456         * @return pointer to a tree copy
    459457         */
    460         f4_node * duplicate();
     458        f4_node* duplicate();
    461459
    462460        /**
     
    468466};
    469467
    470 // convert f4 geno string to tree structure (internal)
    471 
    472468/**
    473469 * The main function for converting a string of f4 encoding to a tree structure. Prepares
     
    476472 * @return a pointer to the f4_node object representing the f4 tree root
    477473 */
    478 f4_node * f4_processtree(const char *geno);
     474f4_node* f4_processtree(const char *geno);
    479475
    480476/**
     
    488484 * @param genot the string holding all the genotype
    489485 * @param pos0 the current position of processing in string
    490  * @param current parent of the analysed branch of the genotype
     486 * @param parent current parent of the analysed branch of the genotype
    491487 * @return 0 if processing was successful, otherwise returns the position of an error in the genotype
    492488 */
     
    504500 * @return the pointer to the first character in string after connection definition
    505501 */
    506 const char * parseConnection(const char *fragm, int &relfrom, double &weight);
     502const char *parseConnection(const char *fragm, int &relfrom, double &weight);
    507503
    508504/**
     
    518514 * @return the pointer to the first character in string after the connection definition
    519515 */
    520 const char * parseConnectionWithNeuron(const char *fragm, string &neutype, double &weight);
     516const char *parseConnectionWithNeuron(const char *fragm, string &neutype, double &weight);
    521517
    522518#endif
  • cpp/frams/genetics/f4/oper_f4.cpp

    r773 r774  
    6767}
    6868
    69 int Geno_f4::ValidateRec(f4_node * geno, int retrycount) const
     69int Geno_f4::ValidateRec(f4_node *geno, int retrycount) const
    7070{
    7171        // ! the genotype is geno->child (not geno) !
     
    113113
    114114
    115 int Geno_f4::checkValidity(const char * geno, const char *genoname)
     115int Geno_f4::checkValidity(const char* geno, const char *genoname)
    116116{
    117117        f4_node root;
     
    164164                        {
    165165                                // make neuron
    166                                 NeuroClass * rndclass = GenoOperators::getRandomNeuroClass();
     166                                NeuroClass *rndclass = GenoOperators::getRandomNeuroClass();
    167167                                if (rndclass == NULL)
    168168                                {
     
    177177                                                for (int i = 0; i < g->count(); i++)
    178178                                                {
    179                                                         f4_node * gcur = g->ordNode(i);
    180                                                         char * temp = (char*)gcur->name.c_str();
    181                                                         NeuroClass * neuclass = GenoOperators::parseNeuroClass(temp);
     179                                                        f4_node *gcur = g->ordNode(i);
     180                                                        char* temp = (char*)gcur->name.c_str();
     181                                                        NeuroClass *neuclass = GenoOperators::parseNeuroClass(temp);
    182182                                                        if (neuclass != NULL)
    183183                                                        {
     
    215215                {
    216216                        // add link
    217                         f4_node * par = n1->parent;
    218                         char * temp = (char*)par->name.c_str();
    219                         NeuroClass * neuclass = GenoOperators::parseNeuroClass(temp);
     217                        f4_node *par = n1->parent;
     218                        char* temp = (char*)par->name.c_str();
     219                        NeuroClass *neuclass = GenoOperators::parseNeuroClass(temp);
    220220                        if (neuclass != NULL)
    221221                        {
     
    456456
    457457// change a [ node
    458 void Geno_f4::linkNodeChangeRandom(f4_node * nn, int neuid, std::vector<NeuroClass*> neulist) const      //rewritten by M.K. - should work as before (not tested)
     458void Geno_f4::linkNodeChangeRandom(f4_node *nn, int neuid, std::vector<NeuroClass*> neulist) const      //rewritten by M.K. - should work as before (not tested)
    459459{
    460460        double probs[3] = { 0.1, 0.3, 0.6 };
     
    495495
    496496// make a random : node
    497 void Geno_f4::nparNodeMakeRandom(f4_node * nn) const
     497void Geno_f4::nparNodeMakeRandom(f4_node *nn) const
    498498{
    499499        int sign = (int)(2.0f * rnd01);
     
    505505
    506506// change a repeat # node
    507 void Geno_f4::repeatNodeChangeRandom(f4_node * nn) const
     507void Geno_f4::repeatNodeChangeRandom(f4_node *nn) const
    508508{
    509509        int count;
     
    526526        // ! the genotype is g->child (not g) !
    527527        int i, res;
    528         f4_node * gcopy = NULL;
     528        f4_node *gcopy = NULL;
    529529        // try this max 20 times:
    530530        //   copy, mutate, then validate
     
    600600
    601601// convert to tree
    602 f4_node * root;
     602f4_node *root;
    603603root = new f4_node();
    604604res = f4_processrec(g, 0, root);
     
    654654
    655655
    656 int Geno_f4::CrossOverOne(f4_node * g1, f4_node * g2, float chg) const
     656int Geno_f4::CrossOverOne(f4_node *g1, f4_node *g2, float chg) const
    657657{
    658658        // ! the genotypes are g1->child and g2->child (not g1 g2) !
     
    660660        int smin, smax;
    661661        float size;
    662         f4_node * n1, *n2, *n1p, *n2p;
     662        f4_node *n1, *n2, *n1p, *n2p;
    663663
    664664        // determine desired size
  • cpp/frams/genetics/f4/oper_f4.h

    r760 r774  
    6363         * @return GENOOPER_OK if genotype is valid, GENOPER_REPAIR if genotype can be repaired, GENOPER_OPFAIL if genotype can't be repaired
    6464         */
    65         int  ValidateRec(f4_node * geno, int retrycount) const;
     65        int  ValidateRec(f4_node *geno, int retrycount) const;
    6666
    6767        /**
     
    9595         * @param neulist list of genotype neuron classes
    9696         */
    97         void linkNodeMakeRandom(f4_node * nn, int neuid, std::vector<NeuroClass*> neulist) const;
     97        void linkNodeMakeRandom(f4_node *nn, int neuid, std::vector<NeuroClass*> neulist) const;
    9898
    9999        /**
     
    104104         * @param neulist list of genotype neuron classes
    105105         */
    106         void linkNodeChangeRandom(f4_node * nn, int neuid, std::vector<NeuroClass*> neulist) const;
     106        void linkNodeChangeRandom(f4_node *nn, int neuid, std::vector<NeuroClass*> neulist) const;
    107107
    108108        /**
     
    124124         * @return GENOPER_OK if performed successful mutation, GENOPER_FAIL otherwise
    125125         */
    126         int  MutateOneValid(f4_node * &g, int &method) const;
     126        int  MutateOneValid(f4_node *&g, int &method) const;
    127127
    128128        /**
Note: See TracChangeset for help on using the changeset viewer.