Changeset 774 for cpp/frams/genetics/f4/f4_general.cpp
- Timestamp:
- 04/11/18 01:16:08 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_general.cpp
r770 r774 17 17 #endif 18 18 19 void rolling_dec(double * 19 void rolling_dec(double *v) 20 20 { 21 21 *v -= 0.7853; // 0.7853981 45 degrees 22 22 } 23 23 24 void rolling_inc(double * 24 void rolling_inc(double *v) 25 25 { 26 26 *v += 0.7853; // 0.7853981 45 degrees 27 27 } 28 28 29 int scanrec(const char 29 int scanrec(const char* s, unsigned int slen, char stopchar) 30 30 { 31 31 unsigned int i = 0; … … 63 63 64 64 f4_Cell::f4_Cell(int nname, 65 f4_Cell * 65 f4_Cell *ndad, int nangle, GeneProps newP) 66 66 { 67 67 name = nname; … … 84 84 //OM = Orient_1; 85 85 ctrl = 0; 86 state = 0;87 86 inertia = 0.8; 88 87 force = 0.04; … … 102 101 if (T_NEURON4 == ndad->type) 103 102 { 104 state = ndad->state;105 103 inertia = ndad->inertia; 106 104 force = ndad->force; … … 114 112 115 113 116 f4_Cell::f4_Cell(f4_Cells * nO, int nname, f4_node * ngeno, f4_node * ngcur, f4_Cell *ndad, int nangle, GeneProps newP)114 f4_Cell::f4_Cell(f4_Cells *nO, int nname, f4_node *ngeno, f4_node *ngcur, f4_Cell *ndad, int nangle, GeneProps newP) 117 115 { 118 116 name = nname; … … 138 136 //OM = Orient_1; 139 137 ctrl = 0; 140 state = 0;141 138 inertia = 0.8; 142 139 force = 0.04; … … 156 153 if (T_NEURON4 == ndad->type) 157 154 { 158 state = ndad->state;159 155 inertia = ndad->inertia; 160 156 force = ndad->force; … … 228 224 GeneProps newP = P; 229 225 newP.propagateAlong(false); 230 f4_Cell * 226 f4_Cell *tmp = new f4_Cell(org, org->nc, genot, gcur->child2, this, commacount, newP); 231 227 tmp->repeat = repeat; 232 228 repeat.clear(); … … 246 242 tmp->neuclass = neuclass; 247 243 // duplicate links 248 f4_CellLink * 244 f4_CellLink *ll; 249 245 for (int i = 0; i < nolink; i++) 250 246 { … … 640 636 641 637 642 int f4_Cell::addlink(f4_Cell * 638 int f4_Cell::addlink(f4_Cell *nfrom, double nw, string nt) 643 639 { 644 640 // if incoming neuron does not produce output, return error … … 725 721 726 722 727 f4_CellLink::f4_CellLink(f4_Cell * 723 f4_CellLink::f4_CellLink(f4_Cell *nfrom, double nw, string nt) 728 724 { 729 725 from = nfrom; … … 734 730 735 731 736 f4_Cells::f4_Cells(f4_node * 732 f4_Cells::f4_Cells(f4_node *genome, int nrepair) 737 733 { 738 734 // create ancestor cell … … 862 858 863 859 864 void f4_Cells::addCell(f4_Cell * 860 void f4_Cells::addCell(f4_Cell *newcell) 865 861 { 866 862 if (nc >= MAX4CELLS - 1) … … 880 876 } 881 877 882 void f4_Cells::setRepairRemove(int nerrpos, f4_node * 878 void f4_Cells::setRepairRemove(int nerrpos, f4_node *rem) 883 879 { 884 880 if (!repair) … … 896 892 } 897 893 898 int f4_Cells::setRepairInsert(int nerrpos, f4_node * parent, f4_node *insert)894 int f4_Cells::setRepairInsert(int nerrpos, f4_node *parent, f4_node *insert) 899 895 { 900 896 if (!repair) … … 915 911 } 916 912 917 void f4_Cells::repairGeno(f4_node * 913 void f4_Cells::repairGeno(f4_node *geno, int whichchild) 918 914 { 919 915 // assemble repaired geno, if the case … … 921 917 if ((NULL == repair_remove) && (NULL == repair_insert)) return; 922 918 // traverse genotype tree, remove / insert node 923 f4_node * 919 f4_node *g2; 924 920 if (1 == whichchild) g2 = geno->child; 925 921 else g2 = geno->child2; … … 928 924 if (g2 == repair_remove) 929 925 { 930 f4_node * 926 f4_node *oldgeno; 931 927 geno->removeChild(g2); 932 928 if (g2->child) … … 973 969 { 974 970 int i, j, ccount; 975 f4_Cell * 976 f4_Cell * 971 f4_Cell *thisti; 972 f4_Cell *thneu; 977 973 char buf[200]; 978 974 … … 1117 1113 } 1118 1114 1119 f4_node::f4_node(char nname, f4_node * 1115 f4_node::f4_node(char nname, f4_node *nparent, int npos) 1120 1116 { 1121 1117 name = nname; … … 1138 1134 } 1139 1135 1140 int f4_node::addChild(f4_node * 1136 int f4_node::addChild(f4_node *nchi) 1141 1137 { 1142 1138 if (NULL == child) … … 1153 1149 } 1154 1150 1155 int f4_node::removeChild(f4_node * 1151 int f4_node::removeChild(f4_node *nchi) 1156 1152 { 1157 1153 if (nchi == child2) … … 1190 1186 } 1191 1187 1192 f4_node 1188 f4_node* f4_node::ordNode(int n) 1193 1189 { 1194 1190 int n1; … … 1210 1206 } 1211 1207 1212 f4_node 1208 f4_node* f4_node::randomNode() 1213 1209 { 1214 1210 int n = count(); … … 1217 1213 } 1218 1214 1219 f4_node 1215 f4_node* f4_node::randomNodeWithSize(int mn, int mx) 1220 1216 { 1221 1217 // try random nodes, and accept if size in range 1222 1218 // limit to maxlim tries 1223 1219 int i, n, maxlim; 1224 f4_node * 1220 f4_node *nod = NULL; 1225 1221 maxlim = count(); 1226 1222 for (i = 0; i < maxlim; i++) … … 1285 1281 { 1286 1282 char *temp = (char*)name.c_str(); 1287 NeuroClass * 1283 NeuroClass *nc = GenoOperators::parseNeuroClass(temp); 1288 1284 if (nc != NULL) 1289 1285 { … … 1326 1322 } 1327 1323 1328 f4_node 1329 { 1330 f4_node * 1324 f4_node* f4_node::duplicate() 1325 { 1326 f4_node *copy; 1331 1327 copy = new f4_node(*this); 1332 1328 copy->parent = NULL; // set later … … 1356 1352 // scan genotype string and build tree 1357 1353 // return >1 for error (errorpos) 1358 int f4_processrec(const char * genot, unsigned pos0, f4_node *parent)1354 int f4_processrec(const char* genot, unsigned pos0, f4_node *parent) 1359 1355 { 1360 1356 int i, j, res, t; … … 1363 1359 double w; 1364 1360 unsigned gpos, oldpos; 1365 f4_node * 1361 f4_node *node1, *par; 1366 1362 unsigned beginindex; 1367 1363 string neutype = ""; … … 1409 1405 // repetition marker, 1 by default 1410 1406 ExtValue val; 1411 const char 1407 const char* end = val.parseNumber(genot + gpos + 1, ExtPType::TInt); 1412 1408 if (end == NULL) i = 1; 1413 1409 else i = val.getInt(); … … 1499 1495 gpos += 2; //skipping "N:" 1500 1496 beginindex = gpos; 1501 char 1497 char* end = (char*)genot + beginindex; 1502 1498 GenoOperators::parseNeuroClass(end); 1503 1499 gpos += end - genot - beginindex; … … 1602 1598 if (*parser != '[') return NULL; 1603 1599 parser++; 1604 char 1600 char* p = (char*)parser; 1605 1601 if (GenoOperators::parseNeuroClass(p) == NULL) return NULL; 1606 1602 neutype = string(parser, (const char *)p); … … 1617 1613 } 1618 1614 1619 f4_node * f4_processtree(const char* geno)1620 { 1621 f4_node * 1615 f4_node* f4_processtree(const char* geno) 1616 { 1617 f4_node *root; 1622 1618 int res; 1623 1619 root = new f4_node(); … … 1628 1624 if (root->child) 1629 1625 { 1630 char 1626 char* buf = (char*)malloc(300); 1631 1627 DB(printf("(%d) ", root->child->count());) 1632 1628 buf[0] = 0;
Note: See TracChangeset
for help on using the changeset viewer.