/**
 *  Auteur : MACHIZAUD Andréa
 *  TD 01 - Heuristique
 *  Sujet : Gradient à pas fixe
 *  Fonction objectif pour l'optimisation déterministe : x_{k+1} = x_{k} - \ro_{k} \grad ES(x_{k})
 *  Fonction test : ES(x) = x_{1}^{2} + x_{2}^{2} + x_{3}^{2}
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//lib aleatoire
#include <time.h>
#include <conio.h>

#define TAU      0.01
#define OMEGA    0.0001

#define EPSILON  0.000001
#define MAX_ITER 100000

float fonctionInitiale(float x){
    return 2*x;
}

float fonctionInitialeDerivee(){
    return 2;
}

float MethodePenalisation(float x, float epsilon){

    float eps = epsilon;

    float fonction = fonctionInitiale(x);
    float fonctionDerivee = fonctionInitialeDerivee();
    int i = 0;

    float x1 = fonctionDerivee + (1/epsilon)*fonction;

    while(i<MAX_ITER){
        eps = eps/2.0;
        x1 = fonctionDerivee + (1/epsilon)*fonction;
        i++;
    }

    return x1;

}


int main()
{
    int choix = 4;
    //float x0[3] = {3,3,3}, pas;
    float x,epsilon;

    // Init the random seed
    srand (time (NULL));

    printf("\nVecteur initial x : ");
    /*
     * saisir le vecteur en donnant chaque composante séparée par une virgule.
     * e.g : 5.0,3.0,4.0
     */
//    scanf("%f,%f,%f",&x0[0],&x0[1],&x0[2]);
    //printVector3(x0);
    //printf("\nFunction value for x : %f",ES(x0));

    printf("\nChoix de la méthode :");
    printf("\n1 - Gradient à pas fixe");
    printf("\n2 - Gradient à pas optimal");
    printf("\n3 - Benchmark\n");
    printf("\n4 - Pénalisation\n");

//    scanf("%d",&choix);
    printf("%d\n",choix);

    switch(choix)
    {
        case 1 :

            break;
        case 2 :
            break;
        case 3 :
            break;
        case 4 :

            printf("Saisissez votre x à optimiser :\n");
            scanf("%d",&x);

            printf("Saisissez votre epsilon :\n");
            scanf("%d",&epsilon);

            printf("Résultat : %f \n",MethodePenalisation(x,epsilon));
    }

    return EXIT_SUCCESS;
}
