Visual Servoing Platform  version 3.4.0
vpLinProg.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Linear Programming with simplex
33  *
34  * Authors:
35  * Olivier Kermorgant
36  *
37  *****************************************************************************/
38 
39 #ifndef vpLinProgh
40 #define vpLinProgh
41 
42 #include <cmath> // For std::abs() on iOS
43 #include <cstdlib> // For std::abs() on iOS
44 
45 #include <visp3/core/vpConfig.h>
46 #include <visp3/core/vpColVector.h>
47 #include <visp3/core/vpMatrix.h>
48 
66 class VISP_EXPORT vpLinProg
67 {
68 public:
69 
70 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
71 
122  typedef std::pair<unsigned int, double> BoundedIndex;
123 
126  static bool simplex(const vpColVector &c, vpMatrix A, vpColVector b,
127  vpColVector &x, const double &tol = 1e-6);
128 
129  static bool solveLP(const vpColVector &c, vpMatrix A, vpColVector b,
130  const vpMatrix &C, const vpColVector &d, vpColVector &x,
131  std::vector<BoundedIndex> l = {},
132  std::vector<BoundedIndex> u = {},
133  const double &tol = 1e-6);
134 
136 #endif
137 
140  static bool colReduction(vpMatrix &A, vpColVector &b, bool full_rank = false, const double &tol = 1e-6);
141 
142  static bool rowReduction(vpMatrix &A, vpColVector &b, const double &tol = 1e-6);
144 
155  static bool allZero(const vpColVector &x, const double &tol = 1e-6)
156  {
157  for(unsigned int i = 0; i < x.getRows(); ++i)
158  {
159  if(std::abs(x[i]) > tol)
160  return false;
161  }
162  return true;
163  }
164 
175  static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol = 1e-6)
176  {
177  for(unsigned int i = 0; i < b.getRows(); ++i)
178  {
179  if(std::abs(A.getRow(i)*x - b[i]) > tol)
180  return false;
181  }
182  return true;
183  }
184 
194  static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr = 1e-6)
195  {
196  for(unsigned int i = 0; i < d.getRows(); ++i)
197  {
198  if(C.getRow(i)*x - d[i] > thr)
199  return false;
200  }
201  return true;
202  }
203 
212  static bool allLesser(const vpColVector &x, const double &thr = 1e-6)
213  {
214  for(unsigned int i = 0; i < x.getRows(); ++i)
215  {
216  if(x[i] > thr)
217  return false;
218  }
219  return true;
220  }
221 
230  static bool allGreater(const vpColVector &x, const double &thr = 1e-6)
231  {
232  for(unsigned int i = 0; i < x.getRows(); ++i)
233  {
234  if(x[i] < thr)
235  return false;
236  }
237  return true;
238  }
240 };
241 #endif // vpLinProgh
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:153
static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol=1e-6)
Definition: vpLinProg.h:175
std::pair< unsigned int, double > BoundedIndex
Definition: vpLinProg.h:122
static bool allGreater(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:230
vpRowVector getRow(unsigned int i) const
Definition: vpMatrix.cpp:5215
This class provides two solvers for Linear Programs.
Definition: vpLinProg.h:66
static bool allLesser(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:212
unsigned int getRows() const
Definition: vpArray2D.h:289
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr=1e-6)
Definition: vpLinProg.h:194
static bool allZero(const vpColVector &x, const double &tol=1e-6)
Definition: vpLinProg.h:155