1 /* Siconos is a program dedicated to modeling, simulation and control
2 * of non smooth dynamical systems.
3 *
4 * Copyright 2021 INRIA.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 /*
20 |A C| |u| |a| |0|
21 | |*| |+| |=| |
22 |D B| |v| |b| |w|
23 0<z*v>0
24 dim(u)=mm
25 dim(v)=nn
26
27 **************************************************************************/
28 #include "mlcp_direct_enum.h"
29 #ifndef __cplusplus
30 #include <stdbool.h> // for false
31 #endif
32 #include <stdio.h> // for printf
33 #include "MLCP_Solvers.h" // for mlcp_direct, mlcp_enum
34 #include "MixedLinearComplementarityProblem.h" // for MixedLinearComplement...
35 #include "SolverOptions.h" // for SolverOptions
36 #include "mlcp_cst.h" // for SICONOS_DPARAM_MLCP_S...
37 #include "mlcp_direct.h" // for mlcp_direct_addConfig...
38 #include "numerics_verbose.h" // for numerics_error, verbose
39
40
41 /* #define DEBUG_MESSAGES */
42 #include "siconos_debug.h"
43
44 static int sN;
45 static int sM;
46
47 static int * siWorkEnum = 0;
48 static int * siWorkDirect = 0;
49 static double * sdWorkEnum = 0;
50 static double * sdWorkDirect = 0;
51
mlcp_direct_enum_init(MixedLinearComplementarityProblem * problem,SolverOptions * options)52 void mlcp_direct_enum_init(MixedLinearComplementarityProblem* problem, SolverOptions* options)
53 {
54 sN = problem->n;
55 sM = problem->m;
56 int iOffset = mlcp_direct_getNbIWork(problem, options);
57 int dOffset = mlcp_direct_getNbDWork(problem, options);
58 siWorkEnum = options->iWork + iOffset;
59 siWorkDirect = options->iWork;
60 sdWorkEnum = options->dWork + dOffset;
61 sdWorkDirect = options->dWork;
62 mlcp_direct_init(problem, options);
63
64 }
mlcp_direct_enum_reset()65 void mlcp_direct_enum_reset()
66 {
67 mlcp_direct_reset();
68 siWorkEnum = 0;
69 siWorkDirect = 0;
70 sdWorkEnum = 0;
71 sdWorkDirect = 0;
72 }
73
mlcp_direct_enum(MixedLinearComplementarityProblem * problem,double * z,double * w,int * info,SolverOptions * options)74 void mlcp_direct_enum(MixedLinearComplementarityProblem* problem, double *z, double *w, int *info, SolverOptions* options)
75 {
76 DEBUG_BEGIN("mlcp_direct_enum(...)\n");
77 DEBUG_PRINTF("options->iWork = %p\n", options->iWork);
78 if(!siWorkEnum)
79 {
80 *info = 1;
81 numerics_printf_verbose(0,"MLCP_DIRECT_ENUM error, call a non initialised method!!!!!!!!!!!!!!!!!!!!!\n");
82 return;
83 }
84 /*First, try direct solver*/
85 options->dWork = sdWorkDirect;
86 options->iWork = siWorkDirect;
87 mlcp_direct(problem, z, w, info, options);
88 if(*info)
89 {
90 DEBUG_PRINT("Solver direct failed, so run the enum solver\n");
91 options->dWork = sdWorkEnum;
92 options->iWork = siWorkEnum;
93 mlcp_enum(problem, z, w, info, options);
94 if(!(*info))
95 {
96 mlcp_direct_addConfigFromWSolution(problem, w + sN);
97 }
98 /* Come back to previous memory adress to ensure correct freeing */
99 options->dWork = sdWorkDirect;
100 options->iWork = siWorkDirect;
101 }
102 DEBUG_PRINTF("options->iWork = %p\n", options->iWork);
103 DEBUG_END("mlcp_direct_enum(...)\n");
104 }
105
mlcp_direct_enum_set_default(SolverOptions * options)106 void mlcp_direct_enum_set_default(SolverOptions* options)
107 {
108 options->dparam[SICONOS_IPARAM_MLCP_ENUM_USE_DGELS] = 0;
109 options->dparam[SICONOS_DPARAM_MLCP_SIGN_TOL_POS] = 1e-12;
110 options->dparam[SICONOS_DPARAM_MLCP_SIGN_TOL_NEG] = 1e-12;
111 options->iparam[SICONOS_IPARAM_MLCP_NUMBER_OF_CONFIGURATIONS] = 3;
112 options->iparam[SICONOS_IPARAM_MLCP_UPDATE_REQUIRED] = 0;
113 options->filterOn = false;
114
115 }
116