Changeset 972 for cpp/frams/model
- Timestamp:
- 07/03/20 00:32:23 (4 years ago)
- Location:
- cpp/frams/model
- Files:
-
- 5 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 } -
cpp/frams/model/model.h
r935 r972 102 102 protected: 103 103 ShapeType shape; 104 ShapeType declared_shape; 104 105 105 106 SString nameForErrors() const; 106 107 int internalcheck(CheckType check); 107 108 108 void init(const Geno &srcgen, bool _using_checkpoints, bool _is_checkpoint);109 void init( );109 void init(const Geno &srcgen, ShapeType sh, bool _using_checkpoints, bool _is_checkpoint); 110 void init(ShapeType sh); 110 111 111 112 void delMap(); … … 136 137 bool isUsingCheckpoints() const { return using_checkpoints; } 137 138 bool isCheckpoint() const { return is_checkpoint; } 139 static SString genoFormatForShapeType(ShapeType st); 140 static ShapeType shapeTypeForGenoFormat(const SString& format); 141 static const char* getShapeTypeName(ShapeType sh); 138 142 139 143 void updateRefno(); // set ::refno for all elements … … 150 154 ModelUserTags userdata; 151 155 152 /// Create empty model with invalid empty genotype 153 Model(); 156 /// Create empty model with invalid empty genotype, declaring the shape type for later operations 157 Model(ShapeType sh = SHAPE_UNKNOWN); 158 159 /// Change the declared shape type of the Model 160 void declareShapeType(ShapeType sh); 154 161 155 162 /** Create a model based on provided genotype … … 158 165 @see getMap() 159 166 */ 160 Model(const Geno &src, bool buildmaps = false, bool _using_checkpoints = false, bool _is_checkpoint = false);167 Model(const Geno &src, ShapeType sh, bool buildmaps = false, bool _using_checkpoints = false, bool _is_checkpoint = false); 161 168 Model(const Model &mod, bool buildmaps = false, bool _using_checkpoints = false, bool _is_checkpoint = false); 162 169 /** duplicate the model. -
cpp/frams/model/modelobj.cpp
r732 r972 58 58 void ModelObj::p_newfromstring(ExtValue *args, ExtValue *ret) 59 59 { 60 *ret = makeDynamicObject(new Model(Geno(args[0].getString()) ));60 *ret = makeDynamicObject(new Model(Geno(args[0].getString()), Model::SHAPE_UNKNOWN)); 61 61 } 62 62 … … 65 65 Geno *g = GenoObj::fromObject(args[0].getObject()); 66 66 if (g) 67 *ret = makeDynamicObject(new Model(*g ));67 *ret = makeDynamicObject(new Model(*g, Model::SHAPE_UNKNOWN)); 68 68 else 69 69 ret->setEmpty(); … … 74 74 Model *m = NULL; 75 75 if (args[0].getType() == TString) 76 m = new Model(Geno(args[0].getString()), false, true);76 m = new Model(Geno(args[0].getString()), Model::SHAPE_UNKNOWN, false, true); 77 77 else 78 78 { 79 79 Geno *g = GenoObj::fromObject(args[0].getObject(), false); 80 80 if (g) 81 m = new Model(*g, false, true);81 m = new Model(*g, Model::SHAPE_UNKNOWN, false, true); 82 82 else 83 83 logPrintf("Model", "newWithCheckpoints", LOG_ERROR, "Geno or string expected, %s found", args[0].typeDescription().c_str()); -
cpp/frams/model/modelparts.h
r952 r972 34 34 { 35 35 public: 36 enum ShapeType { SHAPE_BALL_AND_STICK , SHAPE_SOLIDS, SHAPE_UNKNOWN, SHAPE_ILLEGAL };36 enum ShapeType { SHAPE_BALL_AND_STICK = 0, SHAPE_SOLIDS = 1, SHAPE_UNKNOWN, SHAPE_ILLEGAL }; ///< 0 and 1 have special significance - these values allow for bit operations. 37 37 }; 38 38 -
cpp/frams/model/similarity/simil_model.cpp
r877 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 … … 122 122 123 123 // assign matching function 124 int (ModelSimil:: * pfMatchingFunction) () = NULL;124 int (ModelSimil:: * pfMatchingFunction) () = NULL; 125 125 126 126 pfMatchingFunction = &ModelSimil::MatchPartsGeometry; … … 534 534 return NULL; 535 535 } 536 Model *m = new Model(*g );536 Model *m = new Model(*g, Model::SHAPE_UNKNOWN); 537 537 if (!m->isValid()) 538 538 { … … 2058 2058 { 2059 2059 if (geo) 2060 dist[i *bigger + j] += m_adFactors[3] * m_aPositions[1 - m_iSmaller][i].length();2060 dist[i * bigger + j] += m_adFactors[3] * m_aPositions[1 - m_iSmaller][i].length(); 2061 2061 else 2062 dist[i *bigger + j] = m_adFactors[1] * m_aDegrees[1 - m_iSmaller][i][DEGREE] + m_adFactors[2] * m_aDegrees[1 - m_iSmaller][i][NEURONS];2062 dist[i * bigger + j] = m_adFactors[1] * m_aDegrees[1 - m_iSmaller][i][DEGREE] + m_adFactors[2] * m_aDegrees[1 - m_iSmaller][i][NEURONS]; 2063 2063 } 2064 2064 // compute distance between parts … … 2066 2066 { 2067 2067 if (geo) 2068 dist[i *bigger + j] += m_adFactors[3] * m_aPositions[1 - m_iSmaller][i].distanceTo(m_aPositions[m_iSmaller][j]);2068 dist[i * bigger + j] += m_adFactors[3] * m_aPositions[1 - m_iSmaller][i].distanceTo(m_aPositions[m_iSmaller][j]); 2069 2069 else 2070 dist[i *bigger + j] = m_adFactors[1] * abs(m_aDegrees[1 - m_iSmaller][i][DEGREE] - m_aDegrees[m_iSmaller][j][DEGREE])2070 dist[i * bigger + j] = m_adFactors[1] * abs(m_aDegrees[1 - m_iSmaller][i][DEGREE] - m_aDegrees[m_iSmaller][j][DEGREE]) 2071 2071 + m_adFactors[2] * abs(m_aDegrees[1 - m_iSmaller][i][NEURONS] - m_aDegrees[m_iSmaller][j][NEURONS]); 2072 2072 } … … 2104 2104 int nBigger = m_Mod[1 - m_iSmaller]->getPartCount(); 2105 2105 2106 double* partsDistances = new double[nBigger *nBigger]();2106 double* partsDistances = new double[nBigger * nBigger](); 2107 2107 FillPartsDistances(partsDistances, nBigger, nSmaller, false); 2108 2108 int *assignment = new int[nBigger](); … … 2138 2138 // - models (m_Mod) exist and are available 2139 2139 // - all properties are created and available (m_aDegrees and m_aPositions) 2140 double* tmpPartsDistances = new double[nBigger *nBigger]();2140 double* tmpPartsDistances = new double[nBigger * nBigger](); 2141 2141 std::copy(partsDistances, partsDistances + nBigger * nBigger, tmpPartsDistances); 2142 2142 // recompute geometric properties according to the transformation iTransform
Note: See TracChangeset
for help on using the changeset viewer.