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 #ifndef MLCP_PROBLEM_H 19 #define MLCP_PROBLEM_H 20 21 /*!\file MixedLinearComplementarityProblem.h 22 \brief Structure used to define a Mixed Linear Complementarity Problem 23 24 */ 25 26 #include <stdio.h> // for FILE 27 #include "NumericsFwd.h" // for MixedLinearComplementarityProblem, Numerics... 28 #include "SiconosConfig.h" // for BUILD_AS_CPP // IWYU pragma: keep 29 30 /** \struct MixedLinearComplementarityProblem MixedLinearComplementarityProblem.h 31 * The Structure that contains and defines MLCProblem. Find \f$(z,w)\f$ such that: 32 * \f$ 33 * \left\{ 34 * \begin{array}{l} 35 * M \ z + q = w \\ 36 * w_1=0 \\ 37 * 0 \le w_{2} \perp v \ge 0 38 * \end{array} 39 * \right. 40 * \text{ with } 41 * z= 42 * \left[ 43 * \begin{array}{c} 44 * u\\ 45 * v\\ 46 * \end{array} 47 * \right] 48 * \text{ and } 49 * w= 50 * \left[ 51 * \begin{array}{c} 52 * w_{1}\\ 53 * w_{2}\\ 54 * \end{array} 55 * \right] 56 * \f$ 57 * \f$ u, w_{1}\f$ are vectors of size n. 58 * \f$ v, w_{2}\f$ are vectors of size m. 59 * 60 * ABCD format (see "R. W. {Cottle} and J. {Pang} and R. E. {Stone}", "The Linear Complementarity Problem, Academic Press, Inc., 1992, Section 1.5 ) 61 * \left[ 62 * \begin{array}{cc} 63 * A & C \\ 64 * D & B \\ 65 * \end{array} 66 * \right] 67 */ 68 struct MixedLinearComplementarityProblem 69 { 70 int isStorageType1; /**< boolean for storageType1 1 if the problem 71 is saved using (M,q), 0 otherwise */ 72 int isStorageType2; /**< boolean for storageType2 1 if the problem 73 is saved using (A,B,C,D,a,b), 0 otherwise*/ 74 int n; /**< number of equality constraints */ 75 int m; /**< number of complementarity constraints */ 76 int * blocksRows; /**< The rows from blocksRows[i] to blocksRows[i+1]-1 77 forms a block of equalities iif bloksIsComp[i]=0, 78 else the block is a complementarity block. 79 The number of total blocks is given by NbBlocks 80 such that blocksRows[NbBlocks] = n+m */ 81 int * blocksIsComp; /**< if bloksIsComp[i]=0, then block i formed by the rows 82 from blocksRows[i] to blocksRows[i+1]-1 is an equality block 83 else the block is a complementarity block. 84 */ 85 NumericsMatrix* M; /**< M matrix of the MLCP */ 86 double *q; /**< q vector of the MLCP */ 87 /** NumericsMatrix* Bblock;*/ /**< Bblock ?*/ 88 double *A; /**< A matrix of the MLCP */ 89 double *B; /**< B matrix of the MLCP */ 90 double *C; /**< C matrix of the MLCP */ 91 double *D; /**< D matrix of the MLCP */ 92 double *a; /**< a vector of the MLCP */ 93 double *b; /**< b vector of the MLCP */ 94 }; 95 96 97 #if defined(__cplusplus) && !defined(BUILD_AS_CPP) 98 extern "C" 99 { 100 #endif 101 102 /** \fn void mixedLinearComplementarity_free(MixedLinearComplementarityProblem* problem) 103 * \brief function to delete a MixedLinearComplementarityProblem 104 * \param problem pointer to a MixedLinearComplementarityProblem to delete 105 */ 106 void mixedLinearComplementarity_free(MixedLinearComplementarityProblem* problem); 107 108 /** create empty MLCP 109 * \return empy MLCP 110 */ 111 MixedLinearComplementarityProblem* mixedLinearComplementarity_new(void); 112 113 /** display a MLCP 114 */ 115 void mixedLinearComplementarity_display(MixedLinearComplementarityProblem* p); 116 117 /** \fn int mixedLinearComplementarity_printInFile(MixedLinearComplementarityProblem* problem, FILE* file) 118 * \brief function to write in a file a MixedLinearComplementarityProblem 119 * \param problem pointer to a MixedLinearComplementarityProblem to print 120 * \param file pointer to a FILE 121 * \return 0 if ok 122 */ 123 int mixedLinearComplementarity_printInFile(MixedLinearComplementarityProblem* problem, FILE* file); 124 125 126 /** \fn int mixedLinearComplementarity_newFromFile(MixedLinearComplementarityProblem* problem, FILE* file) 127 * \brief function to read and create a MixedLinearComplementarityProblem 128 * from a file 129 * \param problem pointer to a MixedLinearComplementarityProblem to create 130 * \param file pointer to a FILE 131 * \return 0 if ok 132 */ 133 int mixedLinearComplementarity_newFromFile(MixedLinearComplementarityProblem* problem, FILE* file); 134 135 /** \fn int mixedLinearComplementarity_newFromFileOld(MixedLinearComplementarityProblem* problem, FILE* file) 136 * \brief function to read and create a MixedLinearComplementarityProblem 137 * from a file 138 * \param problem pointer to a MixedLinearComplementarityProblem to create 139 * \param file pointer to a FILE 140 * \return 0 if ok 141 */ 142 int mixedLinearComplementarity_newFromFileOld(MixedLinearComplementarityProblem* problem, FILE* file); 143 144 /** \fn int mixedLinearComplementarity_newFromFilename(MixedLinearComplementarityProblem* problem, FILE* MLCPfile) 145 * \brief function to read and create a MixedLinearComplementarityProblem 146 * from a file 147 * \param problem pointer to a MixedLinearComplementarityProblem to create 148 * \param filename that contains the mlcp 149 * \return 0 if ok 150 */ 151 int mixedLinearComplementarity_newFromFilename(MixedLinearComplementarityProblem* problem, const char* filename); 152 153 /** \fn MixedLinearComplementarityProblem* mixedLinearComplementarity_fromMtoABCD(MixedLinearComplementarityProblem* problem); 154 * \brief function to create a MLCP with ABCD format from M formatted MLCP 155 */ 156 157 MixedLinearComplementarityProblem* mixedLinearComplementarity_fromMtoABCD(MixedLinearComplementarityProblem* problem); 158 159 #if defined(__cplusplus) && !defined(BUILD_AS_CPP) 160 } 161 #endif 162 163 #endif 164 165