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]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.