Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SOCP.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __SOCP_hh__
26 #define __SOCP_hh__
27 
28 #include <bias_config.h>
29 #include <Base/Debug/Debug.hh>
30 #include <Base/Math/Vector.hh>
31 #include <Base/Math/Matrix.hh>
32 #include <vector>
33 
34 namespace BIAS
35 {
36 
37  /** @class SOCP
38  @brief Wrapper for Second-Order Cone Programming implementation,
39  by Miguel S. Lobo et al. from Stanford university provided
40  at http://www.stanford.edu/~boyd/old_software/socp/
41  See User's Guide [1] and [2] for details about the algorithm
42  and socp/README.txt for information about the authors.
43 
44  Solves Second-Order Cone Programming (SOCP) problems defined by:
45 
46  min f^T * x s.t. ||A_i * x + b_i|| <= c_i * x + d_i for i = 1, ..., L
47 
48  [1] M. S. Lobo, L. Vandenberghe, S. Boyd: SOCP Software for
49  Second-Order Cone Programming - User's Guide, April 1997.
50  [2] M. S. Lobo, L. Vandenberghe, S. Boyd, H. Lebret: Second-Order Cone
51  Programming: Interior-Point Methods and Engineering Applications,
52  Linear Algebra and Applications, 1997.
53 
54  @see socp/socp.h
55  @author esquivel 05/2012
56  */
57  class BIASMathAlgo_EXPORT SOCP : public BIAS::Debug
58  {
59 
60  public:
61 
62  /** @brief Create SOCP solver with default parameters. */
63  SOCP();
64 
65  /** @brief Release memory used. */
66  ~SOCP();
67 
68  /** @brief Set maximal number of iterations performed by SOCP algorithm. */
69  void SetMaxIterations(int iter) { MaxIters_ = iter; }
70 
71  /** @brief Get maximal number of iterations performed by SOCP algorithm. */
72  int GetMaxIterations() const { return MaxIters_; }
73 
74  /** @brief Set parameter nu that controls the rate of convergence.
75  Recommended range is 5 to 50.
76  @see See SOCP user guide [1] for details about this parameter.
77  */
78  void SetNu(double nu) { Nu_ = nu; }
79 
80  /** @brief Get parameter nu that controls the rate of convergence. */
81  double GetNu() const { return Nu_; }
82 
83  /** @brief Set target value used in convergence criterion only when
84  relative tolerance given is < 0.
85  @see See SOCP user guide [1] for details about this parameter.
86  */
87  void SetTargetValue(double target) { TargetValue_ = target; }
88 
89  /** @brief Get target value used in convergence criterion. */
90  double GetTargetValue() const { return TargetValue_; }
91 
92  /** @brief Set absolute tolerance used to determine convergence.
93  See SOCP user guide [1] for details about this parameter.
94  */
95  void SetAbsoluteTolerance(double tol) { AbsTolerance_ = tol; }
96 
97  /** @brief Get absolute tolerance used to determine convergence. */
98  double GetAbsoluteTolerance() const { return AbsTolerance_; }
99 
100  /** @brief Set relative tolerance used to determine convergence.
101  @see See SOCP user guide [1] for details about this parameter.
102  */
103  void SetRelativeTolerance(double tol) { RelTolerance_ = tol; }
104 
105  /** @brief Get relative tolerance used to determine convergence. */
106  double GetRelativeTolerance() const { return RelTolerance_; }
107 
108  /** @brief Solve Second-Order Cone Programming instance with L constraints.
109 
110  Compute vector x minimizing f * x subject to the constraints
111  ||A_i * x + b_i|| <= c_i * x + d_i for i = 1, ..., L starting with
112  the given solution x.
113 
114  L is the number of constraints, m is the number of variables.
115  Vector N = (N_1, ..., N_L) specifies the problem size of the
116  i-th constraint, i.e. A_i is a N_i x m matrix, b_i is a vector
117  of size N_i, c_i is a vector of size m and d_i is a scalar.
118  Both f and x are vectors of size m.
119 
120  The vectors z_1, ..., z_L and scalars w_1, ..., w_L describe the
121  solution to the dual problem. Each vector z_i is of size N_i.
122  Note that a feasable dual solution must be given as a start point
123  in addition to the primal solution x.
124 
125  @return Returns < 0 in case of errors, 0 otherwise.
126  */
127  int Compute(int L, int m, const std::vector<int> &N,
128  const Vector<double> &f,
129  const std::vector< Matrix<double> > &A,
130  const std::vector< Vector<double> > &b,
131  const std::vector< Vector<double> > &c,
132  const std::vector<double> &d,
133  Vector<double> &x, std::vector< Vector<double> > &z,
134  std::vector<double> &w);
135 
136  /** @brief Solve single-constraint Second-Order Cone Programming instance.
137 
138  Compute vector x minimizing f * x subject to the constraint
139  ||A * x + b|| <= c * x + d starting with the given solution x.
140 
141  m is the number of variables, n specifies the problem size of the
142  constraint, i.e. A is a n x m matrix, b is a vector of size n,
143  c is a vector of size m and d is a scalar.
144  Both f and x are vectors of size m.
145  Vector z of size n and scalar w describe the solution to the dual
146  problem. A feasable dual solution must be given as a start point in
147  addition to the primal solution x.
148 
149  @return Returns < 0 in case of errors, 0 otherwise.
150  */
151  int Compute(int m, int n, const Vector<double> &f,
152  const Matrix<double> &A, const Vector<double> &b,
153  const Vector<double> &c, double d,
154  Vector<double> &x, Vector<double> &z, double &w);
155 
156  private:
157 
158  int MaxIters_;
159  double AbsTolerance_, RelTolerance_;
160  double TargetValue_;
161  double Nu_;
162 
163  };
164 
165 }
166 
167 #endif // __SOCP_hh__
int GetMaxIterations() const
Get maximal number of iterations performed by SOCP algorithm.
Definition: SOCP.hh:72
double GetAbsoluteTolerance() const
Get absolute tolerance used to determine convergence.
Definition: SOCP.hh:98
double GetRelativeTolerance() const
Get relative tolerance used to determine convergence.
Definition: SOCP.hh:106
Wrapper for Second-Order Cone Programming implementation, by Miguel S.
Definition: SOCP.hh:57
void SetNu(double nu)
Set parameter nu that controls the rate of convergence.
Definition: SOCP.hh:78
void SetTargetValue(double target)
Set target value used in convergence criterion only when relative tolerance given is &lt; 0...
Definition: SOCP.hh:87
double GetNu() const
Get parameter nu that controls the rate of convergence.
Definition: SOCP.hh:81
double GetTargetValue() const
Get target value used in convergence criterion.
Definition: SOCP.hh:90
void SetRelativeTolerance(double tol)
Set relative tolerance used to determine convergence.
Definition: SOCP.hh:103
void SetAbsoluteTolerance(double tol)
Set absolute tolerance used to determine convergence.
Definition: SOCP.hh:95
void SetMaxIterations(int iter)
Set maximal number of iterations performed by SOCP algorithm.
Definition: SOCP.hh:69