// This file is a part of Framsticks SDK. http://www.framsticks.com/ // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. // Copyright (C) 1999,2000 Adam Rotaru-Varga (adam_rotaru@yahoo.com), GNU LGPL // Copyright (C) since 2001 Maciej Komosinski #ifndef _F4_OPER_H_ #define _F4_OPER_H_ #include #include "f4_general.h" #include "common/nonstd.h" #include "../genooperators.h" #include /** @name Codes for general mutation types */ //@{ #define F4_ADD 0 /// findAllNeuronsAndNode(f4_Node * const & g, f4_Node* const &needle_neuron, int &found_index); /** * 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. * @param g root node * @param neuron neuroclass node to look for in all nodes in g * @param other_has_output if true, other neuron will provide output; otherwise, it will accept input(s) * @param neuron_index returned index of neuron * @param other_neuron_index returned index of a random neuron that provides an output or accepts inputs * @return true if succeeded, false otherwise */ static bool findConnectionNeuronIndexes(f4_Node * const &g, f4_Node *neuron, bool other_has_output, int &neuron_index, int &other_neuron_index); /** * Creates a random connection to an existing neuron and randomizes connection weight * sensor for a neuron. * @param nn neuron class node * @param nn_index index of the nn neuron * @param other_index index of the neuron providing output, to get input from */ void connectionNodeChangeRandom(f4_Node *nn, int nn_index, int other_index) const; /** * Introduces a random modification to the neuron node. * @param nn neuron node */ void nparNodeMakeRandom(f4_Node *nn) const; /** * Increases or decreases the amount of repetitions in the repetition node. * @param nn repetition node */ void repeatNodeChangeRandom(f4_Node *nn) const; /** * Tries to perform a mutation until success. There is a maximum of 20 tries. Returns GENOPER_OK or GENOPER_OPFAIL. * @param g genotype tree * @param method reference to the variable that will get the selected method of mutation * @return GENOPER_OK if performed successful mutation, GENOPER_FAIL otherwise */ int MutateOneValid(f4_Node *&g, int &method) const; /** * Performs crossover of two creatures. The 'chg' parameter determines approximately what * percentage of the first creature should form the offspring. '1-chg' is the percentage * of the second creature in the offspring. * @param g1 first parent * @param g2 second parent * @param chg percentage of the first parent in offspring (the second parent has the rest) */ int CrossOverOne(f4_Node *g1, f4_Node *g2, float chg) const; }; #endif