Changeset 1249 for cpp/frams/genetics/f4/f4_conv.cpp
- Timestamp:
- 05/21/23 23:16:51 (18 months ago)
- File:
-
- 1 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();
Note: See TracChangeset
for help on using the changeset viewer.