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_Solvers.h"  // for mixedLinearComplementarity_simplex_setDefa...
29 #include "NumericsFwd.h"   // for MixedLinearComplementarityProblem, SolverO...
30 #include "mlcp_simplex.h"  // for mlcp_simplex_init, mlcp_simplex_reset
31 #include "SiconosConfig.h" // for HAVE_MLCPSIMPLEX  // IWYU pragma: keep
32 
33 #ifdef HAVE_MLCPSIMPLEX
34 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include "SiconosCompat.h"
39 #include <math.h>
40 /*import external implementation*/
41 #include "external_mlcp_simplex.h"
42 
43 static int sIsInitialize = 0;
44 #endif
45 
mlcp_simplex_init(MixedLinearComplementarityProblem * problem,SolverOptions * options)46 void mlcp_simplex_init(MixedLinearComplementarityProblem* problem, SolverOptions* options)
47 {
48 #ifdef HAVE_MLCPSIMPLEX
49   int nn = problem->n;
50   int mm = problem->m;
51   extern_mlcp_simplex_init_with_M(&nn, &mm, problem->M->matrix0);
52   sIsInitialize = 1;
53 #endif
54 }
mlcp_simplex_reset()55 void mlcp_simplex_reset()
56 {
57 #ifdef HAVE_MLCPSIMPLEX
58   extern_mlcp_simplex_stop();
59   sIsInitialize = 0;
60 #endif
61 }
62 
mlcp_simplex(MixedLinearComplementarityProblem * problem,double * z,double * w,int * info,SolverOptions * options)63 void mlcp_simplex(MixedLinearComplementarityProblem* problem, double *z, double *w, int *info, SolverOptions* options)
64 {
65 #ifdef HAVE_MLCPSIMPLEX
66   //  double tol ;
67   //  double * workingFloat=options->dWork;
68   //  int * workingInt=options->iWork;
69   //  int lin;
70   //  int npm=(problem->n)+(problem->m);
71   //  int npm2 = npm*npm;
72   //  int NRHS=1;
73   //  int one=1;
74   //  int * ipiv;
75   //  int check;
76   //  int DGESVinfo=1;
77   int nn = problem->n;
78   int mm = problem->m;
79 
80   if(!sIsInitialize)
81     extern_mlcp_simplex_init_with_M(&nn, &mm, problem->M->matrix0);
82 
83   extern_mlcp_simplex(problem->q, problem->q + nn, z, z + nn, w, info,  options->iparam, options->dparam);
84 
85   if(!sIsInitialize)
86     extern_mlcp_simplex_stop();
87 #endif
88 }
89