-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathSupportedConeT.hpp
More file actions
195 lines (176 loc) · 4.42 KB
/
SupportedConeT.hpp
File metadata and controls
195 lines (176 loc) · 4.42 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#pragma once
#include <cstdint>
#include <stdexcept>
#include <type_traits>
namespace clarabel
{
// Provides the layout for SupportedConeT objects in Rust
// Base type of all cones
template<typename T = double>
struct SupportedConeT
{
static_assert(std::is_same<T, float>::value || std::is_same<T, double>::value, "T must be float or double");
public:
// Tag for the type of the cone
enum class Tag
{
ZeroConeT,
NonnegativeConeT,
SecondOrderConeT,
ExponentialConeT,
PowerConeT,
GenPowerConeT,
#ifdef FEATURE_SDP
PSDTriangleConeT,
#endif
};
Tag tag;
protected:
struct ZeroConeT_Body
{
uintptr_t _0;
};
struct NonnegativeConeT_Body
{
uintptr_t _0;
};
struct SecondOrderConeT_Body
{
uintptr_t _0;
};
struct ExponentialConeT_Body
{
};
struct PowerConeT_Body
{
T _0;
};
struct GenPowerConeT_Body
{
const T* _0;
uintptr_t _1;
uintptr_t _2;
};
#ifdef FEATURE_SDP
struct PSDTriangleConeT_Body
{
uintptr_t _0;
};
#endif
// Data
union
{
ZeroConeT_Body zero_cone_t;
NonnegativeConeT_Body nonnegative_cone_t;
SecondOrderConeT_Body second_order_cone_t;
ExponentialConeT_Body exponential_cone_t;
PowerConeT_Body power_cone_t;
GenPowerConeT_Body genpower_cone_t;
#ifdef FEATURE_SDP
PSDTriangleConeT_Body psd_triangle_cone_t;
#endif
};
public:
unsigned int nvars() const
{
switch (this->tag)
{
case Tag::ZeroConeT:
return this->zero_cone_t._0;
case Tag::NonnegativeConeT:
return this->nonnegative_cone_t._0;
case Tag::SecondOrderConeT:
return this->second_order_cone_t._0;
case Tag::ExponentialConeT:
return 3;
case Tag::PowerConeT:
return 3;
case Tag::GenPowerConeT:
return this->genpower_cone_t._1 + this->genpower_cone_t._2;
#ifdef FEATURE_SDP
case Tag::PSDTriangleConeT: {
unsigned int k = this->psd_triangle_cone_t._0;
return (k * (k + 1)) >> 1;
}
#endif
default:
throw std::invalid_argument("Invalid cone type");
}
}
};
template<typename T = double>
struct ZeroConeT : public SupportedConeT<T>
{
public:
ZeroConeT(uintptr_t dimension)
{
this->tag = SupportedConeT<T>::Tag::ZeroConeT;
this->zero_cone_t = { dimension };
}
uintptr_t dimension() const { return this->nonnegative_cone_t._0; }
};
template<typename T = double>
struct NonnegativeConeT : public SupportedConeT<T>
{
public:
NonnegativeConeT(uintptr_t dimension)
{
this->tag = SupportedConeT<T>::Tag::NonnegativeConeT;
this->nonnegative_cone_t = { dimension };
}
uintptr_t dimension() const { return this->zero_cone_t._0; }
};
template<typename T = double>
struct SecondOrderConeT : public SupportedConeT<T>
{
public:
SecondOrderConeT(uintptr_t dimension)
{
this->tag = SupportedConeT<T>::Tag::SecondOrderConeT;
this->second_order_cone_t = { dimension };
}
T dimension() const { return this->second_order_cone_t._0; }
};
template<typename T = double>
struct ExponentialConeT : public SupportedConeT<T>
{
public:
ExponentialConeT() { this->tag = SupportedConeT<T>::Tag::ExponentialConeT; }
};
template<typename T = double>
struct PowerConeT : public SupportedConeT<T>
{
public:
PowerConeT(T power)
{
this->tag = SupportedConeT<T>::Tag::PowerConeT;
this->power_cone_t = { power };
}
T power() const { return this->power_cone_t._0; }
};
template<typename T = double>
struct GenPowerConeT : public SupportedConeT<T>
{
public:
GenPowerConeT(const Eigen::Ref<Eigen::VectorX<T>> &alpha, uintptr_t dim2)
{
this->tag = SupportedConeT<T>::Tag::GenPowerConeT;
const T* alpha_data = alpha.data();
uintptr_t dim1 = alpha.size();
this->genpower_cone_t = {alpha_data,dim1,dim2 };
}
};
#ifdef FEATURE_SDP
template<typename T = double>
struct PSDTriangleConeT : public SupportedConeT<T>
{
public:
PSDTriangleConeT(uintptr_t dimension)
{
this->tag = SupportedConeT<T>::Tag::PSDTriangleConeT;
this->psd_triangle_cone_t = { dimension };
}
T dimension() const { return this->psd_triangle_cone_t._0; }
};
#endif
} // namespace clarabel