Changeset 969 for cpp/frams/genetics/fS/fS_general.h
- Timestamp:
- 06/30/20 00:32:56 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified cpp/frams/genetics/fS/fS_general.h ¶
r958 r969 14 14 #include "frams/util/multirange.h" 15 15 16 /** @name Names of genotype modes */17 //@{18 #define MODIFIER_MODE 'M'19 #define PARAM_MODE 'S'20 #define CYCLE_MODE 'J'21 //@}22 23 16 /** @name Values of constants used in encoding */ 24 17 //@{ 25 18 #define BRANCH_START '(' 26 19 #define BRANCH_END ')' 27 #define BRANCH_SEPARATOR ' ,'20 #define BRANCH_SEPARATOR '^' 28 21 #define PARAM_START '{' 29 22 #define PARAM_END '}' … … 45 38 /** @name Every modifier changes the underlying value by this multiplier */ 46 39 const double MODIFIER_MULTIPLIER = 1.1; 47 /** @name In mutation parameters will be multiplied by at most this value */48 const double PARAM_MAX_MULTIPLIER = 1.5;49 50 40 /** 51 41 * Used in finding the proper distance between the parts … … 70 60 #define INGESTION "i" 71 61 #define FRICTION "f" 62 #define STIFFNESS "st" 72 63 #define SIZE "s" 73 64 #define SIZE_X "x" … … 80 71 #define RY "ry" 81 72 #define RZ "rz" 82 #define JOINT_DISTANCE "j"83 73 //@} 84 74 /** @name Macros and values used in collision detection */ … … 113 103 const char DEFAULT_JOINT = 'a'; 114 104 const string JOINTS = "bc"; 105 const string ALL_JOINTS = "abc"; 115 106 const int JOINT_COUNT = JOINTS.length(); 116 const string MODIFIERS = "IFS ";107 const string MODIFIERS = "IFST"; 117 108 const char SIZE_MODIFIER = 's'; 118 109 const vector<string> PARAMS {INGESTION, FRICTION, ROT_X, ROT_Y, ROT_Z, RX, RY, RZ, SIZE, SIZE_X, SIZE_Y, SIZE_Z, 119 JOINT_DISTANCE};110 STIFFNESS}; 120 111 121 112 /** @name Default values of node parameters*/ 122 113 static const Part defPart = Model::getDefPart(); 123 const std::map<string, double> defaultParamValues = { 114 static const Joint defJoint = Model::getDefJoint(); 115 const std::map<Part::Shape, double> volumeMultipliers = { 116 {Part::Shape::SHAPE_CUBOID, 8.0}, 117 {Part::Shape::SHAPE_CYLINDER, 2.0 * M_PI}, 118 {Part::Shape::SHAPE_ELLIPSOID, (4.0 / 3.0) * M_PI}, 119 }; 120 const std::map<string, double> defaultValues = { 124 121 {INGESTION, defPart.ingest}, 125 122 {FRICTION, defPart.friction}, 123 {STIFFNESS, defJoint.stif}, 126 124 {ROT_X, 0.0}, 127 125 {ROT_Y, 0.0}, … … 133 131 {SIZE_X, 1.0}, 134 132 {SIZE_Y, 1.0}, 135 {SIZE_Z, 1.0}, 136 {JOINT_DISTANCE, 1.0} 133 {SIZE_Z, 1.0} 134 }; 135 136 const std::map<string, double> minValues = { 137 {INGESTION, 0}, 138 {FRICTION, 0}, 139 {STIFFNESS, 0.0}, 140 {ROT_X, -M_PI}, 141 {ROT_Y, -M_PI}, 142 {ROT_Z, -M_PI}, 143 {RX, -M_PI}, 144 {RY, -M_PI}, 145 {RZ, -M_PI}, 146 {SIZE, 0.01}, 147 {SIZE_X, 0.01}, 148 {SIZE_Y, 0.01}, 149 {SIZE_Z, 0.01} 150 }; 151 152 const std::map<string, double> maxValues = { 153 {INGESTION, 1.0}, 154 {FRICTION, 1.0}, 155 {STIFFNESS, 0.0}, 156 {ROT_X, M_PI}, 157 {ROT_Y, M_PI}, 158 {ROT_Z, M_PI}, 159 {RX, M_PI}, 160 {RY, M_PI}, 161 {RZ, M_PI}, 162 {SIZE, 100.0}, 163 {SIZE_X, 100.0}, 164 {SIZE_Y, 100.0}, 165 {SIZE_Z, 100.0} 137 166 }; 138 167 … … 252 281 double ing = 1.0; /// Ingestion multiplier 253 282 double s = 1.0; /// Size multipliers 283 double stif = 1.0; /// Stiffness multipliers 254 284 255 285 State(State *_state); /// Derive the state from parent … … 301 331 private: 302 332 Substring *partDescription = nullptr; 303 bool cycleMode, modifierMode, paramMode; /// Possible modes304 333 Node *parent; 305 334 Part *part; /// A part object built from node. Used in building the Model … … 309 338 vector<Node *> children; /// Vector of all direct children 310 339 std::map<char, int> modifiers; /// Vector of all modifiers 311 char joint = DEFAULT_JOINT; /// Set of all joints312 340 vector<fS_Neuron *> neurons; /// Vector of all the neurons 313 341 314 static double calculateRadiusFromVolume(Part::Shape partType, double volume) 315 { 316 double result; 317 switch (partType) 318 { 319 case Part::Shape::SHAPE_CUBOID: 320 result = std::cbrt(volume / 8.0); 321 break; 322 case Part::Shape::SHAPE_CYLINDER: 323 result = std::cbrt(volume / (2.0 * M_PI)); 324 break; 325 case Part::Shape::SHAPE_ELLIPSOID: 326 result = std::cbrt(volume / ((4.0 / 3.0) * M_PI)); 327 break; 328 default: 329 logMessage("fS", "calculateVolume", LOG_ERROR, "Invalid part type"); 330 } 331 return result; 332 } 342 double getDistance(); 333 343 334 344 void cleanUp(); … … 384 394 * @param _state state of the parent 385 395 */ 386 void getState(State *_state , const Pt3D &parentSize);396 void getState(State *_state); 387 397 388 398 /** … … 419 429 420 430 public: 431 char joint = DEFAULT_JOINT; /// Set of all joints 421 432 Part::Shape partType; /// The type of the part 422 433 State *state = nullptr; /// The phenotypic state that inherits from ancestors 423 434 424 Node(Substring &genotype, bool _modifierMode, bool _paramMode, bool _cycleMode,Node *parent);435 Node(Substring &genotype, Node *parent); 425 436 426 437 ~Node(); … … 452 463 * @return True if the parameter value was change, false otherwise 453 464 */ 454 bool changeSizeParam(string paramKey, double multiplier,bool ensureCircleSection);465 bool changeSizeParam(string paramKey, bool ensureCircleSection); 455 466 456 467 /** … … 501 512 502 513 static int precision; 514 static bool TURN_WITH_ROTATION; 503 515 504 516 /** … … 511 523 512 524 void getState(); 513 514 /**515 * Get a random multiplier for parameter mutation516 * @return Random parameter multiplier517 */518 static double randomParamMultiplier();519 525 520 526 /**
Note: See TracChangeset
for help on using the changeset viewer.