Changeset 1249
- Timestamp:
- 05/21/23 23:16:51 (18 months ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_conv.cpp
r1240 r1249 124 124 // reset recursive traverse flags 125 125 for (int i = 0; i < cells->cell_count; i++) 126 cells->C[i]->rec ProcessedFlag = 0;126 cells->C[i]->recurProcessedFlag = false; 127 127 128 128 open(using_checkpoints); // begin model build … … 131 131 for (int i = 0; i < cells->cell_count; i++) 132 132 { 133 int res = buildModelRec (cells->C[i]);133 int res = buildModelRecur(cells->C[i]); 134 134 if (res) 135 135 { … … 166 166 167 167 168 int f4_Model::buildModelRec(f4_Cell *C) 169 { 170 int partidx; 171 int j, res; 172 MultiRange range; 173 174 if (C->recProcessedFlag) 168 int f4_Model::buildModelRecur(f4_Cell *C) 169 { 170 if (C->recurProcessedFlag) 175 171 // already processed 176 172 return 0; 177 173 178 174 // mark it processed 179 C->rec ProcessedFlag = 1;175 C->recurProcessedFlag = true; 180 176 181 177 // make sure parent is a stick 182 if ( NULL != C->dadlink)178 if (C->dadlink != NULL) 183 179 if (C->dadlink->type != CELL_STICK) 184 180 { … … 187 183 188 184 // make sure its parent is processed first 189 if ( NULL != C->dadlink)190 { 191 res = buildModelRec(C->dadlink);185 if (C->dadlink != NULL) 186 { 187 int res = buildModelRecur(C->dadlink); 192 188 if (res) return res; 193 189 } 194 190 195 191 char tmpLine[100]; 196 197 range = C->genoRange; 192 MultiRange range = C->genoRange; 193 198 194 if (C->type == CELL_STICK) 199 195 { … … 208 204 //C->firstend.x, C->firstend.y, C->firstend.z 209 205 ); 210 partidx= addFromString(PartType, tmpLine, &range);211 if ( partidx< 0) return -1;206 jj_p1_refno = addFromString(PartType, tmpLine, &range); 207 if (jj_p1_refno < 0) return -1; 212 208 this->checkpoint(); 213 jj_p1_refno = partidx;214 209 } 215 210 else { … … 225 220 /*"vol=" 1.0/C->P.mass,*/ C->P.friction, C->P.ingestion, C->P.assimilation 226 221 ); 227 partidx = addFromString(PartType, tmpLine, &range); 228 if (partidx < 0) return -2; 229 C->p2_refno = partidx; 222 C->p2_refno = addFromString(PartType, tmpLine, &range); 223 if (C->p2_refno < 0) return -2; 230 224 231 225 // new joint object … … 245 239 C->P.stamina 246 240 ); 247 partidx= addFromString(JointType, tmpLine, &range);248 if ( partidx< 0) return -13;241 C->joint_refno = addFromString(JointType, tmpLine, &range); 242 if (C->joint_refno < 0) return -13; 249 243 this->checkpoint(); 250 C->joint_refno = partidx;251 244 } 252 245 … … 254 247 { 255 248 const char* nclass = C->neuclass->name.c_str(); 256 int partno, jointno;257 249 if (C->neuclass->getPreferredLocation() == 0) 258 250 { 259 if (strcmp(nclass, "N") == 0) 260 { 261 partno = C->dadlink->p2_refno; 262 if ((partno < 0) || (partno >= getPartCount())) return -21; 263 else sprintf(tmpLine, "p=%d,d=\"N:in=%g,fo=%g,si=%g\"", partno, C->inertia, C->force, C->sigmo); 264 } 251 if (strcmp(nclass, "N") == 0) //special case just to specify the only neuron properties supported by f4, i.e., the properties for neuron class 'N' 252 sprintf(tmpLine, "d=\"N:in=%g,fo=%g,si=%g\"", C->inertia, C->force, C->sigmo); 265 253 else 266 {267 254 sprintf(tmpLine, "d=\"%s\"", nclass); 268 } 269 partidx= addFromString(NeuronType, tmpLine, &range);270 if ( partidx< 0) return -22;255 256 C->neuro_refno = addFromString(NeuronType, tmpLine, &range); 257 if (C->neuro_refno < 0) return -22; 271 258 this->checkpoint(); 272 C->neuro_refno = partidx;273 259 } 274 260 else if (C->neuclass->getPreferredLocation() == 1) // attached to Part or have no required attachment - also part 275 261 { 276 partno = C->dadlink->p2_refno;262 int partno = C->dadlink->p2_refno; 277 263 if ((partno < 0) || (partno >= getPartCount())) return -21; 278 264 279 if (strcmp(nclass, "N") == 0) 280 sprintf(tmpLine, "p=%d,d=\"N:in=%g,fo=%g,si=%g\"", partno, C->inertia, C->force, C->sigmo); 281 else 282 sprintf(tmpLine, "p=%d,d=\"%s\"", partno, nclass); 283 284 partidx = addFromString(NeuronType, tmpLine, &range); 285 if (partidx < 0) return -22; 265 sprintf(tmpLine, "p=%d,d=\"%s\"", partno, nclass); 266 267 C->neuro_refno = addFromString(NeuronType, tmpLine, &range); 268 if (C->neuro_refno < 0) return -22; 286 269 this->checkpoint(); 287 C->neuro_refno = partidx;288 270 } 289 271 else // attached to Joint, assume there are only three possibilities of getPreferredLocation() 290 272 { 291 jointno = C->dadlink->joint_refno;273 int jointno = C->dadlink->joint_refno; 292 274 293 275 if (strcmp(nclass, "@") == 0) 294 276 sprintf(tmpLine, "j=%d,d=\"@:p=%g\"", jointno, C->P.muscle_power); 295 277 else if (strcmp(nclass, "|") == 0) 296 sprintf(tmpLine, "j=%d,d=\"|:p=%g,r=%g\"", jointno, C->P.muscle_power, C->mz); 278 { 279 sprintf(tmpLine, "j=%d,d=\"|:p=%g,r=%g\"", jointno, C->P.muscle_power, C->dadlink->P.muscle_bend_range); //Macko 2023-05 change: we take muscle_bend_range from dadlink, not from C, because we also assign this neuron to C->dadlink->joint_refno. Without this, for example in /*4*/<<X><<<<X>N:|>X>X>X>X the muscle is attached to the junction with 3 sticks, but gets range=33% as in a four-stick junction. f1 correctly sets range=0.5 for the analogous phenotype: X(X[|],X(X,X,X)) 280 } 297 281 else 298 282 sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass); 299 283 300 partidx= addFromString(NeuronType, tmpLine, &range);301 if ( partidx< 0) return -32;284 C->neuro_refno = addFromString(NeuronType, tmpLine, &range); 285 if (C->neuro_refno < 0) return -32; 302 286 this->checkpoint(); 303 287 } 304 C->neuro_refno = partidx; 305 int n_refno = C->neuro_refno; 306 307 for (j = 0; j < C->conns_count; j++) 288 for (int j = 0; j < C->conns_count; j++) 308 289 { 309 290 if (C->conns[j]->from != NULL) 310 buildModelRec (C->conns[j]->from);291 buildModelRecur(C->conns[j]->from); 311 292 312 293 tmpLine[0] = 0; … … 320 301 if (from >= 0) 321 302 { 322 sprintf(tmpLine, "%d,%d,%g", n_refno, from, C->conns[j]->weight);303 sprintf(tmpLine, "%d,%d,%g", C->neuro_refno, from, C->conns[j]->weight); 323 304 if (addFromString(NeuronConnectionType, tmpLine, &range) < 0) return -35; 324 305 this->checkpoint(); -
cpp/frams/genetics/f4/f4_conv.h
r1238 r1249 83 83 private: 84 84 f4_Cells *cells; 85 int buildModelRec (f4_Cell *ndad);85 int buildModelRecur(f4_Cell *ndad); 86 86 /** 87 87 * Get a cell which is a stick, by traversing dadlinks. -
cpp/frams/genetics/f4/f4_general.cpp
r1241 r1249 12 12 #include <frams/model/model.h> // for min and max attributes 13 13 #include <common/nonstd_math.h> 14 #include <algorithm> // std::min, std::max 14 15 15 16 #ifdef DMALLOC … … 46 47 anglepos = nangle; 47 48 commacount = 0; 48 childcount = 0;49 stickchildcount = 0; 49 50 P = newP; 50 51 rolling = 0; … … 65 66 //firstend = ndad->lastend; 66 67 //OM = ndad->OM; 67 ndad-> childcount++;68 ndad->stickchildcount++; 68 69 } 69 70 if (ndad->type == CELL_NEURON) … … 76 77 // adjust lastend 77 78 //lastend = firstend + ((Orient)OM * (Pt3D(1,0,0) * P.len)); 78 mz= 1;79 P.muscle_bend_range = 1; 79 80 } 80 81 … … 96 97 anglepos = nangle; 97 98 commacount = 0; 98 childcount = 0;99 stickchildcount = 0; 99 100 P = newP; 100 101 rolling = 0; … … 115 116 //firstend = ndad->lastend; 116 117 //OM = ndad->OM; 117 ndad-> childcount++;118 ndad->stickchildcount++; 118 119 } 119 120 if (ndad->type == CELL_NEURON) … … 126 127 // adjust lastend 127 128 //lastend = firstend + ((Orient)OM * (Pt3D(1,0,0) * P.len)); 128 mz= 1;129 P.muscle_bend_range = 1; 129 130 } 130 131 … … 548 549 549 550 550 void f4_Cell::adjustRec() 551 { 552 //f4_OrientMat rot; 553 int i; 554 555 if (recProcessedFlag) 551 void f4_Cell::adjustRecur() 552 { 553 if (recurProcessedFlag) 556 554 // already processed 557 555 return; 558 556 559 557 // mark it processed 560 rec ProcessedFlag = 1;558 recurProcessedFlag = true; 561 559 562 560 // make sure its parent is processed first 563 561 if (dadlink != NULL) 564 dadlink->adjustRec ();562 dadlink->adjustRecur(); 565 563 566 564 // count children 567 childcount = 0;568 for (i = 0; i < org->cell_count; i++)565 stickchildcount = 0; 566 for (int i = 0; i < org->cell_count; i++) 569 567 { 570 568 if (org->C[i]->dadlink == this) 571 569 if (org->C[i]->type == CELL_STICK) 572 childcount++; 573 } 570 stickchildcount++; 571 } 572 573 if (dadlink == NULL) 574 P.muscle_bend_range = 1.0; 575 else 576 P.muscle_bend_range = 1.0 / std::max(1, dadlink->stickchildcount); //bend range in f1: 0, 1 (line XX[|]) -> 100%, 2 (Y-shape X(X[|],X)) -> 50%, 3 (cross X(X[|],X,X)) -> 33% 577 //MacKo 2023-05: but shouldn't this formula ^^ also take commacount into consideration, like in f1? 574 578 575 579 if (type == CELL_STICK) … … 580 584 // rotation due to rolling 581 585 xrot = rolling; 582 mz = 1;583 586 } 584 587 else … … 589 592 Padj.propagateAlong(false); 590 593 591 // rot = Orient_1;594 //f4_OrientMat rot = Orient_1; 592 595 593 596 // rotation due to rolling … … 612 615 // rotation in world coordinates 613 616 //OM = ((f4_OrientMat)dadlink->OM) * OM; 614 mz = dadlink->mz / dadlink->childcount;615 617 } 616 618 //Pt3D lastoffset = (Orient)OM * (Pt3D(1,0,0)*P.len); … … 737 739 // reset recursive traverse flags 738 740 for (int i = 0; i < cell_count; i++) 739 C[i]->rec ProcessedFlag = 0;741 C[i]->recurProcessedFlag = false; 740 742 // process every cell 741 743 for (int i = 0; i < cell_count; i++) 742 C[i]->adjustRec ();744 C[i]->adjustRecur(); 743 745 744 746 //DB( printf("Cell simulation done, %d cells. \n", nc); ) 745 747 746 748 if (PRINT_CELLS_DEVELOPMENT) print_cells("Final"); 749 if (PRINT_CELLS_DEVELOPMENT) 750 for (int i = 0; i < cell_count; i++) 751 printf("%d,%d,dad=%d\tstick_children=%d\tcommas=%d\t|:range=%g\n", i, C[i]->nr, C[i]->dadlink ? C[i]->dadlink->nr : -1, C[i]->stickchildcount, C[i]->commacount, C[i]->P.muscle_bend_range); 747 752 748 753 return errorcode; -
cpp/frams/genetics/f4/f4_general.h
r1239 r1249 181 181 * Adjusts properties of stick objects. 182 182 */ 183 void adjustRec ();184 185 int nr; ///<number of cell (seems to be used only in oldf1 converter for neuron connections)183 void adjustRecur(); 184 185 int nr; ///<number of cell (seems to be used only in the approximate f1 converter for neuron connections) 186 186 int type; ///<type 187 187 f4_Cell *dadlink; ///<pointer to cell parent … … 192 192 f4_Node *old_gcur; ///<used externally by f4_Cells::oneStep() to track changes of gcur, i.e., to detect progress in cell development 193 193 repeat_stack repeat; ///<stack holding repetition nodes and counters 194 int recProcessedFlag;///<used during recursive traverse194 bool recurProcessedFlag; ///<used during recursive traverse 195 195 MultiRange genoRange; ///<remember the genotype codes affecting this cell so far 196 196 197 197 GeneProps P; ///<properties 198 198 int anglepos; ///<number of position within dad's children (,) 199 int childcount; ///<number of children199 int stickchildcount; ///<number of children (sticks only) 200 200 int commacount; ///<number of postitions at lastend (>=childcount) 201 201 double rolling; ///<rolling angle ('R') (around x) … … 203 203 double zrot; ///<horizontal rotation angle due to branching (around z) 204 204 205 double mz; ///<freedom in z206 205 int p2_refno; ///<the number of the last end part object, used in f0 207 206 int joint_refno; ///<the number of the joint object, used in f0 208 207 int neuro_refno; ///<the number of the neuro object, used in f0 209 208 210 double inertia; ///<inertia of neuron 211 double force; ///<force of neuron 212 double sigmo; ///<sigmoid of neuron 209 double inertia; ///<inertia of neuron N 210 double force; ///<force of neuron N 211 double sigmo; ///<sigmoid of neuron N 213 212 f4_CellConn *conns[F4_MAX_CELL_INPUTS]; ///<array of neuron connections 214 213 int conns_count; ///<number of connections -
cpp/frams/genetics/geneprops.h
r1247 r1249 98 98 99 99 /** 100 * Contains physical, biological and other properties of 101 * stick, except for rotation. The constructor initializes properties of sticks with102 * default values. In order to change a property of a stick, the executeModifier() method100 * Contains physical, biological and other properties of a Part and a Joint (as handled 101 * by the f1 and f4 encodings), except for rotation. The constructor initializes properties with 102 * default values. In order to change a property, the executeModifier() method 103 103 * should be called. Modification of length, curvedness and twist properties 104 104 * usually affects further sticks, so new sticks should have properties of
Note: See TracChangeset
for help on using the changeset viewer.