MPSolve  3.2.1
types.h
1 #ifndef MPS_TYPES_H_
2 #define MPS_TYPES_H_
3 
4 /* String type used for some hacks */
5 typedef const char * mps_string;
6 
7 /* Boolean type used in MPSolve */
8 #ifndef __MPS_NOT_DEFINE_BOOL
9 typedef _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. */
20 typedef bool mps_boolean;
21 #endif /* mps_boolean */
22 
23 #define mps_boolean_to_string(x) ((x) == true) ? "true" : "false"
24 
25 /* Debug level */
26 typedef int mps_debug_level;
27 
28 /* Handle systems where isnan and isinf are not available */
29 #include <math.h>
30 #ifndef isnan
31  # define isnan(x) \
32  (sizeof(x) == sizeof(long double) ? isnan_ld (x) \
33  : sizeof(x) == sizeof(double) ? isnan_d (x) \
34  : isnan_f (x))
35 static inline int isnan_f (float x)
36 {
37  return x != x;
38 }
39 static inline int isnan_d (double x)
40 {
41  return x != x;
42 }
43 static inline int isnan_ld (long double x)
44 {
45  return x != x;
46 }
47  #endif
48 
49 #ifndef isinf
50  # define isinf(x) \
51  (sizeof(x) == sizeof(long double) ? isinf_ld (x) \
52  : sizeof(x) == sizeof(double) ? isinf_d (x) \
53  : isinf_f (x))
54 static inline int isinf_f (float x)
55 {
56  return !isnan (x) && isnan (x - x);
57 }
58 static inline int isinf_d (double x)
59 {
60  return !isnan (x) && isnan (x - x);
61 }
62 static inline int isinf_ld (long double x)
63 {
64  return !isnan (x) && isnan (x - x);
65 }
66 #endif
67 
68 #include <mps/mt-types.h>
69 
70 #ifdef __cplusplus
71 
72 /* Forward declarations of the type used in the headers, so they can be
73  * resolved indepently by the header inclusion order. */
74 
75 /* context.h */
76 struct mps_context;
77 
78 /* cluster.h */
79 struct mps_root;
80 struct mps_cluster;
81 struct mps_cluster_item;
82 struct mps_clusterization;
83 
84 /* secular-equation.h */
87 
88 /* monomial-poly.h */
89 struct mps_monomial_poly;
90 
91 /* monomial-matrix-poly.h */
93 
94 /* polynomial.h */
95 struct mps_polynomial;
96 
97 /* input-buffer.h */
98 struct mps_input_buffer;
99 
100 /* approximation.h */
101 struct mps_approximation;
102 
103 /* options.h */
104 struct mps_opt;
105 struct mps_input_option;
108 
109 /* list.h */
110 struct mps_list_element;
111 struct mps_list;
112 
115 
116 /* threading.h */
117 struct mps_thread_job;
118 struct mps_thread_job_queue;
120 struct mps_thread;
121 struct mps_thread_pool;
122 struct mps_thread_pool_queue;
124 
125 /* regeneration-driver.h */
127 
128 #else
129 
130 /* Forward declarations of the type used in the headers, so they can be
131  * resolved indepently by the header inclusion order. */
132 
133 /* context.h */
134 typedef struct mps_context mps_context;
135 
136 /* cluster.h */
137 typedef struct mps_root mps_root;
138 typedef struct mps_cluster mps_cluster;
139 typedef struct mps_cluster_item mps_cluster_item;
141 
142 /* secular-equation.h */
145 
146 /* monomial-poly.h */
147 typedef struct mps_monomial_poly mps_monomial_poly;
148 
149 /* monomial-matrix-poly.h */
151 
152 /* polynomial.h */
153 typedef struct mps_polynomial mps_polynomial;
154 
155 /* input-buffer.h */
156 typedef struct mps_input_buffer mps_input_buffer;
157 
158 /* approximation.h */
159 typedef struct mps_approximation mps_approximation;
160 
161 /* options.h */
162 typedef struct mps_opt mps_opt;
163 typedef struct mps_input_option mps_input_option;
166 
167 /* list.h */
168 typedef struct mps_list_element mps_list_element;
169 typedef struct mps_list mps_list;
170 
171 typedef enum mps_root_status mps_root_status;
172 typedef enum mps_root_inclusion mps_root_inclusion;
173 typedef enum mps_root_attrs mps_root_attrs;
174 
175 typedef enum mps_algorithm mps_algorithm;
176 typedef enum mps_operation mps_operation;
177 typedef enum mps_option_key mps_option_key;
178 typedef enum mps_structure mps_structure;
179 typedef enum mps_representation mps_representation;
180 typedef enum mps_density mps_density;
181 typedef enum mps_output_format mps_output_format;
182 typedef enum mps_output_goal mps_output_goal;
183 typedef enum mps_search_set mps_search_set;
184 typedef enum mps_phase mps_phase;
185 typedef enum mps_starting_strategy mps_starting_strategy;
186 
189 
190 /* threading.h */
191 typedef struct mps_thread_job mps_thread_job;
194 typedef struct mps_thread mps_thread;
195 typedef struct mps_thread_pool mps_thread_pool;
198 
199 /* regeneration-driver.h */
201 
202 #endif
203 
213 enum mps_phase {
214  no_phase, float_phase, dpe_phase, mp_phase
215 };
216 
217 static const mps_string mps_phase_string [] = {
218  "No phase", "Float phase", "DPE phase", "MP phase"
219 };
220 #define MPS_PHASE_TO_STRING(phase) (mps_phase_string[phase])
221 
226 enum mps_operation {
227  MPS_OPERATION_CLUSTER_ANALYSIS,
228  MPS_OPERATION_ABERTH_FP_ITERATIONS,
229  MPS_OPERATION_ABERTH_DPE_ITERATIONS,
230  MPS_OPERATION_ABERTH_MP_ITERATIONS,
231  MPS_OPERATION_REGENERATION,
232  MPS_OPERATION_STARTING_POINTS_FP,
233  MPS_OPERATION_STARTING_POINTS_DPE,
234  MPS_OPERATION_STARTING_POINTS_MP,
235  MPS_OPERATION_SHIFT,
236  MPS_OPERATION_REFINEMENT
237 };
238 static const mps_string mps_operation_string [] = {
239  "Cluster Analysis", "Aberth floating point iterations", "Aberth DPE iterations",
240  "Aberth multiprecision iterations", "Regeneration", "Starting point computation in floating point",
241  "Starting point computatino in DPE", "Starting point computation in multiprecision",
242  "Shift of the polynomial", "Refinement of the approximation"
243 };
244 #define MPS_OPERATION_TO_STRING(operation) (mps_operation_string[operation])
245 
249 enum mps_root_status {
250  MPS_ROOT_STATUS_NEW_CLUSTERED,
251  MPS_ROOT_STATUS_CLUSTERED,
252  MPS_ROOT_STATUS_ISOLATED,
253  MPS_ROOT_STATUS_APPROXIMATED,
254  MPS_ROOT_STATUS_APPROXIMATED_IN_CLUSTER,
255  MPS_ROOT_STATUS_NOT_FLOAT,
256  MPS_ROOT_STATUS_NOT_DPE,
257  MPS_ROOT_STATUS_MULTIPLE
258 };
259 
260 /* Macros to check root status */
261 static const mps_boolean mps_table_of_approximated_roots [] = { false, false, false, true, true, false, false, false };
262 static const mps_boolean mps_table_of_computed_roots [] = { false, false, true, true, true, false, false, false };
263 static const mps_boolean mps_table_of_improvable_roots [] = { false, false, true, true, false, false, false, false };
264 #define MPS_ROOT_STATUS_IS_APPROXIMATED(status) (mps_table_of_approximated_roots[status])
265 #define MPS_ROOT_STATUS_IS_COMPUTED(status) (mps_table_of_computed_roots[status])
266 #define MPS_ROOT_STATUS_IS_IMPROVABLE(status) (mps_table_of_improvable_roots[status])
267 
268 /* Cast of root_status to string */
269 static const mps_string mps_root_status_string[] = {
270  "Clustered (pinned)",
271  "Clustered",
272  "Isolated",
273  "Approximated",
274  "Approximated in a cluster",
275  "Not representable as floating point",
276  "Not representable as DPE",
277  "Multiple root"
278 };
279 #define MPS_ROOT_STATUS_TO_STRING(status) (mps_root_status_string[status])
280 
285 enum mps_root_attrs {
286  MPS_ROOT_ATTRS_NONE,
287  MPS_ROOT_ATTRS_REAL,
288  MPS_ROOT_ATTRS_NOT_REAL,
289  MPS_ROOT_ATTRS_IMAG,
290  MPS_ROOT_ATTRS_NOT_IMAG,
291  MPS_ROOT_ATTRS_NOT_REAL_AND_IMAG
292 };
293 
294 /* Cast of root_attrs to string */
295 static const mps_string mps_root_attrs_string [] = {
296  "None",
297  "Real",
298  "Not real",
299  "Imaginary",
300  "Not imaginary",
301  "Not Real nor imaginary"
302 };
303 #define MPS_ROOT_ATTRS_TO_STRING(attrs) (mps_root_attrs_string[attrs])
304 
309 enum mps_root_inclusion {
310  MPS_ROOT_INCLUSION_UNKNOWN,
311  MPS_ROOT_INCLUSION_IN,
312  MPS_ROOT_INCLUSION_OUT
313 };
314 
315 /* Cast of mps_root_inclusion to string */
316 static const mps_string mps_root_inclusion_string [] = {
317  "Unknown",
318  "In",
319  "Out",
320 };
321 #define MPS_ROOT_INCLUSION_TO_STRING(inclusion) (mps_root_inclusion_string[inclusion])
322 
327 enum mps_algorithm {
331  MPS_ALGORITHM_STANDARD_MPSOLVE,
332 
336  MPS_ALGORITHM_SECULAR_GA
337 };
338 
344 enum mps_option_key {
345  /* Flag for UNDEFINED Options */
346  MPS_FLAG_UNDEFINED,
347 
348  /* Key without values associated */
349  MPS_FLAG_INTEGER,
350  MPS_FLAG_REAL,
351  MPS_FLAG_COMPLEX,
352  MPS_FLAG_RATIONAL,
353  MPS_FLAG_FP,
354 
355  MPS_FLAG_SECULAR,
356  MPS_FLAG_MONOMIAL,
357 
358  MPS_FLAG_DENSE,
359  MPS_FLAG_SPARSE,
360 
361  /* Key with a value */
362  MPS_KEY_DEGREE,
363  MPS_KEY_PRECISION,
364 
365  /* Key introduced in MPSolve 3.1 */
366  MPS_FLAG_CHEBYSHEV
367 };
368 
376 enum mps_structure {
377  MPS_STRUCTURE_REAL_INTEGER,
378  MPS_STRUCTURE_REAL_RATIONAL,
379  MPS_STRUCTURE_REAL_FP,
380  MPS_STRUCTURE_REAL_BIGFLOAT,
381  MPS_STRUCTURE_COMPLEX_INTEGER,
382  MPS_STRUCTURE_COMPLEX_RATIONAL,
383  MPS_STRUCTURE_COMPLEX_FP,
384  MPS_STRUCTURE_COMPLEX_BIGFLOAT,
385  MPS_STRUCTURE_UNKNOWN
386 };
387 
394 enum mps_density {
395  MPS_DENSITY_DENSE,
396  MPS_DENSITY_SPARSE,
397  MPS_DENSITY_USER,
398 };
399 
403 enum mps_output_format {
404  MPS_OUTPUT_FORMAT_COMPACT,
405  MPS_OUTPUT_FORMAT_GNUPLOT,
406  MPS_OUTPUT_FORMAT_GNUPLOT_FULL,
407  MPS_OUTPUT_FORMAT_BARE,
408  MPS_OUTPUT_FORMAT_FULL,
409  MPS_OUTPUT_FORMAT_VERBOSE
410 };
411 
415 enum mps_output_goal {
416  MPS_OUTPUT_GOAL_ISOLATE,
417  MPS_OUTPUT_GOAL_APPROXIMATE,
418  MPS_OUTPUT_GOAL_COUNT
419 };
420 
424 enum mps_search_set {
428  MPS_SEARCH_SET_COMPLEX_PLANE,
429 
433  MPS_SEARCH_SET_POSITIVE_REAL_PART,
434 
438  MPS_SEARCH_SET_NEGATIVE_REAL_PART,
439 
443  MPS_SEARCH_SET_POSITIVE_IMAG_PART,
444 
448  MPS_SEARCH_SET_NEGATIVE_IMAG_PART,
449 
454  MPS_SEARCH_SET_UNITARY_DISC,
455 
460  MPS_SEARCH_SET_UNITARY_DISC_COMPL,
461 
465  MPS_SEARCH_SET_REAL,
466 
470  MPS_SEARCH_SET_IMAG,
471 
475  MPS_SEARCH_SET_CUSTOM
476 };
477 
481 enum mps_representation {
482  MPS_REPRESENTATION_SECULAR,
483  MPS_REPRESENTATION_MONOMIAL,
484  MPS_REPRESENTATION_CHEBYSHEV
485 };
486 
490 enum mps_starting_strategy {
491  MPS_STARTING_STRATEGY_DEFAULT,
492  MPS_STARTING_STRATEGY_RECURSIVE,
493  MPS_STARTING_STRATEGY_FILE
494 };
495 
496 #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:55
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:174
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