#ifndef _WIN32
#include "../include/lminmaxgd.h"
#else
#include "..\include\lminmaxgd.h"
using namespace std;
#endif
#include <time.h>




/////////////////////////////////////////////////////////////////////
/* Example : Discrete Event Systems in Dioid Framework : Control Theory
 Laurent Hardouin, Olivier Boutin, Bertrand Cottenceau, Thomas Brunsch, Joerg Raisch
 Springer, DISC Book
This program compute :
1. the optimal control when a reference output is a priori known
2. the optimal input filtering when the reference output is unknown
3. the optimal feedback
*/
#include "..\src\gd.cpp"
#include "..\src\poly.cpp"
#include "..\src\serie.cpp"
#include "..\src\smatrix.cpp"
#include "..\src\tools.cpp"
#define N 100
using namespace std;

int main(void)
{
try{
clock_t start, finish;
srand(time(NULL));
//struct rusage ru;
clock_t duration;
poly p1;
poly p2,p3,p4;
int i;
int n0=_infinity,t0=_infinity;
int n,t;
gd r;
 n0=rand()%(10);
t0=rand()%(10);
for (i=0;i<N;i++)
{   n=n0+rand()%(10);
t=t0+rand()%(10);
  n=rand()%(10000)+n0;
  t=rand()%(10000)+t0;

r.init(n,t);
    p1.add(r);
    n0=n;
    t0=t;
}
 n0=rand()%(10);
t0=rand()%(10);
for (i=0;i<N;i++)
{     n=n0+rand()%(10);
t=t0+rand()%(10);
  n=rand()%(10000)+n0;
  t=rand()%(10000)+t0;

  r.init(n,t);
    p2.add(r);
    n0=n;
    t0=t;
}
p2.add(epsilon);


// Delay for a specified time.
start = clock();

for(i=0;i<1;i++)
{


p3=otimes(p1,p2);


}

finish=clock();
duration = (finish - start) ;
printf( "%f clock for p3\n", (float)duration );
system("pause");
start = clock();

for(i=0;i<1;i++)
{


p4=otimes(p1,p2);


}
finish=clock();
duration = (finish - start) ;
printf( "%f clock for p4\n", (float)duration );
//cout<<"p3"<<p3<<endl;
cout<<"p1"<<p1<<endl;
cout<<"p2"<<p2<<endl;
  cout<<"p3"<<p3<<endl;
cout<<"p4"<<p4<<endl;
if(p3==p4) cout<<"ok"<<i<<" "<<endl;

cout<<"p3.n= "<<p3.getn()<<endl;
cout<<"p4.n= "<<p4.getn()<<endl;
return(0);
 }
  catch(mem_limite l)
 {
	 cout<<"Exception : too many coefficent in polynom "<<l.memoire<<endl;
	 return(1);
 }

 catch(taille_incorrecte obj)
 { // 0 : r non causal
   // 1 : tentative d'accès à un element d'une matrice avec un indice incorrect
   // 2 : matrice de taille incompatible pour oplus, inf, otimes, rfrac, lfrac
   // 3 : etoile de matrice carré uniquement
	 cout<<"Exception  "<<obj.erreur<<endl;
	 return(1);
 }
}
