OpenCV453
optim.hpp
1/*M///////////////////////////////////////////////////////////////////////////////////////
2//
3// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4//
5// By downloading, copying, installing or using the software you agree to this license.
6// If you do not agree to this license, do not download, install,
7// copy or use the software.
8//
9//
10// License Agreement
11// For Open Source Computer Vision Library
12//
13// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14// Third party copyrights are property of their respective owners.
15//
16// Redistribution and use in source and binary forms, with or without modification,
17// are permitted provided that the following conditions are met:
18//
19// * Redistribution's of source code must retain the above copyright notice,
20// this list of conditions and the following disclaimer.
21//
22// * Redistribution's in binary form must reproduce the above copyright notice,
23// this list of conditions and the following disclaimer in the documentation
24// and/or other materials provided with the distribution.
25//
26// * The name of the copyright holders may not be used to endorse or promote products
27// derived from this software without specific prior written permission.
28//
29// This software is provided by the copyright holders and contributors "as is" and
30// any express or implied warranties, including, but not limited to, the implied
31// warranties of merchantability and fitness for a particular purpose are disclaimed.
32// In no event shall the OpenCV Foundation or contributors be liable for any direct,
33// indirect, incidental, special, exemplary, or consequential damages
34// (including, but not limited to, procurement of substitute goods or services;
35// loss of use, data, or profits; or business interruption) however caused
36// and on any theory of liability, whether in contract, strict liability,
37// or tort (including negligence or otherwise) arising in any way out of
38// the use of this software, even if advised of the possibility of such damage.
39//
40//M*/
41
42#ifndef OPENCV_OPTIM_HPP
43#define OPENCV_OPTIM_HPP
44
45#include "opencv2/core.hpp"
46
47namespace cv
48{
49
58class CV_EXPORTS MinProblemSolver : public Algorithm
59{
60public:
63 class CV_EXPORTS Function
64 {
65 public:
66 virtual ~Function() {}
67 virtual int getDims() const = 0;
68 virtual double getGradientEps() const;
69 virtual double calc(const double* x) const = 0;
70 virtual void getGradient(const double* x,double* grad);
71 };
72
81 virtual Ptr<Function> getFunction() const = 0;
82
89 virtual void setFunction(const Ptr<Function>& f) = 0;
90
95 virtual TermCriteria getTermCriteria() const = 0;
96
108 virtual void setTermCriteria(const TermCriteria& termcrit) = 0;
109
122 virtual double minimize(InputOutputArray x) = 0;
123};
124
155class CV_EXPORTS DownhillSolver : public MinProblemSolver
156{
157public:
164 virtual void getInitStep(OutputArray step) const=0;
165
180 virtual void setInitStep(InputArray step)=0;
181
199 InputArray initStep=Mat_<double>(1,1,0.0),
201};
202
236class CV_EXPORTS ConjGradSolver : public MinProblemSolver
237{
238public:
254};
255
258{
262 SOLVELP_MULTI = 1
264
296CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z);
297
299
300}// cv
301
302#endif
Definition: mat.hpp:386
This type is very similar to InputArray except that it is used for input/output and output function p...
Definition: mat.hpp:295
This is a base class for all more or less complex algorithms in OpenCV
Definition: core.hpp:3091
This class is used to perform the non-linear non-constrained minimization of a function with known gr...
Definition: optim.hpp:237
static Ptr< ConjGradSolver > create(const Ptr< MinProblemSolver::Function > &f=Ptr< ConjGradSolver::Function >(), TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 5000, 0.000001))
This function returns the reference to the ready-to-use ConjGradSolver object.
This class is used to perform the non-linear non-constrained minimization of a function,
Definition: optim.hpp:156
static Ptr< DownhillSolver > create(const Ptr< MinProblemSolver::Function > &f=Ptr< MinProblemSolver::Function >(), InputArray initStep=Mat_< double >(1, 1, 0.0), TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 5000, 0.000001))
This function returns the reference to the ready-to-use DownhillSolver object.
virtual void getInitStep(OutputArray step) const =0
Returns the initial step that will be used in downhill simplex algorithm.
virtual void setInitStep(InputArray step)=0
Sets the initial step that will be used in downhill simplex algorithm.
Template matrix class derived from Mat
Definition: mat.hpp:2199
Represents function being optimized
Definition: optim.hpp:64
Basic interface for all solvers
Definition: optim.hpp:59
virtual void setFunction(const Ptr< Function > &f)=0
Setter for the optimized function.
virtual Ptr< Function > getFunction() const =0
Getter for the optimized function.
virtual TermCriteria getTermCriteria() const =0
Getter for the previously set terminal criteria for this algorithm.
virtual void setTermCriteria(const TermCriteria &termcrit)=0
Set terminal criteria for solver.
virtual double minimize(InputOutputArray x)=0
actually runs the algorithm and performs the minimization.
The class defining termination criteria for iterative algorithms.
Definition: core/types.hpp:853
@ MAX_ITER
ditto
Definition: core/types.hpp:861
@ EPS
the desired accuracy or change in parameters at which the iterative algorithm stops
Definition: core/types.hpp:862
CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z)
Solve given (non-integer) linear programming problem using the Simplex Algorithm (Simplex Method).
SolveLPResult
return codes for cv::solveLP() function
Definition: optim.hpp:258
@ SOLVELP_SINGLE
there is only one maximum for target function
Definition: optim.hpp:261
@ SOLVELP_UNBOUNDED
problem is unbounded (target function can achieve arbitrary high values)
Definition: optim.hpp:259
@ SOLVELP_MULTI
there are multiple maxima for target function - the arbitrary one is returned
Definition: optim.hpp:262
@ SOLVELP_UNFEASIBLE
problem is unfeasible (there are no points that satisfy all the constraints imposed)
Definition: optim.hpp:260
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: cvstd_wrapper.hpp:74