MPSolve 3.2.2
Loading...
Searching...
No Matches
types.h
1#ifndef MPS_TYPES_H_
2#define MPS_TYPES_H_
3
4/* String type used for some hacks */
5typedef const char * mps_string;
6
7/* Boolean type used in MPSolve */
8#ifndef __MPS_NOT_DEFINE_BOOL
9typedef _Bool mps_boolean;
10#ifndef false
11#define false 0
12#endif
13#ifndef true
14#define true 1
15#endif
16#else
17/* Small workaround to make matlab module work; there is,
18 * int matlab headers, already a false keyword defined, so
19 * reusing it here make compilation fail. */
20typedef bool mps_boolean;
21#endif /* mps_boolean */
22
23#define mps_boolean_to_string(x) ((x) == true) ? "true" : "false"
24
25/* Debug level */
26typedef int mps_debug_level;
27
28/* Handle systems where isnan and isinf are not available */
29#ifdef __cplusplus
30 #include <cmath>
31#else
32 #include <math.h>
33#endif
34#ifndef isnan
35 # define isnan(x) \
36 (sizeof(x) == sizeof(long double) ? isnan_ld (x) \
37 : sizeof(x) == sizeof(double) ? isnan_d (x) \
38 : isnan_f (x))
39static inline int isnan_f (float x)
40{
41 return x != x;
42}
43static inline int isnan_d (double x)
44{
45 return x != x;
46}
47static inline int isnan_ld (long double x)
48{
49 return x != x;
50}
51 #endif
52
53#ifndef isinf
54 # define isinf(x) \
55 (sizeof(x) == sizeof(long double) ? isinf_ld (x) \
56 : sizeof(x) == sizeof(double) ? isinf_d (x) \
57 : isinf_f (x))
58static inline int isinf_f (float x)
59{
60 return !isnan (x) && isnan (x - x);
61}
62static inline int isinf_d (double x)
63{
64 return !isnan (x) && isnan (x - x);
65}
66static inline int isinf_ld (long double x)
67{
68 return !isnan (x) && isnan (x - x);
69}
70#endif
71
72#include <mps/mt-types.h>
73
74#ifdef __cplusplus
75
76/* Forward declarations of the type used in the headers, so they can be
77 * resolved indepently by the header inclusion order. */
78
79/* context.h */
80struct mps_context;
81
82/* cluster.h */
83struct mps_root;
84struct mps_cluster;
85struct mps_cluster_item;
87
88/* secular-equation.h */
91
92/* monomial-poly.h */
94
95/* monomial-matrix-poly.h */
97
98/* polynomial.h */
99struct mps_polynomial;
100
101/* input-buffer.h */
102struct mps_input_buffer;
103
104/* approximation.h */
105struct mps_approximation;
106
107/* options.h */
108struct mps_opt;
109struct mps_input_option;
112
113/* list.h */
114struct mps_list_element;
115struct mps_list;
116
119
120/* threading.h */
121struct mps_thread_job;
124struct mps_thread;
125struct mps_thread_pool;
128
129/* regeneration-driver.h */
131
132#else
133
134/* Forward declarations of the type used in the headers, so they can be
135 * resolved indepently by the header inclusion order. */
136
137/* context.h */
138typedef struct mps_context mps_context;
139
140/* cluster.h */
141typedef struct mps_root mps_root;
142typedef struct mps_cluster mps_cluster;
145
146/* secular-equation.h */
149
150/* monomial-poly.h */
152
153/* monomial-matrix-poly.h */
155
156/* polynomial.h */
157typedef struct mps_polynomial mps_polynomial;
158
159/* input-buffer.h */
161
162/* approximation.h */
164
165/* options.h */
166typedef struct mps_opt mps_opt;
170
171/* list.h */
173typedef struct mps_list mps_list;
174
175typedef enum mps_root_status mps_root_status;
176typedef enum mps_root_inclusion mps_root_inclusion;
177typedef enum mps_root_attrs mps_root_attrs;
178
179typedef enum mps_algorithm mps_algorithm;
180typedef enum mps_operation mps_operation;
181typedef enum mps_option_key mps_option_key;
182typedef enum mps_structure mps_structure;
183typedef enum mps_representation mps_representation;
184typedef enum mps_density mps_density;
185typedef enum mps_output_format mps_output_format;
186typedef enum mps_output_goal mps_output_goal;
187typedef enum mps_search_set mps_search_set;
188typedef enum mps_phase mps_phase;
189typedef enum mps_starting_strategy mps_starting_strategy;
190
193
194/* threading.h */
195typedef struct mps_thread_job mps_thread_job;
198typedef struct mps_thread mps_thread;
199typedef struct mps_thread_pool mps_thread_pool;
202
203/* regeneration-driver.h */
205
206#endif
207
217enum mps_phase {
218 no_phase, float_phase, dpe_phase, mp_phase
219};
220
221static const mps_string mps_phase_string [] = {
222 "No phase", "Float phase", "DPE phase", "MP phase"
223};
224#define MPS_PHASE_TO_STRING(phase) (mps_phase_string[phase])
225
230enum mps_operation {
231 MPS_OPERATION_CLUSTER_ANALYSIS,
232 MPS_OPERATION_ABERTH_FP_ITERATIONS,
233 MPS_OPERATION_ABERTH_DPE_ITERATIONS,
234 MPS_OPERATION_ABERTH_MP_ITERATIONS,
235 MPS_OPERATION_REGENERATION,
236 MPS_OPERATION_STARTING_POINTS_FP,
237 MPS_OPERATION_STARTING_POINTS_DPE,
238 MPS_OPERATION_STARTING_POINTS_MP,
239 MPS_OPERATION_SHIFT,
240 MPS_OPERATION_REFINEMENT
241};
242static const mps_string mps_operation_string [] = {
243 "Cluster Analysis", "Aberth floating point iterations", "Aberth DPE iterations",
244 "Aberth multiprecision iterations", "Regeneration", "Starting point computation in floating point",
245 "Starting point computatino in DPE", "Starting point computation in multiprecision",
246 "Shift of the polynomial", "Refinement of the approximation"
247};
248#define MPS_OPERATION_TO_STRING(operation) (mps_operation_string[operation])
249
253enum mps_root_status {
254 MPS_ROOT_STATUS_NEW_CLUSTERED,
255 MPS_ROOT_STATUS_CLUSTERED,
256 MPS_ROOT_STATUS_ISOLATED,
257 MPS_ROOT_STATUS_APPROXIMATED,
258 MPS_ROOT_STATUS_APPROXIMATED_IN_CLUSTER,
259 MPS_ROOT_STATUS_NOT_FLOAT,
260 MPS_ROOT_STATUS_NOT_DPE,
261 MPS_ROOT_STATUS_MULTIPLE
262};
263
264/* Macros to check root status */
265static const mps_boolean mps_table_of_approximated_roots [] = { false, false, false, true, true, false, false, false };
266static const mps_boolean mps_table_of_computed_roots [] = { false, false, true, true, true, false, false, false };
267static const mps_boolean mps_table_of_improvable_roots [] = { false, false, true, true, false, false, false, false };
268#define MPS_ROOT_STATUS_IS_APPROXIMATED(status) (mps_table_of_approximated_roots[status])
269#define MPS_ROOT_STATUS_IS_COMPUTED(status) (mps_table_of_computed_roots[status])
270#define MPS_ROOT_STATUS_IS_IMPROVABLE(status) (mps_table_of_improvable_roots[status])
271
272/* Cast of root_status to string */
273static const mps_string mps_root_status_string[] = {
274 "Clustered (pinned)",
275 "Clustered",
276 "Isolated",
277 "Approximated",
278 "Approximated in a cluster",
279 "Not representable as floating point",
280 "Not representable as DPE",
281 "Multiple root"
282};
283#define MPS_ROOT_STATUS_TO_STRING(status) (mps_root_status_string[status])
284
289enum mps_root_attrs {
290 MPS_ROOT_ATTRS_NONE,
291 MPS_ROOT_ATTRS_REAL,
292 MPS_ROOT_ATTRS_NOT_REAL,
293 MPS_ROOT_ATTRS_IMAG,
294 MPS_ROOT_ATTRS_NOT_IMAG,
295 MPS_ROOT_ATTRS_NOT_REAL_AND_IMAG
296};
297
298/* Cast of root_attrs to string */
299static const mps_string mps_root_attrs_string [] = {
300 "None",
301 "Real",
302 "Not real",
303 "Imaginary",
304 "Not imaginary",
305 "Not Real nor imaginary"
306};
307#define MPS_ROOT_ATTRS_TO_STRING(attrs) (mps_root_attrs_string[attrs])
308
313enum mps_root_inclusion {
314 MPS_ROOT_INCLUSION_UNKNOWN,
315 MPS_ROOT_INCLUSION_IN,
316 MPS_ROOT_INCLUSION_OUT
317};
318
319/* Cast of mps_root_inclusion to string */
320static const mps_string mps_root_inclusion_string [] = {
321 "Unknown",
322 "In",
323 "Out",
324};
325#define MPS_ROOT_INCLUSION_TO_STRING(inclusion) (mps_root_inclusion_string[inclusion])
326
331enum mps_algorithm {
335 MPS_ALGORITHM_STANDARD_MPSOLVE,
336
340 MPS_ALGORITHM_SECULAR_GA
341};
342
348enum mps_option_key {
349 /* Flag for UNDEFINED Options */
350 MPS_FLAG_UNDEFINED,
351
352 /* Key without values associated */
353 MPS_FLAG_INTEGER,
354 MPS_FLAG_REAL,
355 MPS_FLAG_COMPLEX,
356 MPS_FLAG_RATIONAL,
357 MPS_FLAG_FP,
358
359 MPS_FLAG_SECULAR,
360 MPS_FLAG_MONOMIAL,
361
362 MPS_FLAG_DENSE,
363 MPS_FLAG_SPARSE,
364
365 /* Key with a value */
366 MPS_KEY_DEGREE,
367 MPS_KEY_PRECISION,
368
369 /* Key introduced in MPSolve 3.1 */
370 MPS_FLAG_CHEBYSHEV
371};
372
380enum mps_structure {
381 MPS_STRUCTURE_REAL_INTEGER,
382 MPS_STRUCTURE_REAL_RATIONAL,
383 MPS_STRUCTURE_REAL_FP,
384 MPS_STRUCTURE_REAL_BIGFLOAT,
385 MPS_STRUCTURE_COMPLEX_INTEGER,
386 MPS_STRUCTURE_COMPLEX_RATIONAL,
387 MPS_STRUCTURE_COMPLEX_FP,
388 MPS_STRUCTURE_COMPLEX_BIGFLOAT,
389 MPS_STRUCTURE_UNKNOWN
390};
391
398enum mps_density {
399 MPS_DENSITY_DENSE,
400 MPS_DENSITY_SPARSE,
401 MPS_DENSITY_USER,
402};
403
407enum mps_output_format {
408 MPS_OUTPUT_FORMAT_COMPACT,
409 MPS_OUTPUT_FORMAT_GNUPLOT,
410 MPS_OUTPUT_FORMAT_GNUPLOT_FULL,
411 MPS_OUTPUT_FORMAT_BARE,
412 MPS_OUTPUT_FORMAT_FULL,
413 MPS_OUTPUT_FORMAT_VERBOSE
414};
415
419enum mps_output_goal {
420 MPS_OUTPUT_GOAL_ISOLATE,
421 MPS_OUTPUT_GOAL_APPROXIMATE,
422 MPS_OUTPUT_GOAL_COUNT
423};
424
428enum mps_search_set {
432 MPS_SEARCH_SET_COMPLEX_PLANE,
433
437 MPS_SEARCH_SET_POSITIVE_REAL_PART,
438
442 MPS_SEARCH_SET_NEGATIVE_REAL_PART,
443
447 MPS_SEARCH_SET_POSITIVE_IMAG_PART,
448
452 MPS_SEARCH_SET_NEGATIVE_IMAG_PART,
453
458 MPS_SEARCH_SET_UNITARY_DISC,
459
464 MPS_SEARCH_SET_UNITARY_DISC_COMPL,
465
469 MPS_SEARCH_SET_REAL,
470
474 MPS_SEARCH_SET_IMAG,
475
479 MPS_SEARCH_SET_CUSTOM
480};
481
485enum mps_representation {
486 MPS_REPRESENTATION_SECULAR,
487 MPS_REPRESENTATION_MONOMIAL,
488 MPS_REPRESENTATION_CHEBYSHEV
489};
490
494enum mps_starting_strategy {
495 MPS_STARTING_STRATEGY_DEFAULT,
496 MPS_STARTING_STRATEGY_RECURSIVE,
497 MPS_STARTING_STRATEGY_FILE
498};
499
500#endif /* endif MPS_TYPES_H_ */
Implementation of some thread-safe types that can be easily used with the macro MPS_LOCK() and MPS_UN...
Definition approximation.h:24
Cluster held in a mps_clusterization.
Definition cluster.h:72
A cluster of mps_roots.
Definition cluster.h:51
A list of mps_cluster.
Definition cluster.h:100
Configuration for a command line parser.
Definition options.h:65
This struct holds a configuration for a command line option. This is a step towards a more flexible i...
Definition options.h:28
this struct holds the state of the mps computation
Definition context.h:60
Buffer used to parse input files in MPSolve. It can read a stream line by line.
Definition input-buffer.h:33
Configuration for an input stream; this struct contains the information on how the input stream shoul...
Definition options.h:151
This struct holds a key and the value associated with it. It's used for options that require a value ...
Definition options.h:110
Definition list.h:25
Definition list.h:50
This is the struct that holds all the data of the matrix polynomial.
Definition monomial-matrix-poly.h:39
Data regarding a polynomial represented in the monomial base.
Definition monomial-poly.h:44
Struct holding the options passed on the command line.
Definition options.h:97
Configuration for the output.
Definition options.h:169
Struct that represents an abstract polynomial. All the other real polynomial implementations (such as...
Definition polynomial.h:111
This type represent an abstract implementation of a driver for the regeneration step of the main algo...
Definition regeneration-driver.h:31
This struct represent a root inside of a mps_cluster.
Definition cluster.h:30
Secular equation data.
Definition secular-equation.h:63
This is a struct that represent an iteration on a root. It contains information that could be useful ...
Definition secular-equation.h:189
Struct holding a job queue.
Definition threading.h:76
A new job for mps_thread_fsolve(), mps_thread_dsolve() or mps_thread_msolve().
Definition threading.h:44
An item that can be inserted and/or extracted from a mps_thread_pool_queue.
Definition threading.h:265
A queue of work items that thread can consume.
Definition threading.h:285
A thread pool that contains a set of mps_thread and allow to manage them as a set of worker.
Definition threading.h:303
Data packed to be passed to a new thread that will perform floating point, dpe or multiprecision iter...
Definition threading.h:116
A thread that is part of a thread pool.
Definition threading.h:198