Changeset 1227 for cpp/frams/genetics/f4/f4_conv.cpp
- Timestamp:
- 04/27/23 04:04:06 (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_conv.cpp
r1212 r1227 90 90 if (cells) delete cells; 91 91 cells = new f4_Cells(geno, 0); 92 if (GENOPER_OK != cells->get error())93 { 94 error = cells->get error();95 errorpos = cells->get errorpos();92 if (GENOPER_OK != cells->getErrorCode()) 93 { 94 error = cells->getErrorCode(); 95 errorpos = cells->getErrorPos(); 96 96 //delete cells; 97 97 return error; … … 99 99 100 100 cells->simulate(); 101 if (GENOPER_OK != cells->get error())102 { 103 error = cells->get error();104 errorpos = cells->get errorpos();101 if (GENOPER_OK != cells->getErrorCode()) 102 { 103 error = cells->getErrorCode(); 104 errorpos = cells->getErrorPos(); 105 105 return error; 106 106 } 107 107 108 108 // reset recursive traverse flags 109 for (i = 0; i < cells-> nc; i++)109 for (i = 0; i < cells->cell_count; i++) 110 110 cells->C[i]->recProcessedFlag = 0; 111 111 … … 114 114 // process every cell 115 115 int res; 116 for (i = 0; i < cells-> nc; i++)116 for (i = 0; i < cells->cell_count; i++) 117 117 { 118 118 res = buildModelRec(cells->C[i]); 119 119 if (res) 120 120 { 121 logMessage("f4_Model", "build ModelRec", 2, "Error in buildingModel");121 logMessage("f4_Model", "buildFromF4", LOG_ERROR, "Error in building a Model"); 122 122 error = res; 123 123 break; … … 135 135 f4_Cell* f4_Model::getStick(f4_Cell *C) 136 136 { 137 if ( T_STICK4 == C->type) return C;137 if (C->type == CELL_STICK) return C; 138 138 if (NULL != C->dadlink) 139 139 return getStick(C->dadlink); 140 140 // we have no more dadlinks, find any stick 141 for (int i = 0; i < cells-> nc; i++)142 if (cells->C[i]->type == T_STICK4)141 for (int i = 0; i < cells->cell_count; i++) 142 if (cells->C[i]->type == CELL_STICK) 143 143 return cells->C[i]; 144 144 // none! 145 logMessage("f4_Model", "getStick", 2, "Not a single stick");145 logMessage("f4_Model", "getStick", LOG_ERROR, "Not a single stick"); 146 146 return NULL; 147 147 } 148 148 149 149 150 /// updated by MacKo to follow new SDK standards (no more neuroitems)151 150 int f4_Model::buildModelRec(f4_Cell *C) 152 151 { … … 164 163 // make sure parent is a stick 165 164 if (NULL != C->dadlink) 166 if (C->dadlink->type != T_STICK4)167 { 168 C->dadlink = getStick(C->dadlink);165 if (C->dadlink->type != CELL_STICK) 166 { 167 C->dadlink = getStick(C->dadlink); 169 168 } 170 169 … … 179 178 180 179 range = C->genoRange; 181 if (C->type == T_STICK4)180 if (C->type == CELL_STICK) 182 181 { 183 182 int jj_p1_refno; // save for later … … 190 189 /*1.0/C->P.mass,*/ C->P.friction, C->P.ingestion, C->P.assimilation 191 190 //C->firstend.x, C->firstend.y, C->firstend.z 192 191 ); 193 192 partidx = addFromString(PartType, tmpLine, &range); 194 193 if (partidx < 0) return -1; … … 207 206 //C->lastend.x, C->lastend.y, C->lastend.z 208 207 /*"vol=" 1.0/C->P.mass,*/ C->P.friction, C->P.ingestion, C->P.assimilation 209 208 ); 210 209 partidx = addFromString(PartType, tmpLine, &range); 211 210 if (partidx < 0) return -2; … … 227 226 //C->P.ruch, // rotstif 228 227 C->P.stamina 229 228 ); 230 229 partidx = addFromString(JointType, tmpLine, &range); 231 230 if (partidx < 0) return -13; … … 234 233 } 235 234 236 if (C->type == T_NEURON4) ///<this case was updated by MacKo235 if (C->type == CELL_NEURON) 237 236 { 238 237 const char* nclass = C->neuclass->name.c_str(); … … 259 258 partno = C->dadlink->p2_refno; 260 259 if ((partno < 0) || (partno >= getPartCount())) return -21; 260 261 261 if (strcmp(nclass, "N") == 0) 262 {263 262 sprintf(tmpLine, "p=%d,d=\"N:in=%g,fo=%g,si=%g\"", partno, C->inertia, C->force, C->sigmo); 264 }265 263 else 266 {267 264 sprintf(tmpLine, "p=%d,d=\"%s\"", partno, nclass); 268 } 265 269 266 partidx = addFromString(NeuronType, tmpLine, &range); 270 267 if (partidx < 0) return -22; … … 275 272 { 276 273 jointno = C->dadlink->joint_refno; 277 sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass); 274 275 if (strcmp(nclass, "@") == 0) 276 sprintf(tmpLine, "j=%d,d=\"@:p=%g\"", jointno, C->P.muscle_power); 277 else if (strcmp(nclass, "|") == 0) 278 sprintf(tmpLine, "j=%d,d=\"|:p=%g,r=%g\"", jointno, C->P.muscle_power, C->mz); 279 else 280 sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass); 281 278 282 partidx = addFromString(NeuronType, tmpLine, &range); 279 283 if (partidx < 0) return -32; … … 283 287 int n_refno = C->neuro_refno; 284 288 285 if ((strcmp(nclass,"N") == 0) && C->ctrl) 286 { 287 if (1 == C->ctrl) 288 sprintf(tmpLine, "j=%d,d=\"@:p=%g\"", C->dadlink->joint_refno, C->P.muscle_power); 289 else 290 sprintf(tmpLine, "j=%d,d=\"|:p=%g,r=%g\"", C->dadlink->joint_refno, C->P.muscle_power, C->mz); 291 partidx = addFromString(NeuronType, tmpLine, &range); 292 if (partidx < 0) return -32; 293 sprintf(tmpLine, "%d,%d", partidx, n_refno); 294 if (addFromString(NeuronConnectionType, tmpLine, &range) < 0) return -33; 295 this->checkpoint(); 296 } 297 298 for (j = 0; j < C->nolink; j++) 299 { 300 if (NULL != C->links[j]->from) 301 buildModelRec(C->links[j]->from); 289 for (j = 0; j < C->conns_count; j++) 290 { 291 if (C->conns[j]->from != NULL) 292 buildModelRec(C->conns[j]->from); 302 293 303 294 tmpLine[0] = 0; 304 if (C-> links[j]->from == NULL)295 if (C->conns[j]->from == NULL) 305 296 { 306 const char* nclass = C->links[j]->t.c_str(); 307 char* temp = (char*)C->links[j]->t.c_str(); 308 NeuroClass *sensortest = GenoOperators::parseNeuroClass(temp); 309 //backward compatibility for G*TS 310 if (C->links[j]->t == "*" || C->links[j]->t == "S" || C->links[j]->t == "T") 311 { 312 partno = C->dadlink->p2_refno; 313 sprintf(tmpLine, "p=%d,d=\"%s\"", partno, nclass); 314 } 315 else if (C->links[j]->t == "G") 316 { 317 jointno = C->dadlink->joint_refno; 318 sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass); 319 } 320 else if (sensortest->getPreferredLocation() == 0) 321 { 322 sprintf(tmpLine, "d=\"%s\"",nclass); 323 } 324 else if (sensortest->getPreferredLocation() == 1) 325 { 326 partno = C->dadlink->p2_refno; 327 sprintf(tmpLine, "p=%d,d=\"%s\"", partno, nclass); 328 } 329 else 330 { 331 jointno = C->dadlink->joint_refno; 332 sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass); 333 } 334 297 logMessage("f4_Model", "buildModelRec", LOG_ERROR, "Old code for sensors as inputs embedded in [connection]: C->conns[j]->from == NULL"); 335 298 } 336 299 int from = -1; 337 if (tmpLine[0]) //input from receptor 338 { 339 from = addFromString(NeuronType, tmpLine, &range); 340 if (from < 0) return -34; 341 this->checkpoint(); 342 } /*could be 'else'...*/ 343 344 if (NULL != C->links[j]->from) // input from another neuron 345 from = C->links[j]->from->neuro_refno; 300 if (C->conns[j]->from != NULL) // input from another neuron 301 from = C->conns[j]->from->neuro_refno; 346 302 if (from >= 0) 347 303 { 348 sprintf(tmpLine, "%d,%d,%g", n_refno, from, C-> links[j]->w);304 sprintf(tmpLine, "%d,%d,%g", n_refno, from, C->conns[j]->weight); 349 305 if (addFromString(NeuronConnectionType, tmpLine, &range) < 0) return -35; 350 306 this->checkpoint();
Note: See TracChangeset
for help on using the changeset viewer.