Visual Servoing Platform  version 3.6.1 under development (2024-04-27)
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)
114  typedef std::pair<unsigned int, double> BoundedIndex;
115 
118  static bool simplex(const vpColVector &c, vpMatrix A, vpColVector b, vpColVector &x, const double &tol = 1e-6);
119 
120  static bool solveLP(const vpColVector &c, vpMatrix A, vpColVector b, const vpMatrix &C, const vpColVector &d,
121  vpColVector &x, std::vector<BoundedIndex> l = {}, std::vector<BoundedIndex> u = {},
122  const double &tol = 1e-6);
123 
125 #endif
126 
129  static bool colReduction(vpMatrix &A, vpColVector &b, bool full_rank = false, const double &tol = 1e-6);
130 
131  static bool rowReduction(vpMatrix &A, vpColVector &b, const double &tol = 1e-6);
133 
144  static bool allZero(const vpColVector &x, const double &tol = 1e-6)
145  {
146  for (unsigned int i = 0; i < x.getRows(); ++i) {
147  if (std::abs(x[i]) > tol)
148  return false;
149  }
150  return true;
151  }
152 
163  static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol = 1e-6)
164  {
165  for (unsigned int i = 0; i < b.getRows(); ++i) {
166  if (std::abs(A.getRow(i) * x - b[i]) > tol)
167  return false;
168  }
169  return true;
170  }
171 
181  static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr = 1e-6)
182  {
183  for (unsigned int i = 0; i < d.getRows(); ++i) {
184  if (C.getRow(i) * x - d[i] > thr)
185  return false;
186  }
187  return true;
188  }
189 
198  static bool allLesser(const vpColVector &x, const double &thr = 1e-6)
199  {
200  for (unsigned int i = 0; i < x.getRows(); ++i) {
201  if (x[i] > thr)
202  return false;
203  }
204  return true;
205  }
206 
215  static bool allGreater(const vpColVector &x, const double &thr = 1e-6)
216  {
217  for (unsigned int i = 0; i < x.getRows(); ++i) {
218  if (x[i] < thr)
219  return false;
220  }
221  return true;
222  }
224 };
225 #endif
unsigned int getRows() const
Definition: vpArray2D.h:337
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:215
static bool allLesser(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:198
static bool allZero(const vpColVector &x, const double &tol=1e-6)
Definition: vpLinProg.h:144
static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr=1e-6)
Definition: vpLinProg.h:181
static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol=1e-6)
Definition: vpLinProg.h:163
std::pair< unsigned int, double > BoundedIndex
Definition: vpLinProg.h:114
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:146
vpRowVector getRow(unsigned int i) const
Definition: vpMatrix.cpp:5013