-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.hpp
More file actions
174 lines (137 loc) · 4.6 KB
/
Copy pathCommon.hpp
File metadata and controls
174 lines (137 loc) · 4.6 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Common.hpp
* Author: matthewsupernaw
*
* Created on September 16, 2016, 12:42 PM
*/
#ifndef COMMON_HPP
#define COMMON_HPP
#include "../ATL/AutoDiff/AutoDiff.hpp"
#include <vector>
#include <map>
namespace mas {
std::ofstream mas_log("mas.log");
template<typename REAL_T>
struct VariableTrait {
typedef atl::Variable<REAL_T> variable;
static void SetName(variable& var, const std::string& value) {
var.SetName(value);
}
static void SetValue(variable& var, const REAL_T& value) {
var.SetValue(value);
}
static void SetMinBoundary(variable& var, const REAL_T& value) {
var.SetMinBoundary(value);
}
static void SetMaxBoundary(variable& var, const REAL_T& value) {
var.SetMaxBoundary(value);
}
};
template<typename REAL_T>
struct ModelObject {
typedef typename VariableTrait<REAL_T>::variable variable;
int id;
std::map<variable*, int> estimated_parameters_map;
typedef typename std::map<variable*, int>::iterator estimable_parameter_iterator;
std::vector<variable*> estimated_parameters;
std::vector<int> estimated_phase;
void Register(variable& var, int phase = 1) {
estimated_parameters_map[&var] = phase;
this->estimated_parameters.push_back(&var);
this->estimated_phase.push_back(phase);
}
};
enum DataUnits {
MT = 0,
KG,
LBS,
IT,
NUMBERS,
NA
};
enum DataObjectType {
CATCH_BIOMASS = 0,
CATCH_PROPORTION_AT_AGE,
CATCH_PROPORTION_AT_LENGTH,
CATCH_MEAN_SIZE_AT_AGE,
SURVEY_BIOMASS = 0,
SURVEY_PROPORTION_AT_AGE,
SURVEY_PROPORTION_AT_LENGTH,
SURVEY_MEAN_SIZE_AT_AGE,
UNKNOWN
};
enum FishSexType {
MALE = 0,
FEMALE,
UNDIFFERENTIATED
};
template<typename REAL_T>
struct DataObject {
std::vector<REAL_T> data;
DataObjectType type;
FishSexType sex_type;
DataUnits units;
std::string name;
uint32_t area_id;
uint32_t population_id;
uint32_t dimensions;
size_t imax;
size_t jmax;
size_t kmax;
size_t lmax;
size_t mmax;
size_t nmax;
inline REAL_T& get(int i) {
return data[i];
}
inline REAL_T& get(int i, int j) {
return data[i * jmax + j];
}
inline REAL_T& get(int i, int j, int k) {
return data[i * jmax * kmax + j * kmax + k];
}
inline REAL_T& get(int i, int j, int k, int l) {
return data[i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l];
}
inline REAL_T& get(int i, int j, int k, int l, int m) {
return data[i * jmax * kmax * lmax * mmax + j * kmax * lmax * mmax + k * lmax * mmax + l * mmax + m];
}
inline REAL_T& get(int i, int j, int k, int l, int m, int n) {
return data[i * jmax * kmax * lmax * mmax * nmax + j * kmax * lmax * mmax * nmax + k * lmax * mmax * nmax + l * mmax * nmax + m * nmax + m];
}
static DataObjectType GetType(const std::string& str) {
if (str == "catch_biomass") {
return CATCH_BIOMASS;
} else if (str == "catch_proportion_at_age") {
return CATCH_PROPORTION_AT_AGE;
} else if (str == "catch_proportion_at_length") {
return CATCH_PROPORTION_AT_LENGTH;
} else if (str == "catch_mean_size_at_age") {
return CATCH_MEAN_SIZE_AT_AGE;
} else if (str == "survey_biomass") {
return CATCH_BIOMASS;
} else if (str == "survey_proportion_at_age") {
return CATCH_PROPORTION_AT_AGE;
} else if (str == "survey_proportion_at_length") {
return CATCH_PROPORTION_AT_LENGTH;
} else if (str == "survey_mean_size_at_age") {
return CATCH_MEAN_SIZE_AT_AGE;
} else {
std::cout << "Data Error: unknown data_object_type \"" << str << "\"";
}
return UNKNOWN;
}
};
template <typename T>
T StringToNumber(const std::string &Text) {
std::istringstream ss(Text);
T result;
return (ss >> result) ? result : 0;
}
}
#endif /* COMMON_HPP */