Visual Servoing Platform  version 3.6.1 under development (2023-12-07)
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:
113  typedef std::pair<unsigned int, double> BoundedIndex;
114 
117  static bool simplex(const vpColVector &c, vpMatrix A, vpColVector b, vpColVector &x, const double &tol = 1e-6);
118 
119  static bool solveLP(const vpColVector &c, vpMatrix A, vpColVector b, const vpMatrix &C, const vpColVector &d,
120  vpColVector &x, std::vector<BoundedIndex> l = {}, std::vector<BoundedIndex> u = {},
121  const double &tol = 1e-6);
122 
124 
127  static bool colReduction(vpMatrix &A, vpColVector &b, bool full_rank = false, const double &tol = 1e-6);
128 
129  static bool rowReduction(vpMatrix &A, vpColVector &b, const double &tol = 1e-6);
131 
142  static bool allZero(const vpColVector &x, const double &tol = 1e-6)
143  {
144  for (unsigned int i = 0; i < x.getRows(); ++i) {
145  if (std::abs(x[i]) > tol)
146  return false;
147  }
148  return true;
149  }
150 
161  static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol = 1e-6)
162  {
163  for (unsigned int i = 0; i < b.getRows(); ++i) {
164  if (std::abs(A.getRow(i) * x - b[i]) > tol)
165  return false;
166  }
167  return true;
168  }
169 
179  static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr = 1e-6)
180  {
181  for (unsigned int i = 0; i < d.getRows(); ++i) {
182  if (C.getRow(i) * x - d[i] > thr)
183  return false;
184  }
185  return true;
186  }
187 
196  static bool allLesser(const vpColVector &x, const double &thr = 1e-6)
197  {
198  for (unsigned int i = 0; i < x.getRows(); ++i) {
199  if (x[i] > thr)
200  return false;
201  }
202  return true;
203  }
204 
213  static bool allGreater(const vpColVector &x, const double &thr = 1e-6)
214  {
215  for (unsigned int i = 0; i < x.getRows(); ++i) {
216  if (x[i] < thr)
217  return false;
218  }
219  return true;
220  }
222 };
223 #endif
unsigned int getRows() const
Definition: vpArray2D.h:267
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
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:213
static bool allLesser(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:196
static bool allZero(const vpColVector &x, const double &tol=1e-6)
Definition: vpLinProg.h:142
static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr=1e-6)
Definition: vpLinProg.h:179
static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol=1e-6)
Definition: vpLinProg.h:161
std::pair< unsigned int, double > BoundedIndex
Definition: vpLinProg.h:113
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:146
vpRowVector getRow(unsigned int i) const
Definition: vpMatrix.cpp:5226