returnValue FunctionEvaluationTree::C_print( 	FILE       *file     ,
												const char *fcnName  ,
												const char *realString,
												int         precision
												) const{

    acadoFPrintf(file,"/*\n");
    acadoFPrintf(file," *    This file was auto-generated by ACADO Toolkit.\n");
    acadoFPrintf(file," *\n");
    acadoFPrintf(file," *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.\n");
    acadoFPrintf(file," *    Copyright (C) 2008-2011 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven.\n");
    acadoFPrintf(file," *    Developed within the Optimization in Engineering Center (OPTEC) under\n");
    acadoFPrintf(file," *    supervision of Moritz Diehl. All rights reserved.\n");
    acadoFPrintf(file," *\n");
    acadoFPrintf(file," */\n");

    exportHeader             ( file,fcnName,realString );
    exportForwardDeclarations( file,fcnName,realString );
    exportCode               ( file,fcnName,realString,precision );

    return SUCCESSFUL_RETURN;
}
Beispiel #2
0
returnValue SIMexport::exportAndRun(	const String& dirName,
							const String& initStates,
							const String& controls,
							const String& results,
							const String& ref
										)
{
	set( GENERATE_TEST_FILE, 1 );

	Grid integrationGrid;
	modelData.getIntegrationGrid(integrationGrid);
	std::vector<Grid> outputGrids;
	modelData.getOutputGrids(outputGrids);

	int measGrid;
	get( MEASUREMENT_GRID, measGrid );
	if( (MeasurementGrid)measGrid == ONLINE_GRID || ((MeasurementGrid)measGrid == EQUIDISTANT_SUBGRID && !modelData.hasEquidistantIntegrationGrid()) ) return ACADOERROR( RET_INVALID_OPTION );

	_initStates = initStates;
	_controls = controls;
	_results = results;
	_ref = ref;
	uint i, j;
	Vector meas( (uint)outputGrids.size() );
	Vector measRef( (uint)outputGrids.size() );
	for( i = 0; i < outputGrids.size(); i++ ) {
		meas(i) = (double)outputGrids[i].getNumIntervals();
		measRef(i) = (double)outputGrids[i].getNumIntervals()*factorRef;
	}
	
	Vector intGrid( integrationGrid.getNumIntervals()+1 );
	Vector refIntGrid( factorRef*integrationGrid.getNumIntervals()+1 );
	if( !modelData.hasEquidistantIntegrationGrid() ) {
		intGrid(0) = integrationGrid.getTime( 0 );
		refIntGrid(0) = integrationGrid.getTime( 0 );
		for( i = 0; i < integrationGrid.getNumIntervals(); i++ ) {
			intGrid(i+1) = integrationGrid.getTime( i+1 );
			double step = (integrationGrid.getTime( i+1 ) - integrationGrid.getTime( i ))/factorRef;
			for( j = 0; j < factorRef; j++ ) {
				refIntGrid(i*factorRef+1+j) = refIntGrid(i*factorRef+j) + step;
			}
		}
	}

	int numSteps;
    get( NUM_INTEGRATOR_STEPS, numSteps );
	timingCalls = (uint) ceil((double)(timingSteps*modelData.getN())/((double) numSteps) - 10.0*EPS);
	timingSteps = (uint) ceil((double)timingCalls*((double) numSteps/((double) modelData.getN())) - 10.0*EPS);
    
    if( !referenceProvided ) {
	    // REFERENCE:
    	if( !modelData.hasEquidistantIntegrationGrid() ) {
    		modelData.setMeasurements( meas );			// EQUIDISTANT_GRID option is used
    		modelData.setIntegrationGrid( refIntGrid );
    		exportCode(	dirName );
    		exportTest(	dirName, String( "test.c" ), _ref, _refOutputFiles, BT_FALSE, 1 );
    	}
    	else if( (MeasurementGrid)measGrid == EQUIDISTANT_GRID ) {
    		modelData.setMeasurements( meas );
    		set( NUM_INTEGRATOR_STEPS,  (int)factorRef*numSteps );
    		exportCode(	dirName );
    		exportTest(	dirName, String( "test.c" ), _ref, _refOutputFiles, BT_FALSE, 1 );
    	}
    	else {
    		modelData.setMeasurements( measRef );
    		set( NUM_INTEGRATOR_STEPS,  (int)factorRef*numSteps );
    		exportCode(	dirName );
    		exportTest(	dirName, String( "test.c" ), _ref, _refOutputFiles, BT_FALSE, factorRef );
    	}
		executeTest( dirName );
	}
    modelData.clearIntegrationGrid();
    
    // THE INTEGRATOR:
    modelData.setMeasurements( meas );
	set( NUM_INTEGRATOR_STEPS,  numSteps );
	if( !modelData.hasEquidistantIntegrationGrid() ) {
		modelData.setIntegrationGrid( intGrid );
	}
	exportCode(	dirName );
	if(timingSteps > 0 && timingCalls > 0) 	exportTest(	dirName, String( "test.c" ), _results, _outputFiles, BT_TRUE, 1 );
	else 									exportTest(	dirName, String( "test.c" ), _results, _outputFiles, BT_FALSE, 1 );
	executeTest( dirName );

	// THE EVALUATION:
	int nil;
	nil = system( (String(dirName) << "/./compare").getName() );
	
	return SUCCESSFUL_RETURN;
}