Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
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 
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 
49 BEGIN_VISP_NAMESPACE
62 class VISP_EXPORT vpLinProg
63 {
64 public:
65 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
119  typedef std::pair<unsigned int, double> BoundedIndex;
120 
123  static bool simplex(const vpColVector &c, vpMatrix A, vpColVector b, vpColVector &x, const double &tol = 1e-6);
124 
125  static bool solveLP(const vpColVector &c, vpMatrix A, vpColVector b, const vpMatrix &C, const vpColVector &d,
126  vpColVector &x, std::vector<BoundedIndex> l = {}, std::vector<BoundedIndex> u = {},
127  const double &tol = 1e-6);
128 
130 #endif
131 
134  static bool colReduction(vpMatrix &A, vpColVector &b, bool full_rank = false, const double &tol = 1e-6);
135 
136  static bool rowReduction(vpMatrix &A, vpColVector &b, const double &tol = 1e-6);
138 
149  static bool allZero(const vpColVector &x, const double &tol = 1e-6)
150  {
151  for (unsigned int i = 0; i < x.getRows(); ++i) {
152  if (std::abs(x[i]) > tol)
153  return false;
154  }
155  return true;
156  }
157 
168  static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol = 1e-6)
169  {
170  for (unsigned int i = 0; i < b.getRows(); ++i) {
171  if (std::abs(A.getRow(i) * x - b[i]) > tol)
172  return false;
173  }
174  return true;
175  }
176 
186  static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr = 1e-6)
187  {
188  for (unsigned int i = 0; i < d.getRows(); ++i) {
189  if (C.getRow(i) * x - d[i] > thr)
190  return false;
191  }
192  return true;
193  }
194 
203  static bool allLesser(const vpColVector &x, const double &thr = 1e-6)
204  {
205  for (unsigned int i = 0; i < x.getRows(); ++i) {
206  if (x[i] > thr)
207  return false;
208  }
209  return true;
210  }
211 
220  static bool allGreater(const vpColVector &x, const double &thr = 1e-6)
221  {
222  for (unsigned int i = 0; i < x.getRows(); ++i) {
223  if (x[i] < thr)
224  return false;
225  }
226  return true;
227  }
229 };
230 END_VISP_NAMESPACE
231 #endif
unsigned int getRows() const
Definition: vpArray2D.h:347
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
This class provides two solvers for Linear Programs.
Definition: vpLinProg.h:63
static bool allGreater(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:220
static bool allLesser(const vpColVector &x, const double &thr=1e-6)
Definition: vpLinProg.h:203
static bool allZero(const vpColVector &x, const double &tol=1e-6)
Definition: vpLinProg.h:149
static bool allLesser(const vpMatrix &C, const vpColVector &x, const vpColVector &d, const double &thr=1e-6)
Definition: vpLinProg.h:186
static bool allClose(const vpMatrix &A, const vpColVector &x, const vpColVector &b, const double &tol=1e-6)
Definition: vpLinProg.h:168
std::pair< unsigned int, double > BoundedIndex
Definition: vpLinProg.h:119
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
vpRowVector getRow(unsigned int i) const
Definition: vpMatrix.cpp:590