Changeset 760 for cpp/frams/genetics/f4/conv_f4.cpp
- Timestamp:
- 03/15/18 22:55:05 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/conv_f4.cpp
r736 r760 4 4 5 5 // Copyright (C) 1999,2000 Adam Rotaru-Varga (adam_rotaru@yahoo.com), GNU LGPL 6 // Copyright (C) since 2001 Maciej Komosinski 7 // 2018, Grzegorz Latosinski, added support for new API for neuron types and their properties 6 8 7 9 #include "conv_f4.h" … … 27 29 int res; 28 30 f4_Model * model = new f4_Model(); 29 res = model->buildFromF4(in );31 res = model->buildFromF4(in, using_checkpoints); 30 32 if (GENOPER_OK != res) return SString(); // oops 31 33 if (NULL != map) … … 52 54 int res; 53 55 f4_Model * model = new f4_Model(); 54 res = model->buildFromF4(in );56 res = model->buildFromF4(in, using_checkpoints); 55 57 if (GENOPER_OK != res) return SString(); // oops 56 58 SString out; … … 71 73 } 72 74 73 int f4_Model::buildFromF4(SString &geno )75 int f4_Model::buildFromF4(SString &geno, bool using_checkpoints) 74 76 { 75 77 int i; … … 101 103 cells->C[i]->recProcessedFlag = 0; 102 104 103 open( ); // begin model build105 open(using_checkpoints); // begin model build 104 106 105 107 // process every cell … … 184 186 partidx = addFromString(PartType, tmpLine, &range); 185 187 if (partidx < 0) return -1; 188 this->checkpoint(); 186 189 jj_p1_refno = partidx; 187 190 } … … 200 203 partidx = addFromString(PartType, tmpLine, &range); 201 204 if (partidx < 0) return -2; 205 this->checkpoint(); 202 206 C->p2_refno = partidx; 203 207 … … 220 224 partidx = addFromString(JointType, tmpLine, &range); 221 225 if (partidx < 0) return -13; 226 this->checkpoint(); 222 227 C->joint_refno = partidx; 223 228 } … … 225 230 if (C->type == T_NEURON4) ///<this case was updated by MacKo 226 231 { 227 // new neuron object 228 // it is linked to a part (not a joint!) 229 int p_refno = C->dadlink->p2_refno; 230 if ((p_refno < 0) || (p_refno >= getPartCount())) return -21; 231 // joint_refno is currently not used 232 sprintf(tmpLine, "p=%ld,d=\"N:in=%g,fo=%g,si=%g\"", 233 p_refno, 234 C->inertia, C->force, C->sigmo); 235 partidx = addFromString(NeuronType, tmpLine, &range); 236 if (partidx < 0) return -22; 232 const char * nclass = C->neuclass->name.c_str(); 233 int partno, jointno; 234 if (C->neuclass->getPreferredLocation() == 0) 235 { 236 if (strcmp(nclass, "N") == 0) 237 { 238 partno = C->dadlink->p2_refno; 239 if ((partno < 0) || (partno >= getPartCount())) return -21; 240 else sprintf(tmpLine, "p=%ld,d=\"N:in=%g,fo=%g,si=%g\"", partno, C->inertia, C->force, C->sigmo); 241 } 242 else 243 { 244 sprintf(tmpLine, "d=\"%s\"", nclass); 245 } 246 partidx = addFromString(NeuronType, tmpLine, &range); 247 if (partidx < 0) return -22; 248 this->checkpoint(); 249 C->neuro_refno = partidx; 250 } 251 else if (C->neuclass->getPreferredLocation() == 1) // attached to Part or have no required attachment - also part 252 { 253 partno = C->dadlink->p2_refno; 254 if ((partno < 0) || (partno >= getPartCount())) return -21; 255 if (strcmp(nclass, "N") == 0) 256 { 257 sprintf(tmpLine, "d=\"N:in=%g,fo=%g,si=%g\"", partno, C->inertia, C->force, C->sigmo); 258 } 259 else 260 { 261 sprintf(tmpLine, "p=%ld,d=\"%s\"", partno, nclass); 262 } 263 partidx = addFromString(NeuronType, tmpLine, &range); 264 if (partidx < 0) return -22; 265 this->checkpoint(); 266 C->neuro_refno = partidx; 267 } 268 else // attached to Joint 269 { 270 jointno = C->dadlink->joint_refno; 271 sprintf(tmpLine, "n:j=%d,d=\"%s\"", jointno, nclass); 272 partidx = addFromString(NeuronType, tmpLine, &range); 273 if (partidx < 0) return -32; 274 this->checkpoint(); 275 } 237 276 C->neuro_refno = partidx; 238 277 int n_refno = C->neuro_refno; 239 278 240 if ( C->ctrl)279 if ((strcmp(nclass,"N") == 0) && C->ctrl) 241 280 { 242 281 if (1 == C->ctrl) … … 248 287 sprintf(tmpLine, "%d,%d", partidx, n_refno); 249 288 if (addFromString(NeuronConnectionType, tmpLine, &range) < 0) return -33; 289 this->checkpoint(); 250 290 } 251 291 … … 256 296 257 297 tmpLine[0] = 0; 258 if (1 == C->links[j]->t) sprintf(tmpLine, "p=%d,d=\"*\"", p_refno); 259 if (2 == C->links[j]->t) sprintf(tmpLine, "j=%d,d=\"G\"", C->dadlink->joint_refno); 260 if (3 == C->links[j]->t) sprintf(tmpLine, "p=%d,d=\"T\"", p_refno); 261 if (4 == C->links[j]->t) sprintf(tmpLine, "p=%d,d=\"S\"", p_refno); 298 if (C->links[j]->from == NULL) 299 { 300 const char * nclass = C->links[j]->t.c_str(); 301 char * temp = (char*)C->links[j]->t.c_str(); 302 NeuroClass * sensortest = GenoOperators::parseNeuroClass(temp); 303 //backward compatibility for G*TS 304 if (C->links[j]->t == "*" || C->links[j]->t == "S" || C->links[j]->t == "T") 305 { 306 sprintf(tmpLine, "p=%d,d=\"%s\"", partno, nclass); 307 } 308 else if (C->links[j]->t == "G") 309 { 310 jointno = C->dadlink->joint_refno; 311 sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass); 312 } 313 else if (sensortest->getPreferredLocation() == 0) 314 { 315 sprintf(tmpLine, "d=\"%s\"",nclass); 316 } 317 else if (sensortest->getPreferredLocation() == 1) 318 { 319 sprintf(tmpLine, "p=%d,d=\"%s\"", partno, nclass); 320 } 321 else 322 { 323 jointno = C->dadlink->joint_refno; 324 sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass); 325 } 326 327 } 262 328 int from = -1; 263 329 if (tmpLine[0]) //input from receptor … … 265 331 from = addFromString(NeuronType, tmpLine, &range); 266 332 if (from < 0) return -34; 333 this->checkpoint(); 267 334 } /*could be 'else'...*/ 335 268 336 if (NULL != C->links[j]->from) // input from another neuron 269 337 from = C->links[j]->from->neuro_refno; … … 272 340 sprintf(tmpLine, "%d,%d,%g", n_refno, from, C->links[j]->w); 273 341 if (addFromString(NeuronConnectionType, tmpLine, &range) < 0) return -35; 342 this->checkpoint(); 274 343 } 275 344 }
Note: See TracChangeset
for help on using the changeset viewer.