- Timestamp:
- 01/19/18 19:37:43 (7 years ago)
- Location:
- cpp/frams
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f1/conv_f1.cpp
r719 r726 111 111 Builder builder(g, map ? 1 : 0); 112 112 builder.model.open(); 113 builder.grow(-1, g, Pt3D_0, stdprops, -1); // uses Model:: singleStepBuildto create model elements113 builder.grow(-1, g, Pt3D_0, stdprops, -1); // uses Model::addFromString() to create model elements 114 114 if (builder.invalid) return SString(); 115 115 builder.addPendingInputs(); … … 323 323 { 324 324 double len = min(2.0, c.length); 325 sprintf(tmp, " j:p1=%ld,p2=%ld,dx=%lg,rx=%lg,ry=%lg,rz=%lg,stam=%lg,vr=%g,vg=%g,vb=%g",325 sprintf(tmp, "p1=%ld,p2=%ld,dx=%lg,rx=%lg,ry=%lg,rz=%lg,stam=%lg,vr=%g,vg=%g,vb=%g", 326 326 part1, part2, len, angle.x, angle.y, angle.z, c.stamina, c.cred, c.cgreen, c.cblue); 327 327 lastjoint_muscle_power = c.muscle_power; 328 return model. singleStepBuild(tmp, makeRange(g));328 return model.addFromString(Model::JointType, tmp, makeRange(g)); 329 329 } 330 330 331 331 int Builder::growPart(F1Props &c, const char *g) 332 332 { 333 sprintf(tmp, " p:dn=%lg,fr=%lg,ing=%lg,as=%lg,vs=%g,vr=%g,vg=%g,vb=%g",333 sprintf(tmp, "dn=%lg,fr=%lg,ing=%lg,as=%lg,vs=%g,vr=%g,vg=%g,vb=%g", 334 334 1.0 / c.weight, c.friction, c.ingestion, c.assimilation, c.visual_size, c.cred, c.cgreen, c.cblue); 335 return model. singleStepBuild(tmp, makeRange(g));335 return model.addFromString(Model::PartType, tmp, makeRange(g)); 336 336 } 337 337 -
cpp/frams/genetics/f4/conv_f4.cpp
r675 r726 178 178 // new part object for firstend 179 179 // coordinates are left to be computed by Model 180 sprintf(tmpLine, " p:fr=%g,ing=%g,as=%g",180 sprintf(tmpLine, "fr=%g,ing=%g,as=%g", 181 181 /*1.0/C->P.mass,*/ C->P.friction, C->P.ingestion, C->P.assimilation 182 182 //C->firstend.x, C->firstend.y, C->firstend.z 183 183 ); 184 partidx = singleStepBuild(tmpLine, &range);184 partidx = addFromString(PartType, tmpLine, &range); 185 185 if (partidx < 0) return -1; 186 186 jj_p1_refno = partidx; … … 194 194 } 195 195 // new part object for lastend 196 sprintf(tmpLine, " p:fr=%g,ing=%g,as=%g",196 sprintf(tmpLine, "fr=%g,ing=%g,as=%g", 197 197 //C->lastend.x, C->lastend.y, C->lastend.z 198 198 /*"vol=" 1.0/C->P.mass,*/ C->P.friction, C->P.ingestion, C->P.assimilation 199 199 ); 200 partidx = singleStepBuild(tmpLine, &range);200 partidx = addFromString(PartType, tmpLine, &range); 201 201 if (partidx < 0) return -2; 202 202 C->p2_refno = partidx; … … 207 207 if ((jj_p1_refno < 0) || (jj_p1_refno >= getPartCount())) return -11; 208 208 if ((jj_p2_refno < 0) || (jj_p2_refno >= getPartCount())) return -12; 209 sprintf(tmpLine, " j:p1=%ld,p2=%ld,dx=%g,dy=0,dz=0,rx=%g,ry=0,rz=%g"\209 sprintf(tmpLine, "p1=%ld,p2=%ld,dx=%g,dy=0,dz=0,rx=%g,ry=0,rz=%g"\ 210 210 ",stam=%g", 211 211 jj_p1_refno, jj_p2_refno, … … 218 218 C->P.stamina 219 219 ); 220 partidx = singleStepBuild(tmpLine, &range);220 partidx = addFromString(JointType, tmpLine, &range); 221 221 if (partidx < 0) return -13; 222 222 C->joint_refno = partidx; … … 230 230 if ((p_refno < 0) || (p_refno >= getPartCount())) return -21; 231 231 // joint_refno is currently not used 232 sprintf(tmpLine, " n:p=%ld,d=\"N:in=%g,fo=%g,si=%g\"",232 sprintf(tmpLine, "p=%ld,d=\"N:in=%g,fo=%g,si=%g\"", 233 233 p_refno, 234 234 C->inertia, C->force, C->sigmo); 235 partidx = singleStepBuild(tmpLine, &range);235 partidx = addFromString(NeuronType, tmpLine, &range); 236 236 if (partidx < 0) return -22; 237 237 C->neuro_refno = partidx; … … 241 241 { 242 242 if (1 == C->ctrl) 243 sprintf(tmpLine, " n:j=%d,d=\"@:p=%g\"", C->dadlink->joint_refno, C->P.muscle_power);243 sprintf(tmpLine, "j=%d,d=\"@:p=%g\"", C->dadlink->joint_refno, C->P.muscle_power); 244 244 else 245 sprintf(tmpLine, " n:j=%d,d=\"|:p=%g,r=%g\"", C->dadlink->joint_refno, C->P.muscle_power, C->mz);246 partidx = singleStepBuild(tmpLine, &range);245 sprintf(tmpLine, "j=%d,d=\"|:p=%g,r=%g\"", C->dadlink->joint_refno, C->P.muscle_power, C->mz); 246 partidx = addFromString(NeuronType, tmpLine, &range); 247 247 if (partidx < 0) return -32; 248 sprintf(tmpLine, " c:%d,%d", partidx, n_refno);249 if ( singleStepBuild(tmpLine, &range) < 0) return -33;248 sprintf(tmpLine, "%d,%d", partidx, n_refno); 249 if (addFromString(NeuronConnectionType, tmpLine, &range) < 0) return -33; 250 250 } 251 251 … … 256 256 257 257 tmpLine[0] = 0; 258 if (1 == C->links[j]->t) sprintf(tmpLine, " n:p=%d,d=\"*\"", p_refno);259 if (2 == C->links[j]->t) sprintf(tmpLine, " n:j=%d,d=\"G\"", C->dadlink->joint_refno);260 if (3 == C->links[j]->t) sprintf(tmpLine, " n:p=%d,d=\"T\"", p_refno);261 if (4 == C->links[j]->t) sprintf(tmpLine, " n:p=%d,d=\"S\"", p_refno);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); 262 262 int from = -1; 263 263 if (tmpLine[0]) //input from receptor 264 264 { 265 from = singleStepBuild(tmpLine, &range);265 from = addFromString(NeuronType, tmpLine, &range); 266 266 if (from < 0) return -34; 267 267 } /*could be 'else'...*/ … … 270 270 if (from >= 0) 271 271 { 272 sprintf(tmpLine, " c:%d,%d,%g", n_refno, from, C->links[j]->w);273 if ( singleStepBuild(tmpLine, &range) < 0) return -35;272 sprintf(tmpLine, "%d,%d,%g", n_refno, from, C->links[j]->w); 273 if (addFromString(NeuronConnectionType, tmpLine, &range) < 0) return -35; 274 274 } 275 275 } -
cpp/frams/model/model.cpp
r720 r726 22 22 startenergy = 1.0; 23 23 checklevel = 1; 24 #ifdef MODEL_V1_COMPATIBLE25 oldneurocount=-1; // == unknown26 oldconnections=0;27 #endif28 24 map = 0; 29 25 f0map = 0; … … 295 291 } 296 292 293 Model::ItemType Model::itemTypeFromLinePrefix(const char* line) 294 { 295 struct PrefixAndItem { const char* prefix; ItemType type; }; 296 static const PrefixAndItem types[]={ {"m:",ModelType},{"p:",PartType},{"j:",JointType},{"n:",NeuronType},{"c:",NeuronConnectionType},{NULL} }; 297 for(const PrefixAndItem *t=types;t->prefix!=NULL;t++) 298 { 299 const char* in=line; 300 const char* pattern=t->prefix; 301 for(;*in==*pattern;in++,pattern++) 302 if (*pattern==':') 303 return t->type; 304 } 305 return UnknownType; 306 } 307 297 308 void Model::build() 298 309 { … … 322 333 for (; f0txt.getNextToken(pos, line, '\n'); lnum++) 323 334 { 335 const char* line_ptr=line.c_str(); 336 for (; *line_ptr; line_ptr++) 337 if (!strchr(" \r\t", *line_ptr)) break; 338 if (*line_ptr == '#') continue; 339 if (!*line_ptr) continue; 340 341 const char* colon=strchr(line_ptr,':'); 342 ItemType type=UnknownType; 343 SString excluding_prefix; 344 if (colon!=NULL) 345 { 346 colon++; 347 type=itemTypeFromLinePrefix(line_ptr); 348 for (; *colon; colon++) 349 if (!strchr(" \r\t", *colon)) break; 350 excluding_prefix=colon; 351 } 352 324 353 if (autobuildmaps) 325 354 { … … 328 357 } 329 358 mh.reset(); 330 if ( singleStepBuild(line, lnum, autobuildmaps ? (&frommap) : 0) == -1)359 if (addFromString(type, excluding_prefix, lnum, autobuildmaps ? (&frommap) : 0) == -1) 331 360 { 332 361 buildstatus = invalid; … … 558 587 } 559 588 560 int Model:: singleStepBuild(const SString &singleline, const MultiRange* srcrange)561 { 562 return singleStepBuild(singleline, 0, srcrange);563 } 564 565 int Model:: singleStepBuild(const SString &singleline, int line_num, const MultiRange* srcrange)589 int Model::addFromString(ItemType item_type, const SString &singleline, const MultiRange* srcrange) 590 { 591 return addFromString(item_type,singleline, 0, srcrange); 592 } 593 594 int Model::addFromString(ItemType item_type, const SString &singleline, int line_num, const MultiRange* srcrange) 566 595 { 567 596 SString error_message; 568 int result = singleStepBuildNoLog(singleline, error_message, srcrange);597 int result = addFromStringNoLog(item_type, singleline, error_message, srcrange); 569 598 if (result < 0) 570 599 { … … 579 608 } 580 609 581 int Model:: singleStepBuildNoLog(const SString &line, SString& error_message, const MultiRange* srcrange)610 int Model::addFromStringNoLog(ItemType item_type, const SString &line, SString& error_message, const MultiRange* srcrange) 582 611 { 583 612 error_message = SString::empty(); 584 const char*t = line.c_str();585 613 ParamInterface::LoadOptions opts; 586 for (; *t; t++, opts.offset++) 587 if (!strchr(" \r\t", *t)) break; 588 if (*t == '#') return 0; 589 if (!*t) return 0; 590 if (!strncmp(t, "p:", 2)) 591 { 614 switch(item_type) 615 { 616 case PartType: 617 { 592 618 Param partparam(f0_part_paramtab); 593 619 Part *p = new Part(); 594 620 partparam.select(p); 595 opts.offset += 2;596 621 partparam.load(ParamInterface::FormatSingleLine, line, &opts); 597 622 if (opts.parse_failed) { delete p; error_message = "Invalid 'p:'"; return -1; } … … 601 626 if (srcrange) p->setMapping(*srcrange); 602 627 return getPartCount() - 1; 603 } 604 if (!strncmp(t, "m:", 2)) 605 { 628 } 629 630 case ModelType: 631 { 606 632 Param modelparam(f0_model_paramtab); 607 633 modelparam.select(this); 608 opts.offset += 2;609 634 modelparam.load(ParamInterface::FormatSingleLine, line, &opts); 610 635 if (opts.parse_failed) { error_message = "Invalid 'm:'"; return -1; } 611 636 return 0; 612 } 613 else if (!strncmp(t, "j:", 2)) 614 { 637 } 638 639 case JointType: 640 { 615 641 Param jointparam(f0_joint_paramtab); 616 642 Joint *j = new Joint(); 617 643 jointparam.select(j); 618 opts.offset += 2;619 644 j->owner = this; 620 645 jointparam.load(ParamInterface::FormatSingleLine, line, &opts); … … 640 665 return -1; 641 666 } 642 } 643 else if (!strncmp(t, "n:", 2)) // neuro (or the old neuro object as the special case) 644 { 667 } 668 669 case NeuronType: 670 { 645 671 Param neuroparam(f0_neuro_paramtab); 646 672 Neuro *nu = new Neuro(); 647 673 neuroparam.select(nu); 648 opts.offset += 2;649 674 neuroparam.load(ParamInterface::FormatSingleLine, line, &opts); 650 675 if (opts.parse_failed) { delete nu; error_message = "Invalid 'n:'"; return -1; } 651 #ifdef MODEL_V1_COMPATIBLE652 if (nu->neuro_refno>=0) // parent specified...653 {654 if (nu->neuro_refno >= getNeuroCount()) // and it's illegal655 {656 delete nu;657 return -1;658 }659 Neuro *parentNU=getNeuro(nu->neuro_refno);660 parentNU->addInput(nu,nu->weight);661 // default class for parented units: n-n link662 //if (nu->moredata.len()==0) nu->moredata="-";663 }664 else665 #endif666 676 { 667 677 // default class for unparented units: standard neuron … … 680 690 } 681 691 */ 682 #ifdef MODEL_V1_COMPATIBLE683 nu->weight=1.0;684 #endif685 692 nu->owner = this; 686 693 // attach to part/joint … … 703 710 if (srcrange) nu->setMapping(*srcrange); 704 711 // todo: check part/joint ref# 705 #ifdef MODEL_V1_COMPATIBLE706 if (hasOldNeuroLayout())707 {708 int count=old_getNeuroCount();709 neurons.insert(count,nu);710 oldneurocount=count+1;711 return oldneurocount-1;712 }713 else714 #endif715 712 { 716 713 neurons += nu; 717 714 return neurons.size() - 1; 718 715 } 719 } 720 else if (!strncmp(t, "c:", 2)) // add input 721 { 716 } 717 718 case NeuronConnectionType: 719 { 722 720 Param ncparam(f0_neuroconn_paramtab); 723 721 NeuroConn c; 724 722 ncparam.select(&c); 725 opts.offset += 2;726 723 ncparam.load(ParamInterface::FormatSingleLine, line, &opts); 727 724 if (opts.parse_failed) { error_message = "Invalid 'c:'"; return -1; } … … 739 736 error_message = SString::sprintf("Invalid reference to Neuro #%d", n1_ok ? c.n2_refno : c.n1_refno); 740 737 return -1; 741 } 742 #ifdef MODEL_V1_COMPATIBLE 743 else if (!strncmp(t,"ni:",3)) // old neuroitem 744 { 745 // we always use old layout for "ni:" 746 Param neuroitemparam(f0_neuroitem_paramtab); 747 Neuro *nu=new Neuro(); 748 neuroitemparam.select(nu); 749 opts.offset+=3; 750 neuroitemparam.loadSingleLine(line,opts); 751 if (opts.parse_failed) {delete nu; return -1;} 752 // illegal parent? 753 if ((nu->neuro_refno<0)||(nu->neuro_refno>=old_getNeuroCount())) 754 { 755 delete nu; 738 } 739 740 case UnknownType: //handled by addFromString for uniform error handling 756 741 return -1; 757 742 } 758 Neuro *parentN=getNeuro(nu->neuro_refno); 759 // copy part/joint refno from parent, if possible 760 if ((nu->part_refno<0)&&(parentN->part_refno>=0)) 761 nu->part_refno=parentN->part_refno; 762 if ((nu->joint_refno<0)&&(parentN->joint_refno>=0)) 763 nu->joint_refno=parentN->joint_refno; 764 nu->owner=this; 765 // attach to part/joint 766 if (nu->part_refno>=0) 767 nu->attachToPart(nu->part_refno); 768 if (nu->joint_refno>=0) 769 nu->attachToJoint(nu->joint_refno); 770 if (srcrange) 771 nu->setMapping(*srcrange); 772 // special case: old muscles 773 // PARENT neuron will be set up to be the CHILD of the current one (!) 774 if (nu->isOldEffector()) 775 { 776 nu->neuro_refno=parentN->refno; 777 neurons+=nu; 778 nu->owner=this; 779 nu->addInput(parentN,nu->weight); // (!) 780 nu->weight=1.0; 781 parentN->invalidateOldItems(); 782 return 0; // !!! -> ...getItemCount()-1; 783 } 784 parentN->addInput(nu,nu->weight); 785 neurons+=nu; 786 parentN->invalidateOldItems(); 787 if (nu->getClassName().len()==0) 788 { 789 nu->setClassName("-"); 790 // for compatibility, "ni" can define a n-n connection 791 // referring to non-existent neuron (which will be hopefully defined later) 792 // internal check will add the proper input to this unit 793 // if conn_refno >=0 and input count==0 794 oldconnections=1; 795 if (srcrange) 796 parentN->addMapping(*srcrange); 797 } 798 else 799 nu->weight=1.0; 800 return 0; // !!! -> ...getItemCount()-1; 801 } 802 #endif 803 else return -1; 804 } 805 806 #ifdef MODEL_V1_COMPATIBLE 807 int Model::addOldConnectionsInputs() 808 { 809 if (!oldconnections) return 1; 810 Neuro* n; 811 for (int i=0;i<neurons.size();i++) 812 { 813 n=(Neuro*)neurons(i); 814 if (n->conn_refno>=0) 815 if (n->isNNConnection()) 816 if (n->conn_refno < old_getNeuroCount()) 817 { // good reference 818 Neuro* parent=n->parent; // nn connection has exactly one parent 819 int inp=parent->findInput(n); 820 Neuro* target=getNeuro(n->conn_refno); 821 parent->setInput(inp,target,n->weight); 822 removeNeuro(i,0); // no need to remove references 823 i--; 824 } 825 else 826 { 827 logPrintf("Model","internalCheck",LOG_ERROR, 828 "illegal N-N connection #%d (reference to #%d)%s", 829 i,n->conn_refno,nameForErrors().c_str()); 830 return 0; 831 } 832 } 833 oldconnections=0; 834 return 1; 835 } 836 #endif 743 return -1; 744 } 745 837 746 838 747 ///////////// … … 847 756 neurons.insert(newpos, n); 848 757 // conn_refno could be broken -> fix it 849 #ifdef MODEL_V1_COMPATIBLE 850 for (int i=0;i<neurons.size();i++) 851 { 852 Neuro *n2=getNeuro(i); 853 if (n2->isNNConnection()) 854 if (n2->conn_refno == oldpos) n2->conn_refno=newpos; 855 else 856 { if (n2->conn_refno > oldpos) n2->conn_refno--; 857 if (n2->conn_refno >= newpos) n2->conn_refno++; } 858 } 859 invalidateOldNeuroCount(); 860 #endif 861 } 862 863 #ifdef MODEL_V1_COMPATIBLE 864 /** move all old neurons (class "N") to the front of the neurons list. 865 @return number of old neurons 866 */ 867 int Model::reorderToOldLayout() 868 { 869 Neuro *n; 870 int neurocount=0; 871 for (int i=0;i<neurons.size();i++) 872 { 873 n=(Neuro*)neurons(i); 874 if (n->isOldNeuron()) 875 { 876 moveNeuro(i,neurocount); 877 neurocount++; 878 i=neurocount-1; 879 } 880 } 881 return neurocount; 882 } 883 #endif 758 } 759 884 760 //////////// 885 761 … … 1058 934 } 1059 935 } 1060 #ifdef MODEL_V1_COMPATIBLE1061 if (!addOldConnectionsInputs())1062 return 0;1063 #endif1064 936 1065 937 updateNeuroRefno(); // valid refno is important for n-n connections check (later) … … 1068 940 { 1069 941 n = (Neuro*)neurons(i); 1070 #ifdef MODEL_V1_COMPATIBLE1071 VALIDMINMAX(n,Neuro,inertia);1072 VALIDMINMAX(n,Neuro,force);1073 VALIDMINMAX(n,Neuro,sigmo);1074 n->conn_refno=-1;1075 n->weight=1.0;1076 n->neuro_refno=-1;1077 #endif1078 942 n->part_refno = (n->part) ? n->part->refno : -1; 1079 943 n->joint_refno = (n->joint) ? n->joint->refno : -1; … … 1245 1109 } 1246 1110 1247 1248 ////////////////////1249 1250 #ifdef MODEL_V1_COMPATIBLE1251 void Model::calcOldNeuroCount()1252 {1253 if (oldneurocount>=0) return;1254 oldneurocount=reorderToOldLayout();1255 }1256 1257 int Model::old_getNeuroCount()1258 { calcOldNeuroCount();1259 return oldneurocount;}1260 1261 Neuro* Model::old_getNeuro(int i)1262 {calcOldNeuroCount();1263 return (i<oldneurocount)? (Neuro*)getNeuro(i) : (Neuro*)0;1264 }1265 1266 int Model::old_findNeuro(Neuro* n)1267 {calcOldNeuroCount();1268 return findNeuro(n);}1269 1270 Neuro *Model::old_addNewNeuro()1271 {1272 int count=old_getNeuroCount();1273 Neuro *nu=addNewNeuro();1274 nu->setClassName("N");1275 moveNeuro(nu->refno,oldneurocount);1276 oldneurocount=count+1;1277 return (Neuro*)nu;1278 }1279 #endif1280 1281 1111 /////////////////////// 1282 1112 -
cpp/frams/model/model.h
r660 r726 75 75 SList parts, joints, neurons; 76 76 char partmappingchanged; 77 78 #ifdef MODEL_V1_COMPATIBLE79 /** NeuroCount value.80 compatibility_neurocount = -1 if its value is unknown and the layout is not compatible81 @see reorderToOldLayout()82 */83 int oldneurocount;84 char oldconnections;85 86 /** calculate oldNeuroCount */87 void calcOldNeuroCount();88 /** some new calls can invalidate old compatibility data */89 void invalidateOldNeuroCount() {oldneurocount=-1;}90 /**91 for compatibility with old NeuroClass the layout of Neurons92 is changed when old 'Neuro' accessing methods are in use.93 Neurons:94 0 .. compatibility_neurocount-1 : old Neurons (class "N")95 compatibility_neurocount .. neurons.size()-1 : other units96 */97 int reorderToOldLayout();98 99 /** check if compatibility should be preserved */100 int hasOldNeuroLayout() {return oldneurocount>=0;}101 102 /** add inputs to the old "-" units.103 @return 1=ok, 0=invalid input detected */104 int addOldConnectionsInputs();105 #endif106 77 107 78 void internalCopy(const Model &mod); … … 284 255 void clear(); 285 256 257 enum ItemType { UnknownType,ModelType,PartType,JointType,NeuronType,NeuronConnectionType }; 258 static ItemType itemTypeFromLinePrefix(const char* line); 286 259 /** Execute single line of <B>f0</B> genotype. 287 260 Return value is non-negative reference number of the created item, … … 291 264 @param srcrange source genotype range which will be mapped to this element 292 265 */ 293 int singleStepBuild(const SString &singleline, int line_num, const MultiRange* srcrange = NULL);266 int addFromString(ItemType item_type,const SString &singleline, int line_num, const MultiRange* srcrange = NULL); 294 267 /** Execute single line of <B>f0</B> genotype - compatiblity variant */ 295 int singleStepBuild(const SString &singleline, const MultiRange* srcrange = NULL);268 int addFromString(ItemType item_type,const SString &singleline, const MultiRange* srcrange = NULL); 296 269 /** Execute single line of <B>f0</B> genotype - low level variant, used by Model::build(), error messages returned as string instead of calling logger */ 297 int singleStepBuildNoLog(const SString &singleline, SString& error_message, const MultiRange* srcrange = 0);270 int addFromStringNoLog(ItemType item_type,const SString &singleline, SString& error_message, const MultiRange* srcrange = 0); 298 271 299 272 /// separate build stages (for future use) … … 346 319 /// you can access neurons 0 .. getNeuroCount()-1. 347 320 Neuro *getNeuro(int i) const; 348 349 #ifdef MODEL_V1_COMPATIBLE350 /* compatibility calls for accessing old Neuro objects */351 352 /// @deprecated Neuro class will be removed soon353 /// @see compat354 int old_getNeuroCount();355 /// you can access neurons 0 .. getNeuroCount()-1.356 /// @deprecated Neuro class will be removed soon357 Neuro *old_getNeuro(int i);358 /// @see addNewNeuro, addNeuro359 /// @deprecated Neuro class will be removed soon360 Neuro *old_addNewNeuro();361 /// @return neuro index or -1 if not found362 /// @deprecated Neuro class will be removed soon363 int old_findNeuro(Neuro* n);364 #endif365 321 366 322 /** create new Part and add it to the model. @see addPart() */ -
cpp/frams/model/modelparts.cpp
r714 r726 193 193 Neuro::Neuro(double _state, double _inertia, double _force, double _sigmo) 194 194 :PartBase(getDefaultStyle()), state(_state) 195 #ifdef MODEL_V1_COMPATIBLE 196 ,inertia(_inertia),force(_force),sigmo(_sigmo) 197 #endif 198 { 199 #ifdef MODEL_V1_COMPATIBLE 200 olditems=0; 201 #endif 195 { 202 196 flags = 0; 203 197 myclass = 0; … … 217 211 parent = 0; part = 0; joint = 0; 218 212 parentcount = 0; 219 #ifdef MODEL_V1_COMPATIBLE220 olditems=0;221 #endif222 213 flags = 0; 223 214 part_refno = -1; joint_refno = -1; … … 227 218 Neuro::~Neuro() 228 219 { 229 #ifdef MODEL_V1_COMPATIBLE230 if (olditems) delete olditems;231 #endif232 220 int i; 233 221 for (i = 0; i < inputs.size(); i++) … … 281 269 { 282 270 refno = src.refno; 283 #ifdef MODEL_V1_COMPATIBLE284 neuro_refno=-1;285 conn_refno=-1;286 force=src.force;287 sigmo=src.sigmo;288 inertia=src.inertia;289 weight=src.weight;290 olditems=0;291 #endif292 271 state = src.state; 293 272 part_refno = -1; … … 567 546 #endif 568 547 } 569 570 /////// old items571 #ifdef MODEL_V1_COMPATIBLE572 void OldItems::buildlist()573 { // guaranteed to work only for old NN layouts574 // (neurons,neuro connections, old receptors and effectors)575 if (listok) return;576 // inputs can contain both neuroitem connections (details="") and direct neuron references (details="N")577 // in OldItems we create neuroitems freom direct references578 for(int i=0;i<neuro.getInputCount();i++)579 {580 float w;581 Neuro *n=neuro.getInput(i,w);582 if (n->isOldNeuron())583 {584 Neuro *ni=new Neuro();585 ni->setClassName("-");586 ni->weight=w;587 ni->neuro_refno=neuro.refno;588 ni->conn_refno=n->refno;589 items+=ni;590 syntitems+=ni;591 }592 else593 {594 items+=n;595 n->weight=w;596 }597 }598 SList outputs;599 neuro.findOutputs(outputs);600 FOREACH(Neuro*,n,outputs)601 {602 if (n->isNNConnection() || n->isOldNeuron())603 outputs-=n;604 }605 items+=outputs;606 listok=1;607 }608 609 void OldItems::freelist()610 {611 FOREACH(Neuro*,n,syntitems)612 delete n;613 syntitems.clear();614 items.clear();615 listok=0;616 }617 618 int OldItems::getItemCount()619 {620 buildlist();621 return items.size();622 }623 624 NeuroItem *OldItems::getNeuroItem(int i)625 {626 buildlist();627 return (NeuroItem*)items(i);628 }629 630 NeuroItem *OldItems::addNewNeuroItem()631 {632 Neuro *nu=neuro.getModel().addNewNeuro();633 nu->setClassName("-");634 if (listok) items+=nu;635 neuro.addInput(nu);636 return (NeuroItem*)nu;637 }638 639 int OldItems::findNeuroItem(NeuroItem *ni)640 {641 buildlist();642 return items.find((void*)ni);643 }644 #endif645 548 646 549 /////////////////////////////////////// … … 801 704 } 802 705 803 804 706 ///////////////////////////////////////////////////////////////// 805 /////////////////////////////////////////////////////////////////806 707 807 708 #include F0_CLASSES_FILE 808 809 #ifdef MODEL_V1_COMPATIBLE810 811 #define FIELDSTRUCT Neuro812 ParamEntry f0_old_neuro_tab[]=813 {814 {"Connections",2,6,"n",},815 {"Other properties",},816 {"p",0,0,"part ref#","d",FIELD(part_refno),},817 {"j",0,0,"joint ref#","d",FIELD(joint_refno),},818 {"s",1,0,"state","f",FIELD(state),},819 {"in",1,0,"Inertia","f",FIELD(inertia),},820 {"fo",1,0,"Force","f",FIELD(force),},821 {"si",1,0,"Sigmoid","f",FIELD(sigmo),},822 {0,0,0,},823 };824 #undef FIELDSTRUCT825 826 #define FIELDSTRUCT NeuroItem827 ParamEntry f0_neuroitem_paramtab[]=828 {829 {"Connections",3,12,"ni",},830 {"Geometry",},831 {"Other",},832 {"n",0,0,"neuron ref#","d",FIELD(neuro_refno),},833 {"c",2,0,"connection ref#","d",FIELD(conn_refno),},834 {"w",2,0,"connection weight","f",FIELD(weight),},835 {"p",0,0,"part ref#","d",FIELD(part_refno),},836 {"j",0,0,"joint ref#","d",FIELD(joint_refno),},837 {"px",1,0,"position.x","f",FIELD(pos.x),},838 {"py",1,0,"position.y","f",FIELD(pos.y),},839 {"pz",1,0,"position.z","f",FIELD(pos.z),},840 {"rx",1,0,"rotation.x","f",FIELD(rot.x),},841 {"ry",1,0,"rotation.y","f",FIELD(rot.y),},842 {"rz",1,0,"rotation.z","f",FIELD(rot.z),},843 {"d",2,0,"item details","s",GETSET(details),},844 {0,0,0,},845 };846 #undef FIELDSTRUCT847 #endif848 709 849 710 //////////////////////////////////////// -
cpp/frams/model/modelparts.h
r714 r726 19 19 20 20 #include <stdio.h> 21 22 //#define MODEL_V1_COMPATIBLE23 21 24 22 class Model; … … 289 287 class Neuro; 290 288 291 #ifdef MODEL_V1_COMPATIBLE292 class NeuroItem;293 294 /** for compatibility with old Neuro/NeuroItem */295 class OldItems296 {297 Neuro &neuro;298 SList syntitems; ///< to be deleted299 SList items;300 int listok;301 public:302 OldItems(Neuro &n):neuro(n),listok(0) {}303 ~OldItems() {freelist();}304 void buildlist();305 void freelist();306 307 int getItemCount();308 NeuroItem *getNeuroItem(int i);309 NeuroItem *addNewNeuroItem();310 int findNeuroItem(NeuroItem *n);311 };312 #endif313 314 289 /** Single processing unit in Framsticks NN. */ 315 290 class Neuro : public PartBase … … 482 457 static int getClassIndex(const NeuroClass*nc); 483 458 484 #ifdef MODEL_V1_COMPATIBLE485 friend class OldItems;486 paInt neuro_refno; ///< parent ref# (called neuro_refno for compatibility with old Neuro class), @see moredata487 paInt conn_refno; ///< the other neuron ref# in N-N connections, can be used by some other items488 double weight; ///< weight of the N-N connection and (all?) receptors489 double inertia,force,sigmo; //!!!490 491 /** @deprecated provided only for compatibility with old Neuro/NeuroItem classes.492 use getInputCount() instead. @sa getInputCount() */493 int getItemCount() {return oldItems().getItemCount();}494 495 /** @deprecated provided only for compatibility with old Neuro/NeuroItem classes.496 use getInput() instead. @sa getInput() */497 NeuroItem* getNeuroItem(int i) {return oldItems().getNeuroItem(i);}498 #endif499 500 protected:501 #ifdef MODEL_V1_COMPATIBLE502 /** old Neuro compatibility */503 OldItems* olditems;504 OldItems& oldItems() {if (!olditems) olditems=new OldItems(*this); return *olditems;}505 void invalidateOldItems() {if (olditems) olditems->freelist();}506 #endif507 508 public:509 510 459 // not really private, but you should not access those directly 511 460 double state; … … 522 471 }; 523 472 524 #ifdef MODEL_V1_COMPATIBLE525 class NeuroItem;526 527 /// for compatibility with old NeuroItem class.528 class NeuroItem: public Neuro529 {530 public:531 NeuroItem() {}532 };533 #endif534 535 473 class NeuroExt : public Neuro 536 474 { -
cpp/frams/neuro/impl/neuroimpl-simple.cpp
r286 r726 12 12 int NI_StdNeuron::lateinit() 13 13 { 14 #ifdef MODEL_V1_COMPATIBLE15 if (inertia<0) inertia=neuro->inertia;16 if (force<0) force=neuro->force;17 if (sigmo>1e9) sigmo=neuro->sigmo;18 #endif19 14 istate=newstate+neuro->state; // neuro->state -> random initialization 20 15 calcOutput(); -
cpp/frams/neuro/impl/neuroimpl-simple.h
r286 r726 19 19 public: 20 20 double inertia,force,sigmo; 21 NI_StdNeuron():velocity(0) 22 #ifdef MODEL_V1_COMPATIBLE 23 ,inertia(-1),force(-1),sigmo(1e10)// illegal values, will be adjusted in lateinit() 24 #else 25 ,inertia(0),force(0),sigmo(0) 26 #endif 21 NI_StdNeuron():velocity(0),inertia(0),force(0),sigmo(0) 27 22 {paramentries=NI_StdNeuron_tab;} 28 23 NeuroImpl* makeNew(){return new NI_StdNeuron();} // for NeuroFactory
Note: See TracChangeset
for help on using the changeset viewer.