AliceVision
Photogrammetric Computer Vision Framework
ISolver.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2016 AliceVision contributors.
3 // Copyright (c) 2012 openMVG contributors.
4 // This Source Code Form is subject to the terms of the Mozilla Public License,
5 // v. 2.0. If a copy of the MPL was not distributed with this file,
6 // You can obtain one at https://mozilla.org/MPL/2.0/.
7 
8 #pragma once
9 
10 #include "aliceVision/numeric/numeric.hpp"
11 
12 #include <vector>
13 #include <utility>
14 
15 namespace aliceVision {
16 namespace linearProgramming {
17 
26 {
27  enum eLP_SIGN
28  {
29  LP_LESS_OR_EQUAL = 1, // (<=)
30  LP_GREATER_OR_EQUAL = 2, // (>=)
31  LP_EQUAL = 3, // (=)
32  LP_FREE = 4 // only supported in MOSEK
33  };
34 
35  LPConstraints() { _bminimize = false; }
36 
37  int _nbParams; // The number of parameter/variable in constraint.
38  Mat _constraintMat; // Constraint under Matrix form.
39  Vec _Cst_objective; // Constraint objective value.
40  std::vector<eLP_SIGN> _vec_sign; // Constraint sign.
41  std::vector<std::pair<double, double>> _vec_bounds; // parameter/variable bounds.
42 
43  bool _bminimize; // minimize is true or maximize is false.
44  std::vector<double> _vec_cost; // Objective function
45 };
46 
55 {
56  LPConstraintsSparse() { _bminimize = false; }
57 
58  // Variable part
59  int _nbParams; // The number of parameter/variable in constraint.
60  std::vector<std::pair<double, double>> _vec_bounds; // parameter/variable bounds.
61 
62  // Constraint part
63  sRMat _constraintMat; // Constraint under Matrix form.
64  Vec _Cst_objective; // Constraint objective value.
65  std::vector<LPConstraints::eLP_SIGN> _vec_sign; // Constraint sign.
66 
67  bool _bminimize; // minimize is true or maximize is false.
68  std::vector<double> _vec_cost; // Objective function
69 };
70 
74 class ISolver
75 {
76  public:
77  ISolver(int nbParams)
78  : _nbParams(nbParams){};
79 
81  virtual bool setup(const LPConstraints& constraints) = 0;
82  virtual bool setup(const LPConstraintsSparse& constraints) = 0;
83 
85  virtual bool solve() = 0;
86 
88  virtual bool getSolution(std::vector<double>& estimatedParams) = 0;
89 
90  protected:
91  int _nbParams; // The number of parameter considered in constraint formulation.
92 };
93 
94 } // namespace linearProgramming
95 } // namespace aliceVision
aliceVision::linearProgramming::LPConstraints
Definition: ISolver.hpp:25
aliceVision::linearProgramming::ISolver::getSolution
virtual bool getSolution(std::vector< double > &estimatedParams)=0
Get back solution. Call it after solve.
aliceVision::linearProgramming::ISolver::solve
virtual bool solve()=0
Setup the feasibility and found the solution that best fit the constraint.
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::linearProgramming::ISolver::setup
virtual bool setup(const LPConstraints &constraints)=0
Setup constraint for the given library.
aliceVision::linearProgramming::LPConstraintsSparse
Definition: ISolver.hpp:54
aliceVision::linearProgramming::ISolver
Definition: ISolver.hpp:74