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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Copyright (C) 2012, The Science and Technology Facilities Council (STFC)
// Copyright (C) 2009, Jonathan Hogg <jdh41.at.cantab.net>
// Copyright (C) 2004, 2007 International Business Machines and others.
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// Authors: Jonathan Hogg STFC 2012-12-21
// Jonathan Hogg 2009-07-29
// Carl Laird, Andreas Waechter IBM 2004-03-17
#ifndef __IPMA97SOLVERINTERFACE_HPP__
#define __IPMA97SOLVERINTERFACE_HPP__
#include "IpSparseSymLinearSolverInterface.hpp"
#include "IpLibraryLoader.hpp"
#include "IpTypes.h"
extern "C"
{
#ifdef IPOPT_SINGLE
#include "hsl_ma97s.h"
#else
#include "hsl_ma97d.h"
#endif
}
/// @since 3.14.0
#define IPOPT_DECL_MA97_DEFAULT_CONTROL(x) void (x)( \
struct ma97_control* control \
)
/// @since 3.14.0
#define IPOPT_DECL_MA97_ANALYSE(x) void (x)( \
const int check, \
const int n, \
const int ptr[], \
const int row[], \
ipnumber val[], \
void** akeep, \
const struct ma97_control* control,\
struct ma97_info* info, \
int order[] \
)
/// @since 3.14.0
#define IPOPT_DECL_MA97_FACTOR(x) void (x)( \
int matrix_type, \
const int ptr[], \
const int row[], \
const ipnumber val[], \
void** akeep, \
void** fkeep, \
const struct ma97_control* control, \
struct ma97_info* info, \
ipnumber scale[] \
)
/// @since 3.14.0
#define IPOPT_DECL_MA97_FACTOR_SOLVE(x) void (x)( \
int matrix_type, \
const int ptr[], \
const int row[], \
const ipnumber val[], \
int nrhs, \
ipnumber xx[], \
int ldx, \
void** akeep, \
void** fkeep, \
const struct ma97_control* control, \
struct ma97_info* info, \
ipnumber scale[] \
)
/// @since 3.14.0
#define IPOPT_DECL_MA97_SOLVE(x) void (x)( \
const int job, \
const int nrhs, \
ipnumber* xx, \
const int ldx, \
void** akeep, \
void** fkeep, \
const struct ma97_control* control, \
struct ma97_info* info \
)
/// @since 3.14.0
#define IPOPT_DECL_MA97_FINALISE(x) void (x)( \
void** akeep, \
void** fkeep \
)
/// @since 3.14.0
#define IPOPT_DECL_MA97_FREE_AKEEP(x) void (x)( \
void** akeep \
)
namespace Ipopt
{
class Ma97SolverInterface: public SparseSymLinearSolverInterface
{
private:
enum order_opts
{
ORDER_AUTO,
ORDER_BEST,
ORDER_AMD,
ORDER_METIS,
ORDER_MATCHED_AUTO,
ORDER_MATCHED_AMD,
ORDER_MATCHED_METIS
};
enum scale_opts
{
SWITCH_NEVER,
SWITCH_AT_START,
SWITCH_AT_START_REUSE,
SWITCH_ON_DEMAND,
SWITCH_ON_DEMAND_REUSE,
SWITCH_NDELAY,
SWITCH_NDELAY_REUSE,
SWITCH_OD_ND,
SWITCH_OD_ND_REUSE
};
int ndim_; ///< Number of dimensions
Number* val_; ///< Storage for variables
int numneg_; ///< Number of negative pivots in last factorization
int numdelay_; ///< Number of delayed pivots last time we scaled
void* akeep_; ///< Stores pointer to factors (only understood Fortran code!)
void* fkeep_; ///< Stores pointer to factors (only understood Fortran code!)
bool pivtol_changed_; ///< indicates if pivtol has been changed
bool rescale_; ///< Indicates if we should rescale next factorization
Number* scaling_; ///< Store scaling for reuse if doing dynamic scaling
int fctidx_; ///< Current factorization number to dump to
/* Options */
struct ma97_control control_;
Number umax_;
int ordering_;
int scaling_type_;
enum scale_opts switch_[3];
int scaling_val_[3];
int current_level_;
bool dump_;
/**@name MA97 function pointers
* @{
*/
SmartPtr<LibraryLoader> hslloader;
IPOPT_DECL_MA97_DEFAULT_CONTROL(*ma97_default_control);
IPOPT_DECL_MA97_ANALYSE(*ma97_analyse);
IPOPT_DECL_MA97_FACTOR(*ma97_factor);
IPOPT_DECL_MA97_FACTOR_SOLVE(*ma97_factor_solve);
IPOPT_DECL_MA97_SOLVE(*ma97_solve);
IPOPT_DECL_MA97_FINALISE(*ma97_finalise);
IPOPT_DECL_MA97_FREE_AKEEP(*ma97_free_akeep);
///@}
public:
Ma97SolverInterface(
SmartPtr<LibraryLoader> hslloader_ ///< @since 3.14.0
) : val_(NULL),
numdelay_(0),
akeep_(NULL),
fkeep_(NULL),
pivtol_changed_(false),
rescale_(false),
scaling_(NULL),
fctidx_(0),
scaling_type_(0),
dump_(false),
hslloader(hslloader_),
ma97_default_control(NULL),
ma97_analyse(NULL),
ma97_factor(NULL),
ma97_factor_solve(NULL),
ma97_solve(NULL),
ma97_finalise(NULL),
ma97_free_akeep(NULL)
{ }
~Ma97SolverInterface();
static void RegisterOptions(
SmartPtr<RegisteredOptions> roptions
);
/// set MA97 functions to use for every instantiation of this class
/// @since 3.14.0
static void SetFunctions(
IPOPT_DECL_MA97_DEFAULT_CONTROL(*ma97_default_control),
IPOPT_DECL_MA97_ANALYSE(*ma97_analyse),
IPOPT_DECL_MA97_FACTOR(*ma97_factor),
IPOPT_DECL_MA97_FACTOR_SOLVE(*ma97_factor_solve),
IPOPT_DECL_MA97_SOLVE(*ma97_solve),
IPOPT_DECL_MA97_FINALISE(*ma97_finalise),
IPOPT_DECL_MA97_FREE_AKEEP(*ma97_free_akeep)
);
bool InitializeImpl(
const OptionsList& options,
const std::string& prefix
);
/** @name Methods for requesting solution of the linear system. */
///@{
ESymSolverStatus InitializeStructure(
Index dim,
Index nonzeros,
const Index* ia,
const Index* ja
);
Number* GetValuesArrayPtr()
{
return val_;
}
ESymSolverStatus MultiSolve(
bool new_matrix,
const Index* ia,
const Index* ja,
Index nrhs,
Number* rhs_vals,
bool check_NegEVals,
Index numberOfNegEVals
);
Index NumberOfNegEVals() const
{
return numneg_;
}
///@}
//* @name Options of Linear solver */
///@{
bool IncreaseQuality();
bool ProvidesInertia() const
{
return true;
}
EMatrixFormat MatrixFormat() const
{
return CSR_Format_1_Offset;
}
///@}
/** @name Methods related to the detection of linearly dependent
* rows in a matrix */
///@{
bool ProvidesDegeneracyDetection() const
{
return false;
}
ESymSolverStatus DetermineDependentRows(
const Index* /*ia*/,
const Index* /*ja*/,
std::list<Index>& /*c_deps*/
)
{
return SYMSOLVER_FATAL_ERROR;
}
///@}
/** converts a scaling option name to its ma97 option number */
static int ScaleNameToNum(
const std::string& name
);
};
} // namespace Ipopt
#endif