90 const int nc =
getNC();
102 z[0].
setZ( 0, iter );
103 z[1].
setZ( T, iter );
107 for( run1 = 0; run1 < nc; run1++ ){
108 resL( run1, 0 ) =
lb[0][run1] - result(run1);
109 resU( run1, 0 ) =
ub[0][run1] - result(run1);
118 for( run1 = 0; run1 < nc; run1++ ){
119 resL( run1, 0 ) -= result(run1);
120 resU( run1, 0 ) -= result(run1);
168 for( run1 = 0; run1 < nBDirs; run1++ )
172 if(
nx > 0 ) Dx .
setRow( run1,
JJ[0].getX () );
173 if(
na > 0 ) Dxa.
setRow( run1,
JJ[0].getXA() );
174 if(
np > 0 ) Dp .
setRow( run1,
JJ[0].getP () );
175 if(
nu > 0 ) Du .
setRow( run1,
JJ[0].getU () );
176 if(
nw > 0 ) Dw .
setRow( run1,
JJ[0].getW () );
197 for( run1 = 0; run1 < nBDirs; run1++ )
201 if(
nx > 0 ) Dx .
setRow( run1,
JJ[1].getX () );
202 if(
na > 0 ) Dxa.
setRow( run1,
JJ[1].getXA() );
203 if(
np > 0 ) Dp .
setRow( run1,
JJ[1].getP () );
204 if(
nu > 0 ) Du .
setRow( run1,
JJ[1].getU () );
205 if(
nw > 0 ) Dw .
setRow( run1,
JJ[1].getW () );
241 const int nc =
getNC();
246 double *bseed1 =
new double[nc];
247 double *bseed2 =
new double[nc];
248 double *
R =
new double[nc];
251 double *
H1 =
new double[fcn[0].getNumberOfVariables() +1];
252 double *fseed1 =
new double[fcn[0].getNumberOfVariables() +1];
254 double *J2 =
new double[fcn[1].getNumberOfVariables() +1];
255 double *
H2 =
new double[fcn[1].getNumberOfVariables() +1];
256 double *fseed2 =
new double[fcn[1].getNumberOfVariables() +1];
258 for( run1 = 0; run1 < nc; run1++ ){
259 bseed1[run1] = seed(run1,0);
263 for( run1 = 0; run1 < fcn[0].getNumberOfVariables()+1; run1++ )
266 for( run1 = 0; run1 < fcn[1].getNumberOfVariables()+1; run1++ )
283 for( run2 = 0; run2 <
nx; run2++ ){
287 fseed1[
y_index[0][run2]] = 1.0;
288 fcn[0].AD_forward( 0, fseed1, R );
289 for( run1 = 0; run1 < nc; run1++ )
290 Dx( run1, run2 ) = R[run1];
291 fseed1[y_index[0][run2]] = 0.0;
295 for( run1 = 0; run1 <= fcn[0].getNumberOfVariables(); run1++ ){
300 fcn[0].AD_backward2( 0, bseed1, bseed2, J1, H1 );
302 for( run1 = 0 ; run1 <
nx ; run1++ ) Hx ( run2, run1 ) = -H1[y_index[0][run1]];
303 for( run1 = nx ; run1 < nx+
na ; run1++ ) Hxa( run2, run1-nx ) = -H1[y_index[0][run1]];
304 for( run1 = nx+na ; run1 < nx+na+
np ; run1++ ) Hp ( run2, run1-nx-na ) = -H1[y_index[0][run1]];
305 for( run1 = nx+na+np ; run1 < nx+na+np+
nu ; run1++ ) Hu ( run2, run1-nx-na-np ) = -H1[y_index[0][run1]];
306 for( run1 = nx+na+np+nu; run1 < nx+na+np+nu+
nw; run1++ ) Hw ( run2, run1-nx-na-np-nu ) = -H1[y_index[0][run1]];
313 if( nx > 0 ) hessian.
addDense( 0, 0, Hx );
327 for( run2 = 0; run2 <
nx; run2++ ){
331 fseed2[
y_index[1][run2]] = 1.0;
332 fcn[1].AD_forward( 0, fseed2, R );
333 for( run1 = 0; run1 < nc; run1++ )
334 Dx( run1, run2 ) = R[run1];
335 fseed2[y_index[1][run2]] = 0.0;
339 for( run1 = 0; run1 <= fcn[1].getNumberOfVariables(); run1++ ){
344 fcn[1].AD_backward2( 0, bseed1, bseed2, J2, H2 );
346 for( run1 = 0 ; run1 <
nx ; run1++ ) Hx ( run2, run1 ) = -H2[y_index[1][run1]];
347 for( run1 = nx ; run1 < nx+
na ; run1++ ) Hxa( run2, run1-nx ) = -H2[y_index[1][run1]];
348 for( run1 = nx+na ; run1 < nx+na+
np ; run1++ ) Hp ( run2, run1-nx-na ) = -H2[y_index[1][run1]];
349 for( run1 = nx+na+np ; run1 < nx+na+np+
nu ; run1++ ) Hu ( run2, run1-nx-na-np ) = -H2[y_index[1][run1]];
350 for( run1 = nx+na+np+nu; run1 < nx+na+np+nu+
nw; run1++ ) Hw ( run2, run1-nx-na-np-nu ) = -H2[y_index[1][run1]];
357 if( nx > 0 ) hessian.
addDense( N-1, N-1, Hx );
358 if(
na > 0 ) hessian.
addDense( N-1, 2*N-1, Hxa );
359 if(
np > 0 ) hessian.
addDense( N-1, 3*N-1, Hp );
360 if(
nu > 0 ) hessian.
addDense( N-1, 4*N-1, Hu );
361 if(
nw > 0 ) hessian.
addDense( N-1, 5*N-1, Hw );
371 for( run2 = nx; run2 < nx+
na; run2++ ){
375 fseed1[
y_index[0][run2]] = 1.0;
376 fcn[0].AD_forward( 0, fseed1, R );
377 for( run1 = 0; run1 < nc; run1++ )
378 Dxa( run1, run2-nx ) = R[run1];
379 fseed1[y_index[0][run2]] = 0.0;
383 for( run1 = 0; run1 <= fcn[0].getNumberOfVariables(); run1++ ){
388 fcn[0].AD_backward2( 0, bseed1, bseed2, J1, H1 );
390 for( run1 = 0 ; run1 <
nx ; run1++ ) Hx ( run2-nx, run1 ) = -H1[y_index[0][run1]];
391 for( run1 = nx ; run1 < nx+
na ; run1++ ) Hxa( run2-nx, run1-nx ) = -H1[y_index[0][run1]];
392 for( run1 = nx+na ; run1 < nx+na+
np ; run1++ ) Hp ( run2-nx, run1-nx-na ) = -H1[y_index[0][run1]];
393 for( run1 = nx+na+np ; run1 < nx+na+np+
nu ; run1++ ) Hu ( run2-nx, run1-nx-na-np ) = -H1[y_index[0][run1]];
394 for( run1 = nx+na+np+nu; run1 < nx+na+np+nu+
nw; run1++ ) Hw ( run2-nx, run1-nx-na-np-nu ) = -H1[y_index[0][run1]];
401 if( nx > 0 ) hessian.
addDense( N, 0, Hx );
402 if( na > 0 ) hessian.
addDense( N, N, Hxa );
415 for( run2 = nx; run2 < nx+
na; run2++ ){
419 fseed2[
y_index[1][run2]] = 1.0;
420 fcn[1].AD_forward( 0, fseed2, R );
421 for( run1 = 0; run1 < nc; run1++ )
422 Dxa( run1, run2-nx ) = R[run1];
423 fseed2[y_index[1][run2]] = 0.0;
427 for( run1 = 0; run1 <= fcn[1].getNumberOfVariables(); run1++ ){
432 fcn[1].AD_backward2( 0, bseed1, bseed2, J2, H2 );
434 for( run1 = 0 ; run1 <
nx ; run1++ ) Hx ( run2-nx, run1 ) = -H2[y_index[1][run1]];
435 for( run1 = nx ; run1 < nx+
na ; run1++ ) Hxa( run2-nx, run1-nx ) = -H2[y_index[1][run1]];
436 for( run1 = nx+na ; run1 < nx+na+
np ; run1++ ) Hp ( run2-nx, run1-nx-na ) = -H2[y_index[1][run1]];
437 for( run1 = nx+na+np ; run1 < nx+na+np+
nu ; run1++ ) Hu ( run2-nx, run1-nx-na-np ) = -H2[y_index[1][run1]];
438 for( run1 = nx+na+np+nu; run1 < nx+na+np+nu+
nw; run1++ ) Hw ( run2-nx, run1-nx-na-np-nu ) = -H2[y_index[1][run1]];
445 if( nx > 0 ) hessian.
addDense( 2*N-1, N-1, Hx );
446 if( na > 0 ) hessian.
addDense( 2*N-1, 2*N-1, Hxa );
447 if(
np > 0 ) hessian.
addDense( 2*N-1, 3*N-1, Hp );
448 if(
nu > 0 ) hessian.
addDense( 2*N-1, 4*N-1, Hu );
449 if(
nw > 0 ) hessian.
addDense( 2*N-1, 5*N-1, Hw );
459 for( run2 = nx+na; run2 < nx+na+
np; run2++ ){
463 fseed1[
y_index[0][run2]] = 1.0;
464 fcn[0].AD_forward( 0, fseed1, R );
465 for( run1 = 0; run1 < nc; run1++ )
466 Dp( run1, run2-nx-na ) = R[run1];
467 fseed1[y_index[0][run2]] = 0.0;
471 for( run1 = 0; run1 <= fcn[0].getNumberOfVariables(); run1++ ){
476 fcn[0].AD_backward2( 0, bseed1, bseed2, J1, H1 );
478 for( run1 = 0 ; run1 <
nx ; run1++ ) Hx ( run2-nx-na, run1 ) = -H1[y_index[0][run1]];
479 for( run1 = nx ; run1 < nx+
na ; run1++ ) Hxa( run2-nx-na, run1-nx ) = -H1[y_index[0][run1]];
480 for( run1 = nx+na ; run1 < nx+na+
np ; run1++ ) Hp ( run2-nx-na, run1-nx-na ) = -H1[y_index[0][run1]];
481 for( run1 = nx+na+np ; run1 < nx+na+np+
nu ; run1++ ) Hu ( run2-nx-na, run1-nx-na-np ) = -H1[y_index[0][run1]];
482 for( run1 = nx+na+np+nu; run1 < nx+na+np+nu+
nw; run1++ ) Hw ( run2-nx-na, run1-nx-na-np-nu ) = -H1[y_index[0][run1]];
489 if( nx > 0 ) hessian.
addDense( 2*N, 0, Hx );
490 if( na > 0 ) hessian.
addDense( 2*N, N, Hxa );
491 if( np > 0 ) hessian.
addDense( 2*N, 2*N, Hp );
492 if(
nu > 0 ) hessian.
addDense( 2*N, 3*N, Hu );
493 if(
nw > 0 ) hessian.
addDense( 2*N, 4*N, Hw );
504 for( run2 = nx+na; run2 < nx+na+
np; run2++ ){
508 fseed2[
y_index[1][run2]] = 1.0;
509 fcn[1].AD_forward( 0, fseed2, R );
510 for( run1 = 0; run1 < nc; run1++ )
511 Dp( run1, run2-nx-na ) = R[run1];
512 fseed2[y_index[1][run2]] = 0.0;
516 for( run1 = 0; run1 <= fcn[1].getNumberOfVariables(); run1++ ){
521 fcn[1].AD_backward2( 0, bseed1, bseed2, J2, H2 );
523 for( run1 = 0 ; run1 <
nx ; run1++ ) Hx ( run2-nx-na, run1 ) = -H2[y_index[1][run1]];
524 for( run1 = nx ; run1 < nx+
na ; run1++ ) Hxa( run2-nx-na, run1-nx ) = -H2[y_index[1][run1]];
525 for( run1 = nx+na ; run1 < nx+na+
np ; run1++ ) Hp ( run2-nx-na, run1-nx-na ) = -H2[y_index[1][run1]];
526 for( run1 = nx+na+np ; run1 < nx+na+np+
nu ; run1++ ) Hu ( run2-nx-na, run1-nx-na-np ) = -H2[y_index[1][run1]];
527 for( run1 = nx+na+np+nu; run1 < nx+na+np+nu+
nw; run1++ ) Hw ( run2-nx-na, run1-nx-na-np-nu ) = -H2[y_index[1][run1]];
534 if( nx > 0 ) hessian.
addDense( 3*N-1, N-1, Hx );
535 if( na > 0 ) hessian.
addDense( 3*N-1, 2*N-1, Hxa );
536 if( np > 0 ) hessian.
addDense( 3*N-1, 3*N-1, Hp );
537 if(
nu > 0 ) hessian.
addDense( 3*N-1, 4*N-1, Hu );
538 if(
nw > 0 ) hessian.
addDense( 3*N-1, 5*N-1, Hw );
549 for( run2 = nx+na+np; run2 < nx+na+np+
nu; run2++ ){
553 fseed1[
y_index[0][run2]] = 1.0;
554 fcn[0].AD_forward( 0, fseed1, R );
555 for( run1 = 0; run1 < nc; run1++ )
556 Du( run1, run2-nx-na-np ) = R[run1];
557 fseed1[y_index[0][run2]] = 0.0;
561 for( run1 = 0; run1 <= fcn[0].getNumberOfVariables(); run1++ ){
566 fcn[0].AD_backward2( 0, bseed1, bseed2, J1, H1 );
568 for( run1 = 0 ; run1 <
nx ; run1++ ) Hx ( run2-nx-na-np, run1 ) = -H1[y_index[0][run1]];
569 for( run1 = nx ; run1 < nx+
na ; run1++ ) Hxa( run2-nx-na-np, run1-nx ) = -H1[y_index[0][run1]];
570 for( run1 = nx+na ; run1 < nx+na+
np ; run1++ ) Hp ( run2-nx-na-np, run1-nx-na ) = -H1[y_index[0][run1]];
571 for( run1 = nx+na+np ; run1 < nx+na+np+
nu ; run1++ ) Hu ( run2-nx-na-np, run1-nx-na-np ) = -H1[y_index[0][run1]];
572 for( run1 = nx+na+np+nu; run1 < nx+na+np+nu+
nw; run1++ ) Hw ( run2-nx-na-np, run1-nx-na-np-nu ) = -H1[y_index[0][run1]];
579 if( nx > 0 ) hessian.
addDense( 3*N, 0, Hx );
580 if( na > 0 ) hessian.
addDense( 3*N, N, Hxa );
581 if( np > 0 ) hessian.
addDense( 3*N, 2*N, Hp );
582 if( nu > 0 ) hessian.
addDense( 3*N, 3*N, Hu );
583 if(
nw > 0 ) hessian.
addDense( 3*N, 4*N, Hw );
593 for( run2 = nx+na+np; run2 < nx+na+np+
nu; run2++ ){
597 fseed2[
y_index[1][run2]] = 1.0;
598 fcn[1].AD_forward( 0, fseed2, R );
599 for( run1 = 0; run1 < nc; run1++ )
600 Du( run1, run2-nx-na-np ) = R[run1];
601 fseed2[y_index[1][run2]] = 0.0;
605 for( run1 = 0; run1 <= fcn[1].getNumberOfVariables(); run1++ ){
610 fcn[1].AD_backward2( 0, bseed1, bseed2, J2, H2 );
612 for( run1 = 0 ; run1 <
nx ; run1++ ) Hx ( run2-nx-na-np, run1 ) = -H2[y_index[1][run1]];
613 for( run1 = nx ; run1 < nx+
na ; run1++ ) Hxa( run2-nx-na-np, run1-nx ) = -H2[y_index[1][run1]];
614 for( run1 = nx+na ; run1 < nx+na+
np ; run1++ ) Hp ( run2-nx-na-np, run1-nx-na ) = -H2[y_index[1][run1]];
615 for( run1 = nx+na+np ; run1 < nx+na+np+
nu ; run1++ ) Hu ( run2-nx-na-np, run1-nx-na-np ) = -H2[y_index[1][run1]];
616 for( run1 = nx+na+np+nu; run1 < nx+na+np+nu+
nw; run1++ ) Hw ( run2-nx-na-np, run1-nx-na-np-nu ) = -H2[y_index[1][run1]];
623 if( nx > 0 ) hessian.
addDense( 4*N-1, N-1, Hx );
624 if( na > 0 ) hessian.
addDense( 4*N-1, 2*N-1, Hxa );
625 if( np > 0 ) hessian.
addDense( 4*N-1, 3*N-1, Hp );
626 if( nu > 0 ) hessian.
addDense( 4*N-1, 4*N-1, Hu );
627 if(
nw > 0 ) hessian.
addDense( 4*N-1, 5*N-1, Hw );
637 for( run2 = nx+na+np+nu; run2 < nx+na+np+nu+
nw; run2++ ){
641 fseed1[
y_index[0][run2]] = 1.0;
642 fcn[0].AD_forward( 0, fseed1, R );
643 for( run1 = 0; run1 < nc; run1++ )
644 Dw( run1, run2-nx-na-np-nu ) = R[run1];
645 fseed1[y_index[0][run2]] = 0.0;
649 for( run1 = 0; run1 <= fcn[0].getNumberOfVariables(); run1++ ){
654 fcn[0].AD_backward2( 0, bseed1, bseed2, J1, H1 );
656 for( run1 = 0 ; run1 <
nx ; run1++ ) Hx ( run2-nx-na-np-nu, run1 ) = -H1[y_index[0][run1]];
657 for( run1 = nx ; run1 < nx+
na ; run1++ ) Hxa( run2-nx-na-np-nu, run1-nx ) = -H1[y_index[0][run1]];
658 for( run1 = nx+na ; run1 < nx+na+
np ; run1++ ) Hp ( run2-nx-na-np-nu, run1-nx-na ) = -H1[y_index[0][run1]];
659 for( run1 = nx+na+np ; run1 < nx+na+np+
nu ; run1++ ) Hu ( run2-nx-na-np-nu, run1-nx-na-np ) = -H1[y_index[0][run1]];
660 for( run1 = nx+na+np+nu; run1 < nx+na+np+nu+
nw; run1++ ) Hw ( run2-nx-na-np-nu, run1-nx-na-np-nu ) = -H1[y_index[0][run1]];
667 if( nx > 0 ) hessian.
addDense( 4*N, 0, Hx );
668 if( na > 0 ) hessian.
addDense( 4*N, N, Hxa );
669 if( np > 0 ) hessian.
addDense( 4*N, 2*N, Hp );
670 if( nu > 0 ) hessian.
addDense( 4*N, 3*N, Hu );
671 if( nw > 0 ) hessian.
addDense( 4*N, 4*N, Hw );
681 for( run2 = nx+na+np+nu; run2 < nx+na+np+nu+
nw; run2++ ){
685 fseed2[
y_index[1][run2]] = 1.0;
686 fcn[1].AD_forward( 0, fseed2, R );
687 for( run1 = 0; run1 < nc; run1++ )
688 Dw( run1, run2-nx-na-np-nu ) = R[run1];
689 fseed2[y_index[1][run2]] = 0.0;
693 for( run1 = 0; run1 <= fcn[1].getNumberOfVariables(); run1++ ){
698 fcn[1].AD_backward2( 0, bseed1, bseed2, J2, H2 );
700 for( run1 = 0 ; run1 <
nx ; run1++ ) Hx ( run2-nx-na-np-nu, run1 ) = -H2[y_index[1][run1]];
701 for( run1 = nx ; run1 < nx+
na ; run1++ ) Hxa( run2-nx-na-np-nu, run1-nx ) = -H2[y_index[1][run1]];
702 for( run1 = nx+na ; run1 < nx+na+
np ; run1++ ) Hp ( run2-nx-na-np-nu, run1-nx-na ) = -H2[y_index[1][run1]];
703 for( run1 = nx+na+np ; run1 < nx+na+np+
nu ; run1++ ) Hu ( run2-nx-na-np-nu, run1-nx-na-np ) = -H2[y_index[1][run1]];
704 for( run1 = nx+na+np+nu; run1 < nx+na+np+nu+
nw; run1++ ) Hw ( run2-nx-na-np-nu, run1-nx-na-np-nu ) = -H2[y_index[1][run1]];
711 if( nx > 0 ) hessian.
addDense( 5*N-1, N-1, Hx );
712 if( na > 0 ) hessian.
addDense( 5*N-1, 2*N-1, Hxa );
713 if( np > 0 ) hessian.
addDense( 5*N-1, 3*N-1, Hp );
714 if( nu > 0 ) hessian.
addDense( 5*N-1, 4*N-1, Hu );
715 if( nw > 0 ) hessian.
addDense( 5*N-1, 5*N-1, Hw );
Data class for storing generic optimization variables.
Implements a very rudimentary block sparse matrix class.
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
ConstraintElement & operator=(const ConstraintElement &rhs)
void init(unsigned _nRows=0, unsigned _nCols=0)
returnValue setDense(uint rowIdx, uint colIdx, const DMatrix &value)
Allows to pass back messages to the calling function.
DVector evaluate(const EvaluationPoint &x, const int &number=0)
returnValue setZ(const uint &idx, const OCPiterate &iter)
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Stores and evaluates boundary constraints within optimal control problems.
uint getLastIndex() const
#define CLOSE_NAMESPACE_ACADO
returnValue evaluate(const OCPiterate &iter)
returnValue getSubBlock(uint rowIdx, uint colIdx, DMatrix &value) const
BoundaryConstraint & operator=(const BoundaryConstraint &rhs)
Base class for all kind of constraints (except for bounds) within optimal control problems...
returnValue init(uint _nRows, uint _nCols)
GenericMatrix & setRow(unsigned _idx, const GenericVector< T > &_values)
virtual ~BoundaryConstraint()
void rhs(const real_t *x, real_t *f)
unsigned getNumRows() const
uint getNumPoints() const
returnValue evaluateSensitivities()
#define BEGIN_NAMESPACE_ACADO
returnValue addDense(uint rowIdx, uint colIdx, const DMatrix &value)
int getNumberOfVariables() const
GenericVector< T > getRow(unsigned _idx) const
#define ACADOERROR(retval)