Ignore:
Timestamp:
04/27/23 04:04:06 (12 months ago)
Author:
Maciej Komosinski
Message:

Improvements in f4:

  • fixed a bug where newly created cells in a given development step were not counted as in-active-development (overlooked), and if they were the only in-active-development cells, the development of an organism would stop
  • added one extra development step (#ifdef EXTRA_STEP_CELL_DEVELOPMENT) so that cells that became not in-active-development ("halted" or yielding, usually due to waiting for neurons to develop in other cells) would get a chance to continue development (important when we don't want to ignore invalid neuron connections, #ifdef TREAT_BAD_CONNECTIONS_AS_INVALID_GENO)
  • ensured that all connections in a cell are processed (earlier they could be skipped if the development of the cell was "halted" and all cells became not in-active-development)
  • got rid of neuron connection syntax [sensor:weight], now all neuron classes are handled in a uniform way and their [connections] too; the only allowed syntax is [input_index:weight]
  • unified handling of all neuroclasses during parsing, conversion and mutation
  • more correct syntax coloring
  • got rid of general-purpose fields (i1, i2, f1, s1) in class f4_node - now separate fields serve their individual purpose
  • rewritten creating and modifying neuron connections - it is more deliberate to satisfy neuron input/output preferences
  • some invalid neuron connections make a genotype invalid (previously invalid neuron connections were ignored and the genotype was considered valid)
  • added (surprisingly missing) simple debug printout functions to see the f4_Node tree structure and the developing f4_Cells
  • more informative variable and constant names
  • improved performance
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/f4_oper.h

    r779 r1227  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2017  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    3333//@}
    3434
     35/** @name Codes for specific F4_MOD neuron mutation subtypes (not included in mutation_method_names, all are considered F4_MOD there) */
     36//@{
     37#define F4_MODNEU_CONN     0
     38#define F4_MODNEU_WEIGHT   1
     39#define F4_MODNEU_COUNT    2
     40//@}
     41
    3542class Geno_f4 : public GenoOperators
    3643{
     
    4855        // mutation probabilities
    4956        double prob[F4_COUNT];            ///<relative probabilities of selecting mutation types in f4 genotype
    50         double probadd[F4_ADD_COUNT];     ///<relative probabilities of selecting mutation addition subtypes
     57        double probadd[F4_ADD_COUNT];     ///<relative probabilities of selecting addition mutation subtypes
     58        double probmodneu[F4_MODNEU_COUNT];     ///<relative probabilities of selecting neuron mutation subtypes
     59        paInt mut_max_rep;                ///maximum allowed number of repetitions for the '#' repetition gene
    5160
    5261        SString excluded_modifiers;       ///<Modifiers that are excluded in mutation process
     
    6372         * @return GENOOPER_OK if genotype is valid, GENOPER_REPAIR if genotype can be repaired, GENOPER_OPFAIL if genotype can't be repaired
    6473         */
    65         int  ValidateRec(f4_node *geno, int retrycount) const;
     74        int  ValidateRec(f4_Node *geno, int retrycount) const;
    6675
    6776        /**
     
    8695         * @return GENOPER_OK if mutation was performed successfully, GENOPER_FAIL otherwise
    8796         */
    88         int  MutateOne(f4_node *& g, int &method) const;
     97        int  MutateOne(f4_Node *& g, int &method) const;
    8998
    9099        /**
    91          * Creates a random connection to an existing neuron or creates an additional
     100         * Finds all neurons in g (in the order of ordNode()) and returns their neuroclasses in a vector.
     101         * Additionally, looks for the needle_neuron node and returns its index (in the list of the returned vector) as found_index,
     102         * or -1 if not found (for example, it was not a neuroclass node or not added to the "g" tree).
     103         * @param g root node
     104         * @param needle_neuron neuroclass node to look for in all nodes
     105         * @param found_index returned index of needle
     106         * @return all nodes that are neurons
     107         */
     108        static vector<NeuroClass*> findAllNeuronsAndNode(f4_Node * const & g, f4_Node* const &needle_neuron, int &found_index);
     109
     110        /**
     111         * Finds indexes of a given neuron and another random (output- or input-providing) neuron in the list of all neurons present in the "g" tree.
     112         * @param g root node
     113         * @param neuron neuroclass node to look for in all nodes in g
     114         * @param other_has_output if true, other neuron will provide output; otherwise, it will accept input(s)
     115         * @param neuron_index returned index of neuron
     116         * @param other_neuron_index returned index of a random neuron that provides an output or accepts inputs
     117         * @return true if succeeded, false otherwise
     118         */
     119        static bool findConnectionNeuronIndexes(f4_Node * const &g, f4_Node *neuron, bool other_has_output, int &neuron_index, int &other_neuron_index);
     120
     121        /**
     122         * Creates a random connection to an existing neuron and randomizes connection weight
    92123         * sensor for a neuron.
    93124         * @param nn neuron class node
    94          * @param neuid id of a neuron
    95          * @param neulist list of genotype neuron classes
     125         * @param nn_index index of the nn neuron
     126         * @param other_index index of the neuron providing output, to get input from
    96127         */
    97         void linkNodeMakeRandom(f4_node *nn, int neuid, std::vector<NeuroClass*> neulist) const;
    98 
    99         /**
    100          * Changes connection to an existing neuron or creates an additional
    101          * sensor for neuron.
    102          * @param nn neuron connection node
    103          * @param neuid id of a neuron
    104          * @param neulist list of genotype neuron classes
    105          */
    106         void linkNodeChangeRandom(f4_node *nn, int neuid, std::vector<NeuroClass*> neulist) const;
     128        void connectionNodeChangeRandom(f4_Node *nn, int nn_index, int other_index) const;
    107129
    108130        /**
     
    110132         * @param nn neuron node
    111133         */
    112         void nparNodeMakeRandom(f4_node *nn) const;
     134        void nparNodeMakeRandom(f4_Node *nn) const;
    113135
    114136        /**
     
    116138         * @param nn repetition node
    117139         */
    118         void repeatNodeChangeRandom(f4_node *nn) const;
     140        void repeatNodeChangeRandom(f4_Node *nn) const;
    119141
    120142        /**
     
    124146         * @return GENOPER_OK if performed successful mutation, GENOPER_FAIL otherwise
    125147         */
    126         int  MutateOneValid(f4_node *&g, int &method) const;
     148        int  MutateOneValid(f4_Node *&g, int &method) const;
    127149
    128150        /**
     
    134156         * @param chg percentage of the first parent in offspring (the second parent has the rest)
    135157         */
    136         int  CrossOverOne(f4_node *g1, f4_node *g2, float chg) const;
     158        int  CrossOverOne(f4_Node *g1, f4_Node *g2, float chg) const;
    137159};
    138160
Note: See TracChangeset for help on using the changeset viewer.