Visual Servoing Platform  version 3.5.1 under development (2023-03-14)
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/vpColVector.h>
46 #include <visp3/core/vpConfig.h>
47 #include <visp3/core/vpMatrix.h>
48 
66 class VISP_EXPORT vpLinProg
67 {
68 public:
69 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
122  typedef std::pair<unsigned int, double> BoundedIndex;
123 
126  static bool simplex(const vpColVector &c, vpMatrix A, vpColVector b, vpColVector &x, const double &tol = 1e-6);
127 
128  static bool solveLP(const vpColVector &c, vpMatrix A, vpColVector b, const vpMatrix &C, const vpColVector &d,
129  vpColVector &x, std::vector<BoundedIndex> l = {}, std::vector<BoundedIndex> u = {},
130  const double &tol = 1e-6);
131 
133 #endif
134 
137  static bool colReduction(vpMatrix &A, vpColVector &b, bool full_rank = false, const double &tol = 1e-6);
138 
139  static bool rowReduction(vpMatrix &A, vpColVector &b, const double &tol = 1e-6);
141 
152  static bool allZero(const vpColVector &x, const double &tol = 1e-6)
153  {
154  for (unsigned int i = 0; i < x.getRows(); ++i) {
155  if (std::abs(x[i]) > tol)
156  return false;
157  }
158  return true;
159  }
160 
171  static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol = 1e-6)
172  {
173  for (unsigned int i = 0; i < b.getRows(); ++i) {
174  if (std::abs(A.getRow(i) * x - b[i]) > tol)
175  return false;
176  }
177  return true;
178  }
179 
189  static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr = 1e-6)
190  {
191  for (unsigned int i = 0; i < d.getRows(); ++i) {
192  if (C.getRow(i) * x - d[i] > thr)
193  return false;
194  }
195  return true;
196  }
197 
206  static bool allLesser(const vpColVector &x, const double &thr = 1e-6)
207  {
208  for (unsigned int i = 0; i < x.getRows(); ++i) {
209  if (x[i] > thr)
210  return false;
211  }
212  return true;
213  }
214 
223  static bool allGreater(const vpColVector &x, const double &thr = 1e-6)
224  {
225  for (unsigned int i = 0; i < x.getRows(); ++i) {
226  if (x[i] < thr)
227  return false;
228  }
229  return true;
230  }
232 };
233 #endif // vpLinProgh
unsigned int getRows() const
Definition: vpArray2D.h:288
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
This class provides two solvers for Linear Programs.
Definition: vpLinProg.h:67
static bool allGreater(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:223
static bool allLesser(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:206
static bool allZero(const vpColVector &x, const double &tol=1e-6)
Definition: vpLinProg.h:152
static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr=1e-6)
Definition: vpLinProg.h:189
static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol=1e-6)
Definition: vpLinProg.h:171
std::pair< unsigned int, double > BoundedIndex
Definition: vpLinProg.h:122
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:154
vpRowVector getRow(unsigned int i) const
Definition: vpMatrix.cpp:5207