Exemple #1
0
/* programme principal */
int main()
{
	int i;

	srand(0);
/*	srand(4); */

	init_damier();			/* tirage des bombes et comptage des cases */
	display_damier();
	init_jeu();				/* initialisation table recherche 1 */
	i=select_depart();		/* on triche un peu en prenant pour case
							    de d‚part une case contenant un 0 */

	joue_case(i);

	algo1();
	if (modifie !=0) display_jeu();

	for(;;)
	{
		modifie = 0;
		algo2();
		if (modifie == 0) break;
		display_jeu();
		algo1();
		if (modifie == 0) break;
		display_jeu();
	}

	printf("fini...\n");
	getchar();
	return 0;
}
Exemple #2
0
int main( ){

    USING_NAMESPACE_ACADO

    TIME autotime;
    DifferentialState x(2);
    AlgebraicState z;
    Control u;
    DifferentialEquation f1;
    IntermediateState setc_is_1(5);
    setc_is_1(0) = autotime;
    setc_is_1(1) = x(0);
    setc_is_1(2) = x(1);
    setc_is_1(3) = z;
    setc_is_1(4) = u;


    CFunction cLinkModel_1( 3, myAcadoDifferentialEquation1 );
    f1 << cLinkModel_1(setc_is_1);


    double dconstant1 = 0.0;
    double dconstant2 = 5.0;
    int dconstant3 = 10;
    OCP ocp1(dconstant1, dconstant2, dconstant3);
    ocp1.minimizeMayerTerm(x(1));
    ocp1.subjectTo(f1);
    ocp1.subjectTo(AT_START, x(0) == 1.0 );
    ocp1.subjectTo(AT_START, x(1) == 0.0 );


    GnuplotWindow window;
        window.addSubplot(x(0),"DIFFERENTIAL STATE  x");
        window.addSubplot(z,"ALGEBRAIC STATE  z"   );
        window.addSubplot(u,"CONTROL u"            );


    OptimizationAlgorithm algo1(ocp1);
    algo1.set( KKT_TOLERANCE, 1.000000E-05 );
    algo1.set( RELAXATION_PARAMETER, 1.500000E+00 );

 // algo1.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
 // 
    algo1 << window;

    algo1.solve();

    return 0;
}
Exemple #3
0
int main()
{
    std::cout << "[moeoSEEA]" << std::endl;

    TestEval eval;
    eoQuadCloneOp < Solution > xover;
    eoUniformMutation < Solution > mutation(0.05);

    eoRealVectorBounds bounds(2, 1.0, 2.0);
    eoRealInitBounded < Solution > init(bounds);
    eoPop < Solution > pop(20, init);
    eoQuadGenOp <Solution> genOp(xover);
    eoSGATransform < Solution > transform(xover, 0.1, mutation, 0.1);
    eoGenContinue <Solution > continuator(20);
    moeoUnboundedArchive < Solution > archive;

    eoPopLoopEval <Solution> loopEval(eval);
    eoPopEvalFunc <Solution>& popEval(loopEval);

    // build SEEA
    moeoSEEA < Solution > algo1(20, eval, xover, 1.0, mutation, 1.0, archive);
    moeoSEEA < Solution > algo2(continuator, eval, genOp, archive);
    moeoSEEA < Solution > algo3(continuator, popEval, genOp, archive);
    moeoSEEA < Solution > algo4(continuator, eval, transform, archive);
    moeoSEEA < Solution > algo5(continuator, popEval, transform, archive);

    // run the algo
    algo5(pop);

    // final archive
    std::cout << "Final archive" << std::endl;
    std::cout << archive << std::endl;

    std::cout << "[moeoSEEA] OK" << std::endl;
    return EXIT_SUCCESS;
}
Exemple #4
0
Fichier : test.cpp Projet : rtkg/OC
USING_NAMESPACE_ACADO

#include <mex.h>


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{

    MatlabConsoleStreamBuf mybuf;
    RedirectStream redirect(std::cout, mybuf);
    clearAllStaticCounters( );

    mexPrintf("\nACADO Toolkit for Matlab - Developed by David Ariens and Rien Quirynen, 2009-2013 \n");
    mexPrintf("Support available at http://www.acadotoolkit.org/matlab \n \n");

    if (nrhs != 0) {
        mexErrMsgTxt("This problem expects 0 right hand side argument(s) since you have defined 0 MexInput(s)");
    }

    TIME autotime;
    DifferentialState x;
    DifferentialState y;
    DifferentialState th;
    DifferentialState L;
    Control v;
    Control w;
    DifferentialEquation acadodata_f1;
    acadodata_f1 << dot(x) == cos(th)*v;
    acadodata_f1 << dot(y) == sin(th)*v;
    acadodata_f1 << dot(th) == w;
    acadodata_f1 << dot(L) == w*w;

    OCP ocp1(0, 10, 20);
    ocp1.minimizeMayerTerm(L);
    ocp1.subjectTo(acadodata_f1);
    ocp1.subjectTo(AT_START, x == (-1.000000E+00));
    ocp1.subjectTo(AT_START, y == (-1.000000E+00));
    ocp1.subjectTo(AT_START, th == 0.000000E+00);
    ocp1.subjectTo(AT_END, x == 0.000000E+00);
    ocp1.subjectTo(AT_END, y == 0.000000E+00);


    OptimizationAlgorithm algo1(ocp1);
    returnValue returnvalue = algo1.solve();

    VariablesGrid out_states;
    VariablesGrid out_parameters;
    VariablesGrid out_controls;
    VariablesGrid out_disturbances;
    VariablesGrid out_algstates;
    algo1.getDifferentialStates(out_states);
    algo1.getControls(out_controls);
    const char* outputFieldNames[] = {"STATES", "CONTROLS", "PARAMETERS", "DISTURBANCES", "ALGEBRAICSTATES", "CONVERGENCE_ACHIEVED"};
    plhs[0] = mxCreateStructMatrix( 1,1,6,outputFieldNames );
    mxArray *OutS = NULL;
    double  *outS = NULL;
    OutS = mxCreateDoubleMatrix( out_states.getNumPoints(),1+out_states.getNumValues(),mxREAL );
    outS = mxGetPr( OutS );
    for( int i=0; i<out_states.getNumPoints(); ++i ) {
        outS[0*out_states.getNumPoints() + i] = out_states.getTime(i);
        for( int j=0; j<out_states.getNumValues(); ++j ) {
            outS[(1+j)*out_states.getNumPoints() + i] = out_states(i, j);
        }
    }

    mxSetField( plhs[0],0,"STATES",OutS );
    mxArray *OutC = NULL;
    double  *outC = NULL;
    OutC = mxCreateDoubleMatrix( out_controls.getNumPoints(),1+out_controls.getNumValues(),mxREAL );
    outC = mxGetPr( OutC );
    for( int i=0; i<out_controls.getNumPoints(); ++i ) {
        outC[0*out_controls.getNumPoints() + i] = out_controls.getTime(i);
        for( int j=0; j<out_controls.getNumValues(); ++j ) {
            outC[(1+j)*out_controls.getNumPoints() + i] = out_controls(i, j);
        }
    }

    mxSetField( plhs[0],0,"CONTROLS",OutC );
    mxArray *OutP = NULL;
    double  *outP = NULL;
    OutP = mxCreateDoubleMatrix( out_parameters.getNumPoints(),1+out_parameters.getNumValues(),mxREAL );
    outP = mxGetPr( OutP );
    for( int i=0; i<out_parameters.getNumPoints(); ++i ) {
        outP[0*out_parameters.getNumPoints() + i] = out_parameters.getTime(i);
        for( int j=0; j<out_parameters.getNumValues(); ++j ) {
            outP[(1+j)*out_parameters.getNumPoints() + i] = out_parameters(i, j);
        }
    }

    mxSetField( plhs[0],0,"PARAMETERS",OutP );
    mxArray *OutW = NULL;
    double  *outW = NULL;
    OutW = mxCreateDoubleMatrix( out_disturbances.getNumPoints(),1+out_disturbances.getNumValues(),mxREAL );
    outW = mxGetPr( OutW );
    for( int i=0; i<out_disturbances.getNumPoints(); ++i ) {
        outW[0*out_disturbances.getNumPoints() + i] = out_disturbances.getTime(i);
        for( int j=0; j<out_disturbances.getNumValues(); ++j ) {
            outW[(1+j)*out_disturbances.getNumPoints() + i] = out_disturbances(i, j);
        }
    }

    mxSetField( plhs[0],0,"DISTURBANCES",OutW );
    mxArray *OutZ = NULL;
    double  *outZ = NULL;
    OutZ = mxCreateDoubleMatrix( out_algstates.getNumPoints(),1+out_algstates.getNumValues(),mxREAL );
    outZ = mxGetPr( OutZ );
    for( int i=0; i<out_algstates.getNumPoints(); ++i ) {
        outZ[0*out_algstates.getNumPoints() + i] = out_algstates.getTime(i);
        for( int j=0; j<out_algstates.getNumValues(); ++j ) {
            outZ[(1+j)*out_algstates.getNumPoints() + i] = out_algstates(i, j);
        }
    }

    mxSetField( plhs[0],0,"ALGEBRAICSTATES",OutZ );
    mxArray *OutConv = NULL;
    if ( returnvalue == SUCCESSFUL_RETURN ) {
        OutConv = mxCreateDoubleScalar( 1 );
    }
    else {
        OutConv = mxCreateDoubleScalar( 0 );
    }
    mxSetField( plhs[0],0,"CONVERGENCE_ACHIEVED",OutConv );


    clearAllStaticCounters( );

}