-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.h
More file actions
108 lines (88 loc) · 2.76 KB
/
common.h
File metadata and controls
108 lines (88 loc) · 2.76 KB
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
#ifndef __COMMON_H__
#define __COMMON_H__
#include <cstdint>
#include <iostream>
#include <fstream>
#include <random>
#ifdef USE_MPI
#include <mpi.h>
#endif
#include "pes/pes.h"
#define UNIQUE_MIN_SIZE_LOWBOUND 3
#define RHO_LIM 0.1
#define RSQ_LIM 1.0
#define DIST_LIM 1000000.00
#define FITNESS_LIM 1000000.00
#define RHO_FRAC_INIT 0.1
#define FAILURE_LIM_INIT 5
#define SUCCESS_LIM_INIT 15
#define ADD_DELAYS true
#define MEAN_ENERGY_EVAL_TIME 1.0e-2
#define STD_ENERGY_EVAL_TIME 1.0e-3
#define MEAN_GRAD_EVAL_TIME 1.0e-2
#define STD_GRAD_EVAL_TIME 1.0e-3
extern int num_dim;
extern int num_agents_min_tot;
extern int num_agents_ts;
extern int num_threads;
#ifdef USE_MPI
extern int mpi_rank;
extern int num_procs;
extern int mpi_root;
#endif
extern int verbosity;
// Particle Data Structure
typedef struct agent_base_t {
int id; // Agent ID
double* pos; // Position
double* vel; // Velocity
double fitness; // Fitness
double* pos_best; // Best position
double fitness_best; // Best fitness value
} agent_base_t;
typedef struct agent_prop_t {
double* pos; // Position
} agent_prop_t;
typedef struct swarm_prop_t {
int id; // Swarm ID
double* pos_best; // Best position
double fitness_best; // Best fitness value
double radius_sq; // Radius - squared
int num_agent;
} swarm_prop_t;
typedef struct ts_link_t {
int minima_one;
int minima_two;
int owner;
int iterations;
int steps;
bool converged;
double* ts_position;
} ts_link_t;
#ifdef USE_MPI
typedef struct mapping_t {
int rank;
int part_id;
int swarm_id;
} mapping_t;
#endif // USE_MPI
struct double_int{ double d; int i; };
// Region Data Structure
typedef struct region_t {
double* lo;
double* hi;
} region_t;
// Functions
void factor (int* sizes, int num_proc, int num_dimensions);
void get_indices (int* indices, int* sizes, int n, int num_dimensions);
void init_agents(agent_base_t* agents, int num_agents, region_t region);
void save(std::ofstream& fsave, agent_base_t* agents, int num_agents, region_t region);
void save_molecular(std::ofstream& fsave, std::string* species,
agent_base_t* agents, int num_agents, region_t region);
void save_polychrome(std::ofstream& fsave, agent_base_t** agent_bases, int* num_agent_bases,
int num_swarms, region_t region);
// Command Line Option Processing
int find_arg_idx(int argc, char** argv, const char* option);
int find_int_arg(int argc, char** argv, const char* option, int default_value);
char* find_string_option(int argc, char** argv, const char* option, char* default_value);
#endif