-
Notifications
You must be signed in to change notification settings - Fork 0
/
algorithm.hpp
96 lines (83 loc) · 3.49 KB
/
algorithm.hpp
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
#ifndef ALGORITHM_HPP_INCLUDED
#define ALGORITHM_HPP_INCLUDED
#include<ant_config.hpp>
#include<individual.hpp>
#include<evaluation.hpp>
#include<string>
#include<vector>
/**
* Base class for all implementations of evolutionary algorithms
*/
class algorithm
{
private:
std::vector<wire_ptr> load_wires(const std::string&, const std::string&); //called from load_wires, silly?
void create_nec_strs();
protected:
/* common data members for all algorithms */
bool m_auto_seed;
// flag to determine whether to clean and remove nec out files
// nec files will just be overwritten and the wall clock time isn't bad even for exhaustive!
bool m_run_simulator;
float m_exp_weight;
float m_mutation;
float m_max_gain;
float m_max_coup;
float m_min_coup;
std::string m_lua_file;
std::vector<individual_ptr> m_free_inds;
//ant_config_ptr clone(ant_config_ptr);
unsigned int m_min_theta = 0;
float m_step_theta = 46;
float m_incr_theta = 4;
float m_min_phi = 0;
float m_step_phi = 90;
float m_incr_phi = 4;
float m_min_freq = 100;
unsigned int m_step_freq = 1;
float m_incr_freq = 10;
const float gain_wt = 0.5;
const float coupling_wt = 0.5;
unsigned int num_polar(void);
void write_platform(std::ofstream&);
void write_ant(std::ofstream&, ant_config_ptr&, position_ptr&, unsigned int);
void write_excitation(std::ofstream&, unsigned int);
void write_coupling(std::ofstream&, std::vector<int>&);
individual_ptr create_individual(std::string, std::vector<position_ptr> &);
float compare(const evaluation_ptr &, const evaluation_ptr &);
std::vector<individual_ptr> breed(const individual_ptr&, const individual_ptr&);
void simple_mutation(individual_ptr&);
std::vector<position_ptr> mutate_pos_once(std::vector<position_ptr>&);
std::vector<position_ptr> mutate_pos(std::vector<position_ptr>&);
bool overlap(std::vector<position_ptr>&, position_ptr&);
void save_best_nec(individual_ptr&, unsigned int, unsigned int);
void save_population(std::vector<individual_ptr>&, unsigned int, unsigned int);
void save_norm(const std::string&);
unsigned int read_radiation(const std::string, const evaluation_ptr &);
float read_coupling(const std::string, unsigned int);
float cal_fitness(individual_ptr&);
public:
algorithm(std::string);
virtual ~algorithm(void);
std::vector<ant_config_ptr> m_ant_configs; //stores antennas positions and all wires mentioned in the nec file
ant_config_ptr m_platform;
void setup_ant_placements();
void load_nec_files();
void setup_run_context();
void write_freespace();
void run_freespace();
void read_freespace();
virtual void setup_algo_params();
virtual void run(unsigned int) = 0;
virtual void run_simulation(unsigned int) = 0;
};
// body of an inline function needs to be in the header so that the compiler can actually replace it
inline float algorithm::cal_fitness(individual_ptr &ind)
{
return ((gain_wt * ind->m_gain_fitness) + (coupling_wt * ind->m_coupling_fitness));
}
inline unsigned int algorithm::num_polar(void)
{
return m_step_theta * m_step_phi;
}
#endif