<commit_before>/* individual.hpp - CS 472 Project #2: Genetic Programming
 * Copyright 2014 <NAME>
 *
 * Header file for interface of an individual representing a
 * gentically generated solution function
 */

#ifndef _INDIVIDUAL_H_
#define _INDIVIDUAL_H_

#include <vector>
#include <memory>
#include "../problem/problem.hpp"

namespace individual {
  using problem::Problem;
  using std::string;

  enum Function {
    null,
    constant, input,
    sqrt, sin, log, exp,
    add, subtract, divide, multiply, pow,
    lesser, greater };

  struct Size {
    int internals = 0;
    int leafs = 0;
  };

  class Node {
  private:
    Function function = null;
    int arity = 0; // space for time trade-off
    double k = 0; // excess for internal nodes
    std::vector<Node> children;
    void set_constant(const double &, const double &);
    void mutate_self(const double &, const double &);
  public:
    Node() {};
    Node(const Problem &, const int & depth = 0);
    string print() const;
    string represent() const;
    double evaluate(const double &) const;
    const Size size() const;
    Node & visit(const int &, int &);
    void mutate_tree(const double &, const double &, const double &);
  };

  class Individual {
  private:
    Size size;
    double fitness;
    Node root;
  public:
    Individual(const Problem &);
    string print_formula() const;
    string print_calculation(const problem::pairs &) const;
    int get_internals() const {return size.internals;}
    int get_leafs() const {return size.leafs;}
    int get_total() const {return size.internals + size.leafs;}
    double get_fitness() const {return fitness;}
    void update_size();<commit_msg>Adding default constructor to Individual<commit_after>/* individual.hpp - CS 472 Project #2: Genetic Programming
 * Copyright 2014 <NAME>
 *
 * Header file for interface of an individual representing a
 * gentically generated solution function
 */

#ifndef _INDIVIDUAL_H_
#define _INDIVIDUAL_H_

#include <vector>
#include <memory>
#include "../problem/problem.hpp"

namespace individual {
  using problem::Problem;
  using std::string;

  enum Function {
    null,
    constant, input,
    sqrt, sin, log, exp,
    add, subtract, divide, multiply, pow,
    lesser, greater };

  struct Size {
    int internals = 0;
    int leafs = 0;
  };

  class Node {
  private:
    Function function = null;
    int arity = 0; // space for time trade-off
    double k = 0; // excess for internal nodes
    std::vector<Node> children;
    void set_constant(const double &, const double &);
    void mutate_self(const double &, const double &);
  public:
    Node() {};
    Node(const Problem &, const int & depth = 0);
    string print() const;
    string represent() const;
    double evaluate(const double &) const;
    const Size size() const;
    Node & visit(const int &, int &);
    void mutate_tree(const double &, const double &, const double &);
  };

  class Individual {
  private:
    Size size;
    double fitness;
    Node root;
  public:
    Individual() {}
    Individual(const Problem &);
    string print_formula() const;
    string print_calculation(const problem::pairs &) const;
    int get_internals() const {return size.internals;}
    int get_leafs() const {return size.leafs;}
    int get_total() const {return size.internals + size.leafs;}
    double get_fitness() const {return fitness;}
    void update_size();
{'fraction_non_alphanumeric': 0.10859994129732903, 'fraction_numerical': 0.007631347226298797, 'mean_word_length': 3.2976040353089533, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5976134', 'n_tokens_mistral': 1049, 'n_tokens_neox': 997, 'n_words': 346}