123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- /*
- * Copyright (C) 2020,2023 Weber Yann
- *
- * This file is part of pyrpn.
- *
- * pyrpn is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * any later version.
- *
- * pyrpn is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with pyrpn. If not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef __rpn_ifs_mutate__h__
- #define __rpn_ifs_mutate__h__
- #include "config.h"
-
- #include <assert.h>
- #include <errno.h>
- #include <stdint.h>
- #include <sys/random.h>
-
- #include "rpn_mutate.h"
- #include "rpn_if_mutate.h"
- #include "rpn_ifs.h"
-
-
- /**@file rpn_ifs_mutate.h
- * @brief rpn_ifs_t mutation headers
- * @todo implement function to mutate IF (in another file ? : yep)
- */
-
-
- /**@brief IFS mutation parameters */
- typedef struct ifs_mutation_weights_s ifs_mutation_weights_t;
-
- /**@brief IFS mutation parameters
- * @todo add weights for mutations of IF (weights for component mutation in IF)
- */
- struct ifs_mutation_weights_s
- {
- /**@brief Weight for mutation type : expr, weight */
- float w_mut_type[2];
-
- /**@brief internal use fast random choice for mutation type */
- rnd_t _w_type[2];
-
- /**@brief Minimum & maximum weight variation (considering weights
- * in [0.0 .. 1.0] and sum(weights) == 1.0 */
- float w_weight_range[2];
-
- /**@brief Number of IF in the system */
- size_t if_count;
-
- /**@brief Weight for each IF (chance to mutate) */
- float *w_mut_if;
-
- /**@brief internal use fast random choice for if mutation */
- rnd_t *_w_if;
-
- /**@brief IF component mutation weights */
- if_mutation_weight_t *w_comp_if;
- rnd_t *_w_comp_if;
- /**@brief Can be if->rpn_sz (number of component in an IF) or
- * if_count * if->rpn_sz (one weight for each component of each IF) */
- size_t w_comp_if_sz;
-
- /**@brief If 1 if_mut_params will countain if_count params else 1 */
- short custom_params;
-
- /**@brief Optionnal (or NULL) array for custom parameters for
- * each IF */
- rpn_mutation_params_t *if_mut_params;
-
-
- };
-
- /**@brief Allocate internal fields according to the number of IF in the
- * system
- * @param res The struct to allocate in
- * @param sz The number of if in the system
- * @param custom_params If 0 do not allocate
- * @ref ifs_mutation_weights_s::if_mut_params
- * @param custom_comp_if Determine the value in
- * @ref ifs_mutation_weights_s::w_comp_if_sz. If 0 allocate
- * one weight per IF component, else allocate one weight for
- * each component in each IF.
- * @return 0 if no error else -1 and sets errno */
- int ifs_mutation_weights_alloc(ifs_mutation_weights_t *res,
- rpn_ifs_t *ifs, short custom_params, short custom_comp_if);
-
- /**@brief When needed reallocate internal fields to match the number of IF in
- * the system.
- * @note Weights added by reallocation will be the weights average
- * @note New if_mut_params added by reallocation will be copies of previous
- * mutation params
- * @param res The struct to reallocate in
- * @param if_count The new IF count to addapt to
- * @return 0 if no error else -1 and sets errno */
- int ifs_mutation_weights_if_count_update(ifs_mutation_weights_t *res,
- size_t new_if_count);
-
- /**@brief Deallocate internal fields
- * @param res The struct to cleanup */
- void ifs_mutation_weights_dealloc(ifs_mutation_weights_t *w);
-
- /**@brief Once allocate and all values set use this function to
- * update internal fast random indexes
- * @param w the ifs weights to update
- * @return 0 if no error else -1 and sets errno */
- int ifs_mutation_weights_update(ifs_mutation_weights_t *w);
-
- /**@brief Use updated weights to mutate an IFS
- * @param ifs The system to mutate
- * @param w The mutation weights & parameters
- * @param n_mut The number of mutations
- * @param default_mut_params If custom
- * @ref ifs_mutation_weights_s::if_mut_params params for each IF in
- * the system not set, this argument must be not NULL and is used
- * as IF mutation parameter
- */
- int ifs_mutation(rpn_ifs_t *ifs, ifs_mutation_weights_t *w, size_t n_mut);
-
- int ifs_weight_mutation(rpn_ifs_t *ifs, ifs_mutation_weights_t *w, size_t n_mut);
-
- int ifs_if_mutation(rpn_ifs_t *ifs, ifs_mutation_weights_t *w, size_t n_mut);
-
- #endif
|