-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic_operators.h
executable file
·132 lines (109 loc) · 3.91 KB
/
generic_operators.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef GENOP_H
#define GENOP_H
//C Libraries
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
//P-GP2 Libraries
#include "common.h"
#include "debug.h"
#include "graph.h"
#include "graphStacks.h"
#include "parser.h"
#include "morphism.h"
#include "utils.h"
#include "common_functions.h"
typedef struct GP_Dataset {
int inputs;
int outputs;
int rows;
double** data;
} GP_Dataset;
typedef struct GP_1_plus_lambda_env{
Graph* (*mutate)(Graph* host, Function_Set* fset, double mutation_rate);
Function_Set* fset;
double mutation_rate;
int winner_index;
int pop_size;
double winner_score;
bool maximise;
bool neutral_drift;
} GP_1_plus_lambda_env;
typedef struct GP_n_plus_lambda_env{
Graph* (*mutate)(Graph* host, Function_Set* fset, double mutation_rate);
Function_Set* fset;
double mutation_rate;
int* winner_index;
int pop_size;
double* winner_score;
bool maximise;
bool neutral_drift;
} GP_n_plus_lambda_env;
typedef struct GP_tournament_env{
Graph* (*mutate)(Graph* host, Function_Set* fset, double mutation_rate);
Function_Set* fset;
double mutation_rate;
Graph* (*crossover)(Graph* hostA, Graph* hostB);
double crossover_p;
int pop_size;
int tournament_size;
bool maximise;
} GP_tournament_env;
typedef struct GP_eval_env{
Function_Set* fset;
GP_Dataset* dataset;
int pop_size;
} GP_eval_env;
typedef struct GP_eval_square_env{
Function_Set* fset;
GP_Dataset* dataset;
int pop_size;
} GP_eval_square_env;
typedef struct Target_0_env{
int pop_size;
} Target_0_env;
typedef struct Target_x_env{
int pop_size;
double x;
} Target_x_env;
typedef struct Target_worst_x_env{
int pop_size;
double x;
double (*get_worst_score)(Graph* graph, GP_Dataset* dataset, Function_Set* fset);
GP_Dataset* dataset;
Function_Set* fset;
} Target_worst_x_env;
typedef struct Fixed_pop_env{
int pop_size;
} Fixed_pop_env;
//Loads a dataset
GP_Dataset* load_data_set(char* file, int inputs, int rand_inputs, double rand_min, double rand_max, int outputs, int rows);
void freeDataset(GP_Dataset* dataset);
//Performs a 1 plus Lambda select + repopulate
Graph** GP_1_plus_lambda(Graph** population, double* scores, uintptr_t GP_1_plus_lambda_env_pointer);
//Performs a n plus Lambda select + repopulate
Graph** GP_n_plus_lambda(Graph** population, double* scores, uintptr_t GP_n_plus_lambda_env_pointer);
//Performs a tournament selection select + repopulate
Graph** GP_tournament_selection(Graph** population, double* scores, uintptr_t GP_tournament_env_pointer);
//Evaluates a computational network against a dataset
double gp_evaluate(Graph* individual, GP_Dataset* dataset, Function_Set* fset);
//Evaluates a computational network against a dataset
double gp_evaluate_square(Graph* individual, GP_Dataset* dataset, Function_Set* fset);
//Evaluates a computational network against a dataset
double gp_evaluate_worst (Graph* individual, GP_Dataset* dataset, Function_Set* fset);
//Evaluates a computational network against a dataset, printing the result
double gp_print_evaluate(Graph* individual, GP_Dataset* dataset, Function_Set* fset);
//Evaluates a whole population using gp_evaluate
double* gp_evaluate_population(Graph** population, uintptr_t GP_eval_env_pointer);
//Evaluates a whole population using gp_evaluate_square
double* gp_evaluate_square_population(Graph** population, uintptr_t GP_eval_square_env_pointer);
//returns 0 when a population contains an individual scoring exactly 0
bool target_0(Graph** population, double* scores, uintptr_t target_0_env);
//returns 0 when a population contains an individual scoring <= x
bool target_x(Graph** population, double* scores, uintptr_t target_x_env_pointer);
bool target_worst_x(Graph** population, double* scores, uintptr_t target_worst_x_env_pointer);
int fixed_pop_size(Graph** population, uintptr_t pop_size_env);
#endif