qpOASES-3.0beta/interfaces/scilab/qpOASESroutines.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of qpOASES.
3  *
4  * qpOASES -- An Implementation of the Online Active Set Strategy.
5  * Copyright (C) 2007-2011 by Hans Joachim Ferreau, Andreas Potschka,
6  * Christian Kirches et al. All rights reserved.
7  *
8  * qpOASES is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * qpOASES is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with qpOASES; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23 
24 
38 #include <iostream>
39 
40 #include <qpOASES/SQProblem.hpp>
41 
42 
43 using namespace qpOASES;
44 
45 /* global pointers to qpOASES objects */
46 QProblem* qp = 0;
49 
50 
51 extern "C"
52 {
54  int *nV, int* nC, int* nWSR,
55  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
56  );
57 
58  void init( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
59  int* nV, int* nC, int* nWSR,
60  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
61  );
62  void initSB( real_t* H, real_t* g, real_t* lb, real_t* ub,
63  int* nV, int* nWSR,
64  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
65  );
66  void initVM( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
67  int* nV, int* nC, int* nWSR,
68  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
69  );
70 
71  void hotstart( real_t* g, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
72  int* nWSR,
73  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
74  );
75  void hotstartSB( real_t* g, real_t* lb, real_t* ub,
76  int* nWSR,
77  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
78  );
79  void hotstartVM( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
80  int* nWSR,
81  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
82  );
83 
84  void cleanupp( );
85  void cleanupSB( );
86  void cleanupVM( );
87 }
88 
89 
90 
91 /*
92  * t r a n s f o r m A
93  */
94 void transformA( real_t* A, int nV, int nC )
95 {
96  int i, j;
97 
98  real_t* A_tmp = new real_t[nC*nV];
99 
100  for( i=0; i<nV*nC; ++i )
101  A_tmp[i] = A[i];
102 
103  for( i=0; i<nC; ++i )
104  for( j=0; j<nV; ++j )
105  A[i*nV + j] = A_tmp[j*nC + i];
106 
107  delete[] A_tmp;
108 
109  return;
110 }
111 
112 
113 /*
114  * g e t S t a t u s
115  */
116 int getStatus( returnValue returnvalue )
117 {
118  switch ( returnvalue )
119  {
120  case SUCCESSFUL_RETURN:
121  return 0;
122 
124  return 1;
125 
128  return -2;
129 
132  return -3;
133 
134  default:
135  return -1;
136  }
137 }
138 
139 
140 /*
141  * q p o a s e s
142  */
144  int *nV, int* nC, int* nWSR,
145  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
146  )
147 {
148  /* transform A into C style matrix */
149  transformA( A, *nV,*nC );
150 
151  /* setup and solve initial QP */
152  QProblem single_qp( *nV,*nC );
153  single_qp.setPrintLevel( PL_LOW );
154  returnValue returnvalue = single_qp.init( H,g,A,lb,ub,lbA,ubA, *nWSR,0 );
155 
156  /* assign lhs arguments */
157  single_qp.getPrimalSolution( x );
158  *obj = single_qp.getObjVal( );
159  *status = getStatus( returnvalue );
160  *nWSRout = *nWSR;
161  single_qp.getDualSolution( y );
162 
163  return;
164 }
165 
166 
167 /*
168  * i n i t
169  */
171  int* nV, int* nC, int* nWSR,
172  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
173  )
174 {
175  cleanupp( );
176 
177  /* transform A into C style matrix */
178  transformA( A, *nV,*nC );
179 
180  /* setup and solve initial QP */
181  qp = new QProblem( *nV,*nC );
182  qp->setPrintLevel( PL_LOW );
183  returnValue returnvalue = qp->init( H,g,A,lb,ub,lbA,ubA, *nWSR,0 );
184 
185  /* assign lhs arguments */
186  qp->getPrimalSolution( x );
187  *obj = qp->getObjVal( );
188  *status = getStatus( returnvalue );
189  *nWSRout = *nWSR;
190  qp->getDualSolution( y );
191 
192  return;
193 }
194 
195 
196 /*
197  * i n i t S B
198  */
200  int* nV, int* nWSR,
201  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
202  )
203 {
204  cleanupSB( );
205 
206  /* setup and solve initial QP */
207  qpb = new QProblemB( *nV );
208  qpb->setPrintLevel( PL_LOW );
209  returnValue returnvalue = qpb->init( H,g,lb,ub, *nWSR,0 );
210 
211  /* assign lhs arguments */
212  qpb->getPrimalSolution( x );
213  *obj = qpb->getObjVal( );
214  *status = getStatus( returnvalue );
215  *nWSRout = *nWSR;
216  qpb->getDualSolution( y );
217 
218  return;
219 }
220 
221 
222 /*
223  * i n i t V M
224  */
226  int* nV, int* nC, int* nWSR,
227  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
228  )
229 {
230  cleanupVM( );
231 
232  /* transform A into C style matrix */
233  transformA( A, *nV,*nC );
234 
235  /* setup and solve initial QP */
236  sqp = new SQProblem( *nV,*nC );
237  sqp->setPrintLevel( PL_LOW );
238  returnValue returnvalue = sqp->init( H,g,A,lb,ub,lbA,ubA, *nWSR,0 );
239 
240  /* assign lhs arguments */
241  sqp->getPrimalSolution( x );
242  *obj = sqp->getObjVal( );
243  *status = getStatus( returnvalue );
244  *nWSRout = *nWSR;
245  sqp->getDualSolution( y );
246 
247  return;
248 }
249 
250 
251 /*
252  * h o t s t a r t
253  */
255  int* nWSR,
256  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
257  )
258 {
259  /* has QP been initialised? */
260  if ( qp == 0 )
261  {
262  *status = -1;
263  return;
264  }
265 
266  /* solve QP */
267  returnValue returnvalue = qp->hotstart( g,lb,ub,lbA,ubA, *nWSR,0 );
268 
269  /* assign lhs arguments */
270  qp->getPrimalSolution( x );
271  *obj = qp->getObjVal( );
272  *status = getStatus( returnvalue );
273  *nWSRout = *nWSR;
274  qp->getDualSolution( y );
275 
276  return;
277 }
278 
279 
280 /*
281  * h o t s t a r t S B
282  */
284  int* nWSR,
285  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
286  )
287 {
288  /* has QP been initialised? */
289  if ( qpb == 0 )
290  {
291  *status = -1;
292  return;
293  }
294 
295  /* solve QP */
296  returnValue returnvalue = qpb->hotstart( g,lb,ub, *nWSR,0 );
297 
298  /* assign lhs arguments */
299  qpb->getPrimalSolution( x );
300  *obj = qpb->getObjVal( );
301  *status = getStatus( returnvalue );
302  *nWSRout = *nWSR;
303  qpb->getDualSolution( y );
304 
305  return;
306 }
307 
308 
309 /*
310  * h o t s t a r t V M
311  */
313  int* nWSR,
314  real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
315  )
316 {
317  /* has QP been initialised? */
318  if ( sqp == 0 )
319  {
320  *status = -1;
321  return;
322  }
323 
324  /* transform A into C style matrix */
325  transformA( A, sqp->getNV( ),sqp->getNC( ) );
326 
327  /* solve QP */
328  returnValue returnvalue = sqp->hotstart( H,g,A,lb,ub,lbA,ubA, *nWSR,0 );
329 
330  /* assign lhs arguments */
331  sqp->getPrimalSolution( x );
332  *obj = sqp->getObjVal( );
333  *status = getStatus( returnvalue );
334  *nWSRout = *nWSR;
335  sqp->getDualSolution( y );
336 
337  return;
338 }
339 
340 
341 /*
342  * c l e a n u p p
343  */
344 void cleanupp( )
345 {
346  /* Remark: A function cleanup already exists! */
347  if ( qp != 0 )
348  {
349  delete qp;
350  qp = 0;
351  }
352 
353  return;
354 }
355 
356 
357 /*
358  * c l e a n u p S B
359  */
360 void cleanupSB( )
361 {
362  if ( qpb != 0 )
363  {
364  delete qpb;
365  qpb = 0;
366  }
367 
368  return;
369 }
370 
371 
372 /*
373  * c l e a n u p V M
374  */
375 void cleanupVM( )
376 {
377  if ( sqp != 0 )
378  {
379  delete sqp;
380  sqp = 0;
381  }
382 
383  return;
384 }
385 
386 
387 /*
388  * end of file
389  */
returnValue init(const real_t *const _H, const real_t *const _g, const real_t *const _A, const real_t *const _lb, const real_t *const _ub, const real_t *const _lbA, const real_t *const _ubA, int &nWSR, const real_t *const yOpt=0, real_t *const cputime=0)
void initSB(real_t *H, real_t *g, real_t *lb, real_t *ub, int *nV, int *nWSR, real_t *x, real_t *obj, int *status, int *nWSRout, real_t *y)
void hotstart(real_t *g, real_t *lb, real_t *ub, real_t *lbA, real_t *ubA, int *nWSR, real_t *x, real_t *obj, int *status, int *nWSRout, real_t *y)
Implements the online active set strategy for box-constrained QPs.
Implements the online active set strategy for QPs with varying matrices.
Allows to pass back messages to the calling function.
void hotstartVM(real_t *H, real_t *g, real_t *A, real_t *lb, real_t *ub, real_t *lbA, real_t *ubA, int *nWSR, real_t *x, real_t *obj, int *status, int *nWSRout, real_t *y)
void init(real_t *H, real_t *g, real_t *A, real_t *lb, real_t *ub, real_t *lbA, real_t *ubA, int *nV, int *nC, int *nWSR, real_t *x, real_t *obj, int *status, int *nWSRout, real_t *y)
int getNV() const
returnValue init(const real_t *const _H, const real_t *const _g, const real_t *const _lb, const real_t *const _ub, int &nWSR, const real_t *const yOpt=0, real_t *const cputime=0)
returnValue hotstart(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new, const real_t *const lbA_new, const real_t *const ubA_new, int &nWSR, real_t *const cputime)
int getStatus(returnValue returnvalue)
void transformA(real_t *A, int nV, int nC)
returnValue hotstart(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new, int &nWSR, real_t *const cputime)
void initVM(real_t *H, real_t *g, real_t *A, real_t *lb, real_t *ub, real_t *lbA, real_t *ubA, int *nV, int *nC, int *nWSR, real_t *x, real_t *obj, int *status, int *nWSRout, real_t *y)
void hotstartSB(real_t *g, real_t *lb, real_t *ub, int *nWSR, real_t *x, real_t *obj, int *status, int *nWSRout, real_t *y)
#define PL_LOW
int getNC() const
void qpoases(real_t *H, real_t *g, real_t *A, real_t *lb, real_t *ub, real_t *lbA, real_t *ubA, int *nV, int *nC, int *nWSR, real_t *x, real_t *obj, int *status, int *nWSRout, real_t *y)
double real_t
Definition: AD_test.c:10
Implements the online active set strategy for QPs with general constraints.
returnValue hotstart(const real_t *const H_new, const real_t *const g_new, const real_t *const A_new, const real_t *const lb_new, const real_t *const ub_new, const real_t *const lbA_new, const real_t *const ubA_new, int &nWSR, real_t *const cputime)


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