-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsdpa_struct.h
201 lines (152 loc) · 5.96 KB
/
sdpa_struct.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
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
196
197
198
199
200
201
/* -------------------------------------------------------------
This file is a component of SDPA
Copyright (C) 2004 SDPA Project
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------- */
// printing presicion of such as vector
#define P_FORMAT "%+15.9Fe"
#define NO_P_FORMAT "NOPRINT"
#ifndef __sdpa_struct_h__
#define __sdpa_struct_h__
#include <sdpa_include.h>
namespace sdpa {
class Vector {
public:
int nDim;
mpf_class *ele;
Vector();
Vector(int nDim, mpf_class value = 0.0);
~Vector();
void initialize(int nDim, mpf_class value = 0.0);
void initialize(mpf_class value);
void terminate();
void setZero();
void display(FILE *fpout = stdout, const char *printFormat = P_FORMAT);
void display(FILE *fpout, mpf_class scalar, const char *printFormat = P_FORMAT);
bool copyFrom(Vector &other);
};
class BlockVector {
public:
int nBlock;
int *blockStruct;
Vector *ele;
BlockVector();
BlockVector(int nBlock, int *blockStruct, mpf_class value = 0.0);
~BlockVector();
void initialize(int nBlock, int *blockStruct, mpf_class value = 0.0);
void initialize(mpf_class value);
void terminate();
void setZero();
void display(FILE *fpout = stdout, const char *printFormat = P_FORMAT);
bool copyFrom(BlockVector &other);
};
class SparseMatrix {
public:
int nRow, nCol;
enum Type { SPARSE, DENSE };
Type type;
int NonZeroNumber;
// for memory
int NonZeroCount;
// currentry stored
int NonZeroEffect;
// use for calculation of F1,F2,F3
// for Dense
mpf_class *de_ele;
// for Sparse
int *row_index;
int *column_index;
mpf_class *sp_ele;
SparseMatrix();
SparseMatrix(int nRow, int nCol, Type type, int NonZeroNumber);
~SparseMatrix();
void initialize(int nRow, int nCol, Type type, int NonZeroNumber);
void terminate();
void display(FILE *fpout = stdout, const char *printFormat = P_FORMAT);
bool copyFrom(SparseMatrix &other);
void changeToDense(bool forceChange = false);
void setZero();
void setIdentity(mpf_class scalar = 1.0);
bool sortSparseIndex(int &i, int &j);
};
class DenseMatrix {
public:
int nRow, nCol;
enum Type { DENSE, COMPLETION };
Type type;
mpf_class *de_ele;
DenseMatrix();
DenseMatrix(int nRow, int nCol, Type type);
~DenseMatrix();
void initialize(int nRow, int nCol, Type type);
void terminate();
void display(FILE *fpout = stdout, const char *printFormat = P_FORMAT);
bool copyFrom(DenseMatrix &other);
bool copyFrom(SparseMatrix &other);
void setZero();
void setIdentity(mpf_class scalar = 1.0);
};
class SparseLinearSpace {
public:
int SDP_sp_nBlock;
int SOCP_sp_nBlock;
int LP_sp_nBlock;
int *SDP_sp_index;
int *SOCP_sp_index;
int *LP_sp_index;
SparseMatrix *SDP_sp_block;
SparseMatrix *SOCP_sp_block;
mpf_class *LP_sp_block;
SparseLinearSpace();
SparseLinearSpace(int SDP_nBlock, int *SDP_blockStruct, int *SDP_NonZeroNumber, int SOCP_nBlock, int *SOCP_blockStruct, int *SOCP_NonZeroNumber, int LP_nBlock, bool *LP_NonZeroNumber);
SparseLinearSpace(int SDP_sp_nBlock, int *SDP_sp_index, int *SDP_sp_blockStruct, int *SDP_sp_NonZeroNumber, int SOCP_sp_nBlock, int *SOCP_sp_index, int *SOCP_sp_blockStruct, int *SOCP_sp_NonZeroNumber, int LP_sp_nBlock, int *LP_sp_index);
~SparseLinearSpace();
// dense form of block index
void initialize(int SDP_nBlock, int *SDP_blockStruct, int *SDP_NonZeroNumber, int SOCP_nBlock, int *SOCP_blockStruct, int *SOCP_NonZeroNumber, int LP_nBlock, bool *LP_NonZeroNumber);
// sparse form of block index 2008/02/27 kazuhide nakata
void initialize(int SDP_sp_nBlock, int *SDP_sp_index, int *SDP_sp_blockStruct, int *SDP_sp_NonZeroNumber, int SOCP_sp_nBlock, int *SOCP_sp_index, int *SOCP_sp_blockStruct, int *SOCP_sp_NonZeroNumber, int LP_sp_nBlock, int *LP_sp_index);
void terminate();
void changeToDense(bool forceChange = false);
void display(FILE *fpout = stdout, const char *printFormat = P_FORMAT);
bool copyFrom(SparseLinearSpace &other);
void setElement_SDP(int block, int nCol, int nRow, mpf_class ele);
void setElement_SOCP(int block, int nCol, int nRow, mpf_class ele);
void setElement_LP(int block, mpf_class ele);
void setZero();
void setIdentity(mpf_class scalar = 1.0);
// no check
bool sortSparseIndex(int &l, int &i, int &j);
};
class DenseLinearSpace {
public:
int SDP_nBlock;
int SOCP_nBlock;
int LP_nBlock;
DenseMatrix *SDP_block;
DenseMatrix *SOCP_block;
mpf_class *LP_block;
DenseLinearSpace();
DenseLinearSpace(int SDP_nBlock, int *SDP_blockStruct, int SOCP_nBlock, int *SOCP_blockStruct, int LP_nBlock);
~DenseLinearSpace();
void initialize(int SDP_nBlock, int *SDP_blockStruct, int SOCP_nBlock, int *SOCP_blockStruct, int LP_nBlock);
void terminate();
void display(FILE *fpout = stdout, const char *printFormat = P_FORMAT);
bool copyFrom(DenseLinearSpace &other);
void setElement_SDP(int block, int nCol, int nRow, mpf_class ele);
void setElement_SOCP(int block, int nCol, int nRow, mpf_class ele);
void setElement_LP(int block, mpf_class ele);
void setZero();
void setIdentity(mpf_class scalar = 1.0);
};
} // namespace sdpa
#endif // __sdpa_struct_h__