Visual Servoing Platform  version 3.5.1 under development (2023-09-22)
vpLinProg.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Linear Programming with simplex
32  */
33 
34 #ifndef vpLinProgh
35 #define vpLinProgh
36 
37 #include <cmath> // For std::abs() on iOS
38 #include <cstdlib> // For std::abs() on iOS
39 
40 #include <visp3/core/vpColVector.h>
41 #include <visp3/core/vpConfig.h>
42 #include <visp3/core/vpMatrix.h>
43 
61 class VISP_EXPORT vpLinProg
62 {
63 public:
64 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
117  typedef std::pair<unsigned int, double> BoundedIndex;
118 
121  static bool simplex(const vpColVector &c, vpMatrix A, vpColVector b, vpColVector &x, const double &tol = 1e-6);
122 
123  static bool solveLP(const vpColVector &c, vpMatrix A, vpColVector b, const vpMatrix &C, const vpColVector &d,
124  vpColVector &x, std::vector<BoundedIndex> l = {}, std::vector<BoundedIndex> u = {},
125  const double &tol = 1e-6);
126 
128 #endif
129 
132  static bool colReduction(vpMatrix &A, vpColVector &b, bool full_rank = false, const double &tol = 1e-6);
133 
134  static bool rowReduction(vpMatrix &A, vpColVector &b, const double &tol = 1e-6);
136 
147  static bool allZero(const vpColVector &x, const double &tol = 1e-6)
148  {
149  for (unsigned int i = 0; i < x.getRows(); ++i) {
150  if (std::abs(x[i]) > tol)
151  return false;
152  }
153  return true;
154  }
155 
166  static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol = 1e-6)
167  {
168  for (unsigned int i = 0; i < b.getRows(); ++i) {
169  if (std::abs(A.getRow(i) * x - b[i]) > tol)
170  return false;
171  }
172  return true;
173  }
174 
184  static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr = 1e-6)
185  {
186  for (unsigned int i = 0; i < d.getRows(); ++i) {
187  if (C.getRow(i) * x - d[i] > thr)
188  return false;
189  }
190  return true;
191  }
192 
201  static bool allLesser(const vpColVector &x, const double &thr = 1e-6)
202  {
203  for (unsigned int i = 0; i < x.getRows(); ++i) {
204  if (x[i] > thr)
205  return false;
206  }
207  return true;
208  }
209 
218  static bool allGreater(const vpColVector &x, const double &thr = 1e-6)
219  {
220  for (unsigned int i = 0; i < x.getRows(); ++i) {
221  if (x[i] < thr)
222  return false;
223  }
224  return true;
225  }
227 };
228 #endif // vpLinProgh
unsigned int getRows() const
Definition: vpArray2D.h:290
Implementation of column vector and the associated operations.
Definition: vpColVector.h:167
This class provides two solvers for Linear Programs.
Definition: vpLinProg.h:62
static bool allGreater(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:218
static bool allLesser(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:201
static bool allZero(const vpColVector &x, const double &tol=1e-6)
Definition: vpLinProg.h:147
static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr=1e-6)
Definition: vpLinProg.h:184
static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol=1e-6)
Definition: vpLinProg.h:166
std::pair< unsigned int, double > BoundedIndex
Definition: vpLinProg.h:117
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:152
vpRowVector getRow(unsigned int i) const
Definition: vpMatrix.cpp:5237