dense_qp_solver.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit 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 GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
35 
36 
38 
39 
40 //
41 // PUBLIC MEMBER FUNCTIONS:
42 //
43 
45 {
46  setupLogging( );
47 
49  numberOfSteps = 0;
50 }
51 
52 
53 DenseQPsolver::DenseQPsolver( UserInteraction* _userInteraction ) : DenseCPsolver( _userInteraction )
54 {
55  setupLogging( );
56 
58  numberOfSteps = 0;
59 }
60 
61 
63 {
64  qpStatus = rhs.qpStatus;
66 }
67 
68 
70 
71 }
72 
73 
75 
76  if ( this != &rhs ){
77 
79 
80  qpStatus = rhs.qpStatus;
81  }
82  return *this;
83 }
84 
85 
87 {
88  //printf( "nV: %d, nC: %d!!\n",nV,nC );
89  return setupQPobject( nV,nC );
90 }
91 
92 
94 {
95  ASSERT( cp != 0 );
96 
97  if( cp->isQP() == BT_FALSE )
99 
100  return init( cp->getNV(),cp->getNC() );
101 }
102 
103 
105 {
106  ASSERT( cp != 0 );
107 
108  if( cp->isQP() == BT_FALSE )
110 
113 
114  int maxNumQPiterations;
115  get( MAX_NUM_QP_ITERATIONS, maxNumQPiterations );
116 
117  returnValue returnvalue;
118  returnvalue = solve( &cp->H, &cp->A, &cp->g, &cp->lb, &cp->ub, &cp->lbA, &cp->ubA, maxNumQPiterations );
119 
120  if ( ( returnvalue != SUCCESSFUL_RETURN ) && ( returnvalue != RET_QP_SOLUTION_REACHED_LIMIT ) )
121  return returnvalue;
122 
123 
124  // GET THE PRIMAL AND DUAL SOLUTION FROM THE QP SOLVER AND
125  // STORE THEM IN THE RIGHT FORMAT:
126  // -------------------------------------------------------
127  DVector xOpt, yOpt;
128 
129  getPrimalSolution( xOpt );
130  getDualSolution ( yOpt );
131 
132 // xOpt.print("xOpt");
133 // yOpt.print("yOpt");
134 
135  cp->setQPsolution( xOpt,yOpt );
136 
137  return returnvalue;
138 }
139 
140 
142 {
143  return numberOfSteps;
144 }
145 
146 
147 
148 
149 //
150 // PROTECTED MEMBER FUNCTIONS:
151 //
152 
153 
155 {
157 
159  tmp.addItem( LOG_IS_QP_RELAXED );
160 
161  addLogRecord( tmp );
162 
163  return SUCCESSFUL_RETURN;
164 }
165 
166 
167 
169  ) const
170 {
171  uint i;
172  double mean;
173 
174  if ( cp->lb.getDim( ) != cp->ub.getDim( ) )
176 
177  for( i=0; i<cp->lb.getDim( ); ++i )
178  {
179  if ( cp->lb(i) > cp->ub(i) )
180  {
181  if ( cp->lb(i) > cp->ub(i)+SQRT_EPS )
183  else
184  {
185  mean = ( cp->lb(i) + cp->ub(i) ) / 2.0;
186  cp->lb(i) = mean;
187  cp->ub(i) = mean;
188  }
189  }
190  }
191 
192  if ( cp->lbA.getDim( ) != cp->ubA.getDim( ) )
194 
195  for( i=0; i<cp->lbA.getDim( ); ++i )
196  {
197  if ( cp->lbA(i) > cp->ubA(i) )
198  {
199  if ( cp->lbA(i) > cp->ubA(i)+SQRT_EPS )
201  else
202  {
203  mean = ( cp->lbA(i) + cp->ubA(i) ) / 2.0;
204  cp->lbA(i) = mean;
205  cp->ubA(i) = mean;
206  }
207  }
208  }
209 
210  return SUCCESSFUL_RETURN;
211 }
212 
213 
214 
216 
217 // end of file.
virtual returnValue setupLogging()
DVector lb
Definition: dense_cp.hpp:384
returnValue addItem(LogName _name, const char *const _label=DEFAULT_LABEL)
Definition: log_record.cpp:70
DenseQPsolver & operator=(const DenseQPsolver &rhs)
DVector ub
Definition: dense_cp.hpp:385
const double SQRT_EPS
Allows to pass back messages to the calling function.
DVector g
Definition: dense_cp.hpp:382
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
returnValue setQPsolution(const DVector &x_, const DVector &y_)
Definition: dense_cp.cpp:204
BooleanType isQP() const
virtual returnValue setupQPobject(uint nV, uint nC)=0
#define CLOSE_NAMESPACE_ACADO
virtual returnValue makeBoundsConsistent(DenseCP *cp) const
DMatrix H
Definition: dense_cp.hpp:381
Abstract base class for algorithms solving quadratic programs.
uint getNC() const
Data class for storing generic conic programs.
Definition: dense_cp.hpp:55
unsigned getDim() const
Definition: vector.hpp:172
DenseCPsolver & operator=(const DenseCPsolver &rhs)
virtual returnValue getDualSolution(DVector &yOpt) const =0
uint getNV() const
virtual returnValue init(const DenseCP *cp)
Encapsulates all user interaction for setting options, logging data and plotting results.
void rhs(const real_t *x, real_t *f)
virtual returnValue getPrimalSolution(DVector &xOpt) const =0
DVector ubA
Definition: dense_cp.hpp:389
#define ASSERT(x)
DMatrix A
Definition: dense_cp.hpp:387
virtual uint getNumberOfIterations() const
virtual returnValue solve(DenseCP *cp_)
Allows to setup and store user-specified log records of algorithmic information.
Definition: log_record.hpp:72
#define BEGIN_NAMESPACE_ACADO
DVector lbA
Definition: dense_cp.hpp:388
int addLogRecord(LogRecord &_record)
#define BT_FALSE
Definition: acado_types.hpp:49
Base class for algorithms solving conic programs.
#define ACADOERROR(retval)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:32