Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
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 
65 class VISP_EXPORT vpLinProg
66 {
67 public:
68 
69 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
70 
121  typedef std::pair<unsigned int, double> BoundedIndex;
122 
125  static bool simplex(const vpColVector &c, vpMatrix A, vpColVector b,
126  vpColVector &x, const double &tol = 1e-6);
127 
128  static bool solveLP(const vpColVector &c, vpMatrix A, vpColVector b,
129  const vpMatrix &C, const vpColVector &d, vpColVector &x,
130  std::vector<BoundedIndex> l = {},
131  std::vector<BoundedIndex> u = {},
132  const double &tol = 1e-6);
133 
135 #endif
136 
139  static bool colReduction(vpMatrix &A, vpColVector &b, bool full_rank = false, const double &tol = 1e-6);
140 
141  static bool rowReduction(vpMatrix &A, vpColVector &b, const double &tol = 1e-6);
143 
154  static bool allZero(const vpColVector &x, const double &tol = 1e-6)
155  {
156  for(unsigned int i = 0; i < x.getRows(); ++i)
157  {
158  if(std::abs(x[i]) > tol)
159  return false;
160  }
161  return true;
162  }
163 
174  static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol = 1e-6)
175  {
176  for(unsigned int i = 0; i < b.getRows(); ++i)
177  {
178  if(std::abs(A.getRow(i)*x - b[i]) > tol)
179  return false;
180  }
181  return true;
182  }
183 
193  static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr = 1e-6)
194  {
195  for(unsigned int i = 0; i < d.getRows(); ++i)
196  {
197  if(C.getRow(i)*x - d[i] > thr)
198  return false;
199  }
200  return true;
201  }
202 
211  static bool allLesser(const vpColVector &x, const double &thr = 1e-6)
212  {
213  for(unsigned int i = 0; i < x.getRows(); ++i)
214  {
215  if(x[i] > thr)
216  return false;
217  }
218  return true;
219  }
220 
229  static bool allGreater(const vpColVector &x, const double &thr = 1e-6)
230  {
231  for(unsigned int i = 0; i < x.getRows(); ++i)
232  {
233  if(x[i] < thr)
234  return false;
235  }
236  return true;
237  }
239 };
240 #endif // vpLinProgh
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol=1e-6)
Definition: vpLinProg.h:174
std::pair< unsigned int, double > BoundedIndex
Definition: vpLinProg.h:121
static bool allGreater(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:229
vpRowVector getRow(const unsigned int i) const
Definition: vpMatrix.cpp:3844
This class provides two solvers for Linear Programs.
Definition: vpLinProg.h:65
static bool allLesser(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:211
unsigned int getRows() const
Definition: vpArray2D.h:156
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr=1e-6)
Definition: vpLinProg.h:193
static bool allZero(const vpColVector &x, const double &tol=1e-6)
Definition: vpLinProg.h:154