Changeset 972 for cpp/frams/model/model.cpp
- Timestamp:
- 07/03/20 00:32:23 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/model/model.cpp
r955 r972 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 11 11 #define F0_CHECKPOINT_LINE "checkpoint:" 12 12 13 Model::Model( )13 Model::Model(ShapeType sh) 14 14 { 15 15 autobuildmaps = false; 16 init( );17 } 18 19 void Model::init( )16 init(sh); 17 } 18 19 void Model::init(ShapeType sh) 20 20 { 21 21 partmappingchanged = 0; … … 30 30 f0genoknown = 1; 31 31 shape = SHAPE_UNKNOWN; 32 declared_shape = sh; 33 } 34 35 void Model::declareShapeType(ShapeType sh) 36 { 37 declared_shape = sh; 32 38 } 33 39 … … 51 57 f0genoknown = 0; 52 58 shape = mod.shape; 59 declared_shape = mod.declared_shape; 53 60 startenergy = mod.startenergy; 54 61 modelfromgenotype = mod.modelfromgenotype; … … 93 100 94 101 95 Model::Model(const Geno &src, bool buildmaps, bool _using_checkpoints, bool _is_checkpoint)102 Model::Model(const Geno &src, ShapeType st, bool buildmaps, bool _using_checkpoints, bool _is_checkpoint) 96 103 :autobuildmaps(buildmaps) 97 104 { 98 init(src, _using_checkpoints, _is_checkpoint);105 init(src, st, _using_checkpoints, _is_checkpoint); 99 106 } 100 107 … … 110 117 :autobuildmaps(buildmaps) 111 118 { 112 init( );119 init(mod.declared_shape); 113 120 open(_using_checkpoints, _is_checkpoint); 114 121 internalCopy(mod); … … 123 130 } 124 131 125 void Model::init(const Geno &src, bool _using_checkpoints, bool _is_checkpoint)126 { 127 init( );132 void Model::init(const Geno &src, ShapeType sh, bool _using_checkpoints, bool _is_checkpoint) 133 { 134 init(sh); 128 135 using_checkpoints = _using_checkpoints; 129 136 is_checkpoint = _is_checkpoint; … … 162 169 delMap(); 163 170 delF0Map(); 164 init( );171 init(declared_shape); 165 172 geno = Geno(); 166 173 f0geno = Geno(); … … 333 340 f0warnposition = -1; 334 341 MultiMap *convmap = autobuildmaps ? new MultiMap() : NULL; 335 f0geno = (geno.getFormat() == "0") ? geno : geno.getConverted("0", convmap, using_checkpoints); 342 if (declared_shape == SHAPE_UNKNOWN) 343 f0geno = geno.getConverted(Geno::F0_FORMAT_LIST, convmap, using_checkpoints); 344 else 345 f0geno = geno.getConverted(genoFormatForShapeType(declared_shape), convmap, using_checkpoints); 336 346 f0genoknown = 1; 337 347 if (f0geno.isInvalid()) … … 467 477 modelparam.select(this); 468 478 modelparam.saveSingleLine(mod_props, handle_defaults ? &defaultmodel : NULL, true, !handle_defaults); 469 if (mod_props.len () > 1) //are there any non-default values? ("\n" is empty)479 if (mod_props.length() > 1) //are there any non-default values? ("\n" is empty) 470 480 { 471 481 gen += "m:"; … … 476 486 { 477 487 partparam.select(p); 478 len = gen.len ();488 len = gen.length(); 479 489 gen += "p:"; 480 490 partparam.saveSingleLine(gen, handle_defaults ? &defaultpart : NULL, true, !handle_defaults); 481 491 if (map) 482 map->add(len, gen.len () - 1, partToMap(i));492 map->add(len, gen.length() - 1, partToMap(i)); 483 493 } 484 494 for (i = 0; j = (Joint *)joints(i); i++) 485 495 { 486 496 jointparam.select(j); 487 len = gen.len ();497 len = gen.length(); 488 498 jointparam.setParamTab(j->usedelta ? f0_joint_paramtab : f0_nodeltajoint_paramtab); 489 499 gen += "j:"; 490 500 jointparam.saveSingleLine(gen, handle_defaults ? &defaultjoint : NULL, true, !handle_defaults); 491 501 if (map) 492 map->add(len, gen.len () - 1, jointToMap(i));502 map->add(len, gen.length() - 1, jointToMap(i)); 493 503 } 494 504 for (i = 0; n = (Neuro *)neurons(i); i++) 495 505 { 496 506 neuroparam.select(n); 497 len = gen.len ();507 len = gen.length(); 498 508 gen += "n:"; 499 509 neuroparam.saveSingleLine(gen, handle_defaults ? &defaultneuro : NULL, true, !handle_defaults); 500 510 if (map) 501 map->add(len, gen.len () - 1, neuroToMap(i));511 map->add(len, gen.length() - 1, neuroToMap(i)); 502 512 } 503 513 for (a = 0; a < neurons.size(); a++) … … 526 536 nc.info = **s; 527 537 connparam.select(&nc); 528 len = gen.len ();538 len = gen.length(); 529 539 gen += "c:"; 530 540 connparam.saveSingleLine(gen, handle_defaults ? &defaultconn : NULL, true, !handle_defaults); 531 541 if (map) 532 map->add(len, gen.len () - 1, neuroToMap(n->refno));542 map->add(len, gen.length() - 1, neuroToMap(n->refno)); 533 543 } 534 544 } … … 541 551 } 542 552 543 g = Geno(gen.c_str(), '0'); 553 g = Geno(gen.c_str(), genoFormatForShapeType(getShapeType()), "", ""); 554 } 555 556 SString Model::genoFormatForShapeType(ShapeType st) 557 { 558 switch (st) 559 { 560 case SHAPE_BALL_AND_STICK: 561 return "0"; 562 case SHAPE_SOLIDS: 563 return "0s"; 564 default: 565 return Geno::INVALID_FORMAT; 566 } 567 } 568 569 Model::ShapeType Model::shapeTypeForGenoFormat(const SString& format) 570 { 571 if (format == "0") 572 return SHAPE_BALL_AND_STICK; 573 else if (format == "0s") 574 return SHAPE_SOLIDS; 575 else 576 return SHAPE_UNKNOWN; 577 578 } 579 580 const char* Model::getShapeTypeName(ShapeType sh) 581 { 582 switch (sh) 583 { 584 case SHAPE_BALL_AND_STICK: return "ball-and-stick"; 585 case SHAPE_SOLIDS: return "solid shapes"; 586 case SHAPE_UNKNOWN: return "unknown"; 587 588 case SHAPE_ILLEGAL: 589 default: 590 return "illegal"; 591 } 544 592 } 545 593 … … 653 701 if (result < 0) 654 702 { 655 if (error_message.len () == 0) // generic error when no detailed message is available703 if (error_message.length() == 0) // generic error when no detailed message is available 656 704 error_message = "Invalid f0 code"; 657 705 if (line_num > 0) … … 731 779 { 732 780 // default class for unparented units: standard neuron 733 if (nu->getClassName().len () == 0) nu->setClassName("N");781 if (nu->getClassName().length() == 0) nu->setClassName("N"); 734 782 } 735 783 /* … … 832 880 SString Model::nameForErrors() const 833 881 { 834 if (geno.getName().len () > 0)882 if (geno.getName().length() > 0) 835 883 return SString::sprintf(" in '%s'", geno.getName().c_str()); 836 884 return SString::empty(); … … 1061 1109 if (shape == SHAPE_ILLEGAL) 1062 1110 ret = 0; 1111 else if ((declared_shape != SHAPE_UNKNOWN) && (declared_shape != shape)) 1112 { 1113 logPrintf("Model", "internalCheck", LOG_ERROR, "Model shape type '%s' does not match the declared type '%s'", getShapeTypeName(shape), getShapeTypeName(declared_shape)); 1114 ret = 0; 1115 } 1116 1063 1117 return ret; 1064 1118 }
Note: See TracChangeset
for help on using the changeset viewer.