Changeset 1231 for cpp/frams/genetics/f4/f4_general.cpp
- Timestamp:
- 05/02/23 01:36:15 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_general.cpp
r1230 r1231 640 640 641 641 642 f4_Cells::f4_Cells(f4_Node *genome, int nrepair) 643 { 644 // create ancestor cell 642 f4_Cells::f4_Cells(f4_Node *genome, bool nrepair) 643 { 645 644 repair = nrepair; 646 645 errorcode = GENOPER_OK; … … 650 649 repair_insert = NULL; 651 650 tmpcel = NULL; 652 f4rootnode = NULL; 651 652 // create ancestor cell 653 653 C[0] = new f4_Cell(this, 0, genome, genome, NULL, 0, GeneProps::standard_values); 654 654 cell_count = 1; … … 656 656 657 657 658 f4_Cells::f4_Cells(SString & genome, int nrepair)659 {660 repair = nrepair;661 errorcode = GENOPER_OK;662 errorpos = -1;663 repair_remove = NULL;664 repair_parent = NULL;665 repair_insert = NULL;666 tmpcel = NULL;667 f4rootnode = NULL;668 669 // transform geno from string to nodes670 f4rootnode = new f4_Node();671 int _ = 0;672 int res = f4_processRecur(genome.c_str(), _, f4rootnode);673 if (res || (f4rootnode->childCount() != 1))674 {675 errorcode = GENOPER_OPFAIL;676 errorpos = -1;677 }678 679 // create ancestor cell680 C[0] = new f4_Cell(this, 0, f4rootnode->child, f4rootnode->child, NULL, 0, GeneProps::standard_values);681 cell_count = 1;682 }683 658 684 659 f4_Cells::~f4_Cells() 685 660 { 686 661 // release cells 687 int i;688 662 if (cell_count) 689 663 { 690 for (i = cell_count - 1; i >= 0; i--)664 for (int i = cell_count - 1; i >= 0; i--) 691 665 delete C[i]; 692 666 cell_count = 0; 693 667 } 694 if (f4rootnode)695 delete f4rootnode;696 668 } 697 669 … … 1130 1102 int f4_Node::childCount() 1131 1103 { 1132 if (child != NULL) 1133 { 1134 if (child2 != NULL) return 2; 1135 else return 1; 1136 } 1137 else 1138 { 1139 if (child2 != NULL) return 1; 1140 else return 0; 1141 } 1104 return int(child != NULL) + int(child2 != NULL); //0, 1 or 2 1142 1105 } 1143 1106 … … 1256 1219 len = out.length(); 1257 1220 if (len > 1) 1258 if (out[len - 1] == '>') { (out.directWrite())[len - 1] = 0; out.endWrite(); }; //Macko 2023-04 TODO "can be omitted", but should we remove it as a rule even in generated genotypes? see if I can somehow detect junk characters after top-level '>' ends properly: /*4*/<X>N:N>whatever1221 if (out[len - 1] == '>') { (out.directWrite())[len - 1] = 0; out.endWrite(); }; //Macko 2023-04 "can be omitted", but it is removed as a rule even in generated genotypes :) 1259 1222 // copy back to string 1260 1223 // if new is longer, reallocate buf … … 1305 1268 while (pos_inout < (int)strlen(genot)) 1306 1269 { 1307 1270 //#define PRINT_PARSING_LOCATION 1308 1271 #ifdef PRINT_PARSING_LOCATION 1309 1272 printf("%s\n", genot); … … 1342 1305 case '#': 1343 1306 { 1344 // repetition marker , 1 by default1345 ExtValue val;1346 const char* end = val.parseNumber(genot + pos_inout + 1, ExtPType::TInt);1347 //TODO end==NULL? -> error!1348 int reps = (end == NULL) ? 1 : val.getInt();1307 // repetition marker 1308 ExtValue reps; 1309 const char* end = reps.parseNumber(genot + pos_inout + 1, ExtPType::TInt); 1310 if (end == NULL) 1311 return pos_inout + 1; //error 1349 1312 f4_Node *node = new f4_Node("#", par, pos_inout); 1350 node->reps = reps ;1313 node->reps = reps.getInt(); 1351 1314 // skip number 1352 1315 pos_inout += end - (genot + pos_inout); … … 1455 1418 } 1456 1419 1420 int f4_process(const char *genot, f4_Node *root) 1421 { 1422 int pos = 0; 1423 int res = f4_processRecur(genot, pos, root); 1424 if (res > 0) 1425 return res; //error 1426 else if (genot[pos] == 0) //parsed until the end - OK! 1427 return 0; 1428 else return pos + 1; //junk, unparsed genes after successful parsing, for example /*4*/<X>N:N>whatever or /*4*/<X>X>>> 1429 } 1430 1457 1431 const char* parseConnection(const char *fragm, int& relfrom, double &weight) 1458 1432 {
Note: See TracChangeset
for help on using the changeset viewer.