示例#1
0
int main( ){

    USING_NAMESPACE_ACADO

    // INTRODUCE THE VARIABLES:
    // -------------------------
    Parameter a, b;

    // DEFINE AN OPTIMAL CONTROL PROBLEM:
    // ----------------------------------
    NLP nlp;
    nlp.minimize (          a*a + b*b       );
    nlp.subjectTo(  0.08 <= a               );
    nlp.subjectTo(  0.1  <= a + b + 0.3*a*a );


    // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE NLP:
    // ---------------------------------------------------
    OptimizationAlgorithm algorithm(nlp);
    algorithm.solve();


    // PRINT OPTIMAL SOLUTION:
    // -----------------------
	DVector results;
	algorithm.getParameters( results );
	results.print( "optimal solution" );

    return 0;
}
/* >>> start tutorial code >>> */
int main( ){

    USING_NAMESPACE_ACADO

    // DEFINE VALRIABLES:
    // ---------------------------
    DMatrix                 A(3,3);
    DVector                 b(3)  ;
    DifferentialState      x("", 3, 1);
    Function               f     ;


    // DEFINE THE VECTOR AND MATRIX ENTRIES:
    // -------------------------------------
    A.setZero() ;
    A(0,0) = 1.0;  A(1,1) = 2.0;  A(2,2) = 3.0;
    b(0)   = 1.0;  b(1)   = 1.0;  b(2)   = 1.0;


    // DEFINE A TEST FUNCTION:
    // -----------------------
    f << A*x + b;
    f << ( A*x(0) ).getRow( 1 );
    f << ( A*x(0) ).getCol( 0 );

    // TEST THE FUNCTION f:
    // --------------------
    EvaluationPoint zz(f);

    DVector xx(3);
    xx(0) = 1.0;
    xx(1) = 2.0;
    xx(2) = 3.0;

    zz.setX( xx );

    DVector result = f.evaluate( zz );

    result.print(std::cout, "result");

    return 0;
}
示例#3
0
returnValue SCPmethod::feedbackStep(	const DVector& x0_,
										const DVector& p_
										)
{
  
  #ifdef SIM_DEBUG
  printf("START OF THE FEEDBACK STEP \n");
  
  x0_.print("x0");
  #endif
  
  
	returnValue returnvalue;

	if ( ( status != BS_READY ) && ( status != BS_RUNNING ) )
		return ACADOERROR( RET_INITIALIZE_FIRST );

	clockTotalTime.reset( );
	clockTotalTime.start( );
	
	status = BS_RUNNING;
	hasPerformedStep = BT_FALSE;

	if ( checkForRealTimeMode( x0_,p_ ) != SUCCESSFUL_RETURN )
		return ACADOERROR( RET_NLP_STEP_FAILED );

    int hessianMode;
    get( HESSIAN_APPROXIMATION,hessianMode );

	if ( ( isInRealTimeMode == BT_FALSE ) && ( (HessianApproximationMode)hessianMode == EXACT_HESSIAN ) )
	{
		returnvalue = initializeHessianProjection();
		if( returnvalue != SUCCESSFUL_RETURN )
			return ACADOERROR( returnvalue );
	}

	//bandedCP.objectiveGradient.print();
	//x0_.print("x0");
	
    if ( isInRealTimeMode == BT_TRUE )
	{
		if ( setupRealTimeParameters( x0_,p_ ) != SUCCESSFUL_RETURN )
			return ACADOERROR( RET_NLP_STEP_FAILED );
	}

	int printLevel;
	get( PRINTLEVEL,printLevel );

	if ( (PrintLevel)printLevel >= HIGH ) 
		cout << "--> Solving banded QP ...\n";

// 	iter.print();

	if ( bandedCPsolver->solve( bandedCP ) != SUCCESSFUL_RETURN )
		return ACADOERROR( RET_NLP_STEP_FAILED );

// 	bandedCP.deltaX.print();
	
	if ( (PrintLevel)printLevel >= HIGH ) 
		cout << "<-- Solving banded QP done.\n";

	++numberOfSteps;

	return SUCCESSFUL_RETURN;
}