Ignore:
Timestamp:
06/30/20 00:32:56 (4 years ago)
Author:
Maciej Komosinski
Message:

fS: preserved volume during shape-type changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fS/fS_general.h

    r958 r969  
    1414#include "frams/util/multirange.h"
    1515
    16 /** @name Names of genotype modes */
    17 //@{
    18 #define MODIFIER_MODE 'M'
    19 #define PARAM_MODE 'S'
    20 #define CYCLE_MODE 'J'
    21 //@}
    22 
    2316/** @name Values of constants used in encoding */
    2417//@{
    2518#define BRANCH_START '('
    2619#define BRANCH_END ')'
    27 #define BRANCH_SEPARATOR ','
     20#define BRANCH_SEPARATOR '^'
    2821#define PARAM_START '{'
    2922#define PARAM_END '}'
     
    4538/** @name Every modifier changes the underlying value by this multiplier */
    4639const 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 
    5040/**
    5141 * Used in finding the proper distance between the parts
     
    7060#define INGESTION "i"
    7161#define FRICTION "f"
     62#define STIFFNESS "st"
    7263#define SIZE "s"
    7364#define SIZE_X "x"
     
    8071#define RY "ry"
    8172#define RZ "rz"
    82 #define JOINT_DISTANCE "j"
    8373//@}
    8474/** @name Macros and values used in collision detection */
     
    113103const char DEFAULT_JOINT = 'a';
    114104const string JOINTS = "bc";
     105const string ALL_JOINTS = "abc";
    115106const int JOINT_COUNT = JOINTS.length();
    116 const string MODIFIERS = "IFS";
     107const string MODIFIERS = "IFST";
    117108const char SIZE_MODIFIER = 's';
    118109const 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};
    120111
    121112/** @name Default values of node parameters*/
    122113static const Part defPart = Model::getDefPart();
    123 const std::map<string, double> defaultParamValues = {
     114static const Joint defJoint = Model::getDefJoint();
     115const 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};
     120const std::map<string, double> defaultValues = {
    124121                {INGESTION,      defPart.ingest},
    125122                {FRICTION,       defPart.friction},
     123                {STIFFNESS,              defJoint.stif},
    126124                {ROT_X,          0.0},
    127125                {ROT_Y,          0.0},
     
    133131                {SIZE_X,         1.0},
    134132                {SIZE_Y,         1.0},
    135                 {SIZE_Z,         1.0},
    136                 {JOINT_DISTANCE, 1.0}
     133                {SIZE_Z,         1.0}
     134};
     135
     136const 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
     152const 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}
    137166};
    138167
     
    252281        double ing = 1.0;      /// Ingestion multiplier
    253282        double s = 1.0;      /// Size multipliers
     283        double stif = 1.0;      /// Stiffness multipliers
    254284
    255285        State(State *_state); /// Derive the state from parent
     
    301331private:
    302332        Substring *partDescription = nullptr;
    303         bool cycleMode, modifierMode, paramMode; /// Possible modes
    304333        Node *parent;
    305334        Part *part;     /// A part object built from node. Used in building the Model
     
    309338        vector<Node *> children;    /// Vector of all direct children
    310339        std::map<char, int> modifiers;     /// Vector of all modifiers
    311         char joint = DEFAULT_JOINT;           /// Set of all joints
    312340        vector<fS_Neuron *> neurons;    /// Vector of all the neurons
    313341
    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();
    333343
    334344        void cleanUp();
     
    384394         * @param _state state of the parent
    385395         */
    386         void getState(State *_state, const Pt3D &parentSize);
     396        void getState(State *_state);
    387397
    388398        /**
     
    419429
    420430public:
     431        char joint = DEFAULT_JOINT;           /// Set of all joints
    421432        Part::Shape partType;  /// The type of the part
    422433        State *state = nullptr; /// The phenotypic state that inherits from ancestors
    423434
    424         Node(Substring &genotype, bool _modifierMode, bool _paramMode, bool _cycleMode, Node *parent);
     435        Node(Substring &genotype, Node *parent);
    425436
    426437        ~Node();
     
    452463         * @return True if the parameter value was change, false otherwise
    453464         */
    454         bool changeSizeParam(string paramKey, double multiplier, bool ensureCircleSection);
     465        bool changeSizeParam(string paramKey, bool ensureCircleSection);
    455466
    456467        /**
     
    501512
    502513        static int precision;
     514        static bool TURN_WITH_ROTATION;
    503515
    504516        /**
     
    511523
    512524        void getState();
    513 
    514         /**
    515          * Get a random multiplier for parameter mutation
    516          * @return Random parameter multiplier
    517          */
    518         static double randomParamMultiplier();
    519525
    520526        /**
Note: See TracChangeset for help on using the changeset viewer.