Fast IFS using RPN notation
python
c
x86-64
nasm
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

rpn_ifs_mutate.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2020,2023 Weber Yann
  3. *
  4. * This file is part of pyrpn.
  5. *
  6. * pyrpn is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * pyrpn is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with pyrpn. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __rpn_ifs_mutate__h__
  20. #define __rpn_ifs_mutate__h__
  21. #include "config.h"
  22. #include <assert.h>
  23. #include <errno.h>
  24. #include <stdint.h>
  25. #include <sys/random.h>
  26. #include "rpn_mutate.h"
  27. #include "rpn_if_mutate.h"
  28. #include "rpn_ifs.h"
  29. /**@file rpn_ifs_mutate.h
  30. * @brief rpn_ifs_t mutation headers
  31. * @todo implement function to mutate IF (in another file ? : yep)
  32. */
  33. /**@brief IFS mutation parameters */
  34. typedef struct ifs_mutation_weights_s ifs_mutation_weights_t;
  35. /**@brief IFS mutation parameters
  36. * @todo add weights for mutations of IF (weights for component mutation in IF)
  37. */
  38. struct ifs_mutation_weights_s
  39. {
  40. /**@brief Weight for mutation type : expr, weight */
  41. float w_mut_type[2];
  42. /**@brief internal use fast random choice for mutation type */
  43. rnd_t _w_type[2];
  44. /**@brief Minimum & maximum weight variation (considering weights
  45. * in [0.0 .. 1.0] and sum(weights) == 1.0 */
  46. float w_weight_range[2];
  47. /**@brief Number of IF in the system */
  48. size_t if_count;
  49. /**@brief Weight for each IF (chance to mutate) */
  50. float *w_mut_if;
  51. /**@brief internal use fast random choice for if mutation */
  52. rnd_t *_w_if;
  53. /**@brief IF component mutation weights */
  54. if_mutation_weight_t *w_comp_if;
  55. rnd_t *_w_comp_if;
  56. /**@brief Can be if->rpn_sz (number of component in an IF) or
  57. * if_count * if->rpn_sz (one weight for each component of each IF) */
  58. size_t w_comp_if_sz;
  59. /**@brief If 1 if_mut_params will countain if_count params else 1 */
  60. short custom_params;
  61. /**@brief Optionnal (or NULL) array for custom parameters for
  62. * each IF */
  63. rpn_mutation_params_t *if_mut_params;
  64. };
  65. /**@brief Allocate internal fields according to the number of IF in the
  66. * system
  67. * @param res The struct to allocate in
  68. * @param sz The number of if in the system
  69. * @param custom_params If 0 do not allocate
  70. * @ref ifs_mutation_weights_s::if_mut_params
  71. * @param custom_comp_if Determine the value in
  72. * @ref ifs_mutation_weights_s::w_comp_if_sz. If 0 allocate
  73. * one weight per IF component, else allocate one weight for
  74. * each component in each IF.
  75. * @return 0 if no error else -1 and sets errno */
  76. int ifs_mutation_weights_alloc(ifs_mutation_weights_t *res,
  77. rpn_ifs_t *ifs, short custom_params, short custom_comp_if);
  78. /**@brief When needed reallocate internal fields to match the number of IF in
  79. * the system.
  80. * @note Weights added by reallocation will be the weights average
  81. * @note New if_mut_params added by reallocation will be copies of previous
  82. * mutation params
  83. * @param res The struct to reallocate in
  84. * @param if_count The new IF count to addapt to
  85. * @return 0 if no error else -1 and sets errno */
  86. int ifs_mutation_weights_if_count_update(ifs_mutation_weights_t *res,
  87. size_t new_if_count);
  88. /**@brief Deallocate internal fields
  89. * @param res The struct to cleanup */
  90. void ifs_mutation_weights_dealloc(ifs_mutation_weights_t *w);
  91. /**@brief Once allocate and all values set use this function to
  92. * update internal fast random indexes
  93. * @param w the ifs weights to update
  94. * @return 0 if no error else -1 and sets errno */
  95. int ifs_mutation_weights_update(ifs_mutation_weights_t *w);
  96. /**@brief Use updated weights to mutate an IFS
  97. * @param ifs The system to mutate
  98. * @param w The mutation weights & parameters
  99. * @param n_mut The number of mutations
  100. * @param default_mut_params If custom
  101. * @ref ifs_mutation_weights_s::if_mut_params params for each IF in
  102. * the system not set, this argument must be not NULL and is used
  103. * as IF mutation parameter
  104. */
  105. int ifs_mutation(rpn_ifs_t *ifs, ifs_mutation_weights_t *w, size_t n_mut);
  106. int ifs_weight_mutation(rpn_ifs_t *ifs, ifs_mutation_weights_t *w, size_t n_mut);
  107. int ifs_if_mutation(rpn_ifs_t *ifs, ifs_mutation_weights_t *w, size_t n_mut);
  108. #endif