Program listing for file numerics/src/tools/NMS.h#
Return to documentation for this file
1#ifndef NMS_H
2#define NMS_H
3
4
5
6#include "SiconosConfig.h"
7#include "Newton_methods.h"
8#include "NumericsFwd.h"
9#include "line_search.h"
10
11
12#include "siconos_debug.h"
13
14
15
16typedef struct
17{
18 int* final_basis;
19 int* basis_change;
20 int circular_indx;
21} path_record;
22
23
24
25typedef struct
26{
27 unsigned size;
28 int watchdog_search_type;
29 int projected_gradient_search_type;
30 double delta;
31 double delta_var;
32 double sigma;
33 double alpha_min_watchdog;
34 double alpha_min_pgrad;
35 int n;
36 int n_max;
37 double ref_merit;
38 double merit_incr;
39 void* ref_merit_data;
40 double* checkpoint;
41 double delta_checkpoint;
42 double* bestpoint;
43 double merit_bestpoint;
44 double delta_bestpoint;
45 double* workspace;
46 NumericsMatrix* H;
47 void* set;
48 path_record* path_data;
49 search_data* ls_data;
50} NMS_data;
51
52#if defined(__cplusplus) && !defined(BUILD_AS_CPP)
53extern "C"
54{
55#endif
56
57
58 int NMS(NMS_data* data_NMS, void* data, functions_LSA* functions, double* z, double* z_N, int force_watchdog_step, int force_d_step_merit_check, double check_ratio);
59
60
61 NMS_data* create_NMS_data(unsigned size, int matrix_type, int* iparam, double* dparam);
62
63
64 void free_NMS_data(NMS_data* data);
65
66
67 static inline double* NMS_get_F(double* workspace, int n)
68 {
69 return &workspace[0];
70 }
71
72
73 static inline double* NMS_get_F_merit(double* workspace, int n)
74 {
75 return &workspace[n];
76 }
77
78
79 static inline double* NMS_get_JacTheta_F_merit(double* workspace, int n)
80 {
81 return &workspace[2*n];
82 }
83
84
85 static inline double* NMS_get_dir(double* workspace, int n)
86 {
87 return &workspace[3*n];
88 }
89
90
91 static inline double* NMS_get_generic_workV(double* workspace, int n)
92 {
93 return &workspace[4*n];
94 }
95
96
97 static inline double* NMS_checkpoint_0(NMS_data* data_NMS, unsigned n)
98 {
99 return &data_NMS->checkpoint[n];
100 }
101
102
103 static inline double* NMS_checkpoint_T(NMS_data* data_NMS, unsigned n)
104 {
105 return data_NMS->checkpoint;
106 }
107
108
109 static inline double* NMS_bestpoint(NMS_data* data_NMS, unsigned n)
110 {
111 return data_NMS->bestpoint;
112 }
113
114
115 static inline int check_nmd_criterion(double theta_iter, double ref_merit, double sigma, double dotprod)
116 {
117 if (dotprod < 0.0)
118 {
119
120 if (theta_iter <= ref_merit - sigma*dotprod)
121 {
122 DEBUG_PRINTF("NMS nmd accepted theta_iter = %2.2e < tol = %2.2e\n", theta_iter, ref_merit - sigma*dotprod);
123 return 0;
124 }
125
126 DEBUG_PRINTF("NMS nmd rejected theta_iter = %2.2e; tol = %2.2e; diff = %2.2e\n", theta_iter, ref_merit - sigma*dotprod, theta_iter - (ref_merit - sigma*dotprod));
127 }
128 else
129 {
130 if (theta_iter <= (1.0 - sigma)*ref_merit)
131 {
132 DEBUG_PRINTF("NMS nmd accepted theta_iter = %2.2e < tol = %2.2e\n", theta_iter, (1.0 - sigma)*ref_merit);
133 return 0;
134 }
135
136 DEBUG_PRINTF("NMS nmd rejected theta_iter = %2.2e; tol = %2.2e; diff = %2.2e\n", theta_iter, (1.0 - sigma)*ref_merit, theta_iter - (1.0 - sigma)*ref_merit);
137 }
138 return 1;
139 }
140
141#if defined(__cplusplus) && !defined(BUILD_AS_CPP)
142}
143#endif
144
145#endif