-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypeDefinitions.h
141 lines (116 loc) · 3.96 KB
/
typeDefinitions.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
133
134
135
136
137
138
139
140
141
/*Created by Nikilesh Ramesh on 02/11/2024 at 13:33
Motivation: To consolidate all the type definitions into one file
*/
#ifndef __TYPE_DEFINITIONS__
#define __TYPE_DEFINITIONS__
#include <vector>
#include <iostream>
// SHOULD THE PRECISION BE DOUBLE INSTEAD OF FLOAT?? --- YES ! IPOPT uses double as default
// https://stackoverflow.com/questions/57542919/how-to-reserve-a-multi-dimensional-vector-without-increasing-the-vector-size (IMP READ)
#define FLOAT_PRECISION double
typedef const unsigned int Index;
typedef std::vector<FLOAT_PRECISION> Gradient;
typedef FLOAT_PRECISION Perturbation;
typedef std::vector<FLOAT_PRECISION> States;
typedef std::vector<std::vector<FLOAT_PRECISION>> StateVectors;
typedef std::vector<FLOAT_PRECISION> StateGradientVectors;
typedef std::vector<FLOAT_PRECISION> Inputs;
typedef std::vector<std::vector<FLOAT_PRECISION>> InputVectors;
typedef FLOAT_PRECISION Time;
typedef std::vector<FLOAT_PRECISION> TimeVector;
typedef FLOAT_PRECISION Cost;
typedef std::vector<FLOAT_PRECISION> CostVector;
typedef std::vector<FLOAT_PRECISION> ConstraintVector;
// operator overloading on std::vector
template <typename T>
std::vector<T> operator+(std::vector<T> v, T val){
for (auto &&i : v)
{
i += val;
}
return v;
}
template <typename T>
std::vector<T> operator+(std::vector<T> v1, std::vector<T> v2){
for (int i = 0; i < v1.size(); i++)
{
v1[i] = v1[i] + v2[i]; //collecting in v1 to avoid making another copy
}
return v1;
}
template <typename T>
std::vector<T> operator-(std::vector<T> v1, std::vector<T> v2){
for (int i = 0; i < v1.size(); i++)
{
v1[i] = v1[i] - v2[i]; //collecting in v1 to avoid making another copy
}
return v1;
}
template <typename T>
std::vector<T> operator*(std::vector<T> v, T val){
for (auto &&i : v)
{
i *= val;
}
return v;
}
template <typename T>
std::vector<T> operator*(std::vector<T> v1, std::vector<T> v2){
for (int i = 0; i < v1.size(); i++)
{
v1[i] = v1[i] * v2[i]; //collecting in v1 to avoid making another copy
}
return v1;
}
typedef struct TripletSparsityFormat {
std::vector<unsigned int> rows;
std::vector<unsigned int> cols;
std::vector<FLOAT_PRECISION> values;
TripletSparsityFormat(const int size){
rows.resize(size);
cols.resize(size);
values.resize(size);
}
TripletSparsityFormat(void){} // does nothing
void printInfo(){
std::cout<< "Rows: " << rows.size() << " | Cols: " << cols.size() << std::endl;
}
void printFull(){
for (int k = 0; k < rows.size(); k++)
{
std::cout << "(" << rows[k] <<"," << cols[k] <<") = " << values[k] << std::endl;
}
}
}SparseMatrix;
typedef struct FlatMatrix {
std::vector<FLOAT_PRECISION> vals;
FlatMatrix& operator +(FLOAT_PRECISION x){
for (auto &&i : vals)
{
i += x;
}
return *this;
}
}FlatMatrix;
typedef std::vector<unsigned int> PerturbationSelectionVector;
// IS THIS NEEDED? THINK! MAYBE BETTER OF WITH SOME OTHER METHOD
/* so idea is only one variable of the decision variable is perturbed at one time so like if you
the diff wrt a single x_0 i.e. f_{x_0(i)} then you would choose i so have a vector = {i, j, k...}
where i, j, k etc are the idices to choose the value to perturb for x_0, x_f, u_0... */
// SHOULD THIS BE CONST? ONCE INITIALIZED THEY SHOULDN'T CHANGE
// THE NEXT ITERATION THEY SHOULD CREATE A NEW INSTANCE IF THAT MAKES SENSE
// typedef struct PerturbationSelectionVectors {
// std::vector<unsigned int> et0;
// std::vector<unsigned int> etf;
// std::vector<unsigned int> ex0;
// std::vector<unsigned int> exf;
// std::vector<unsigned int> eu0;
// std::vector<unsigned int> euf;
// // std::vector<unsigned int> ep; // for parameters
// } PerturbationSelectionVectors;
// typedef struct Gradient
// {
// Index n;
// std::vector<double> grad_f;
// }Gradient;
#endif