
#ifndef _WIN32
#include "../include/lminmaxgd.h"
#else
#include "..\include\lminmaxgd.h"

#endif
#include <time.h>
using namespace std;
#include <iostream>
#include <time.h>
#include "..\src\gd.cpp"
#include "..\src\poly.cpp"
#include "..\src\serieodotinprogress.cpp"
#include "..\src\smatrix.cpp"
#include "..\src\tools.cpp"
//#include "ominus.cpp"
//#include "expand.cpp"

double inline min(double a,double b)
{
		if(a>b) return b;
		else return a;
}
/////////////////////////////////////////////////////////////////////
/* Example :  Hardouin L., Cottenceau B., Lagrange S., Le Corronc E.

Performance a&nalysis of linear systems over idempotent semiring with additive inputs
Wodes 2008, Goteborg, Sweden
	*/
/////////////////////////////////////////////////////////////////////

int main()
{

	gd temp_gd,temp_gd1;
	poly temp,SR_tf,poly1,poly2,poly3;
	serie temp_serie,temp_serie2,serie1,serie2,temp_seriecheck;
	smatrix transfunction,temp_matrix;
	int time_length;
	int index;

	int window_length;
//    smatrix A1(6,6),AS1(6,6),B(6,2),C(1,6);
//    smatrix u1(2,1);
poly p1,p2,p3,p4,p5,p6,p7;
int a=0,b=0;
int i=0;
int c=0,d=0,e=0,f=0,g=0,h=0;
gd gd1;
int k=0;
while(k<15)
{ p1=epsilon;
p2=epsilon;
    for (i=0;i<2;i++)
{   a=rand()%10+a;
    b=rand()%10+b;
    gd1.init(a,b);
    p1.add(gd1);

    c=rand()%10+c;
    d=rand()%10+d;
    gd1.init(c,d);
    p2.add(gd1);

}

p3=odot(p1,p2);
p4=fracodotsharp(p3,p1);
p6=fracodotsharp(p3,p2);
p5=odot(p4,p1);
p7=odot(p6,p2);



if(p3==p5 && p3==p7)    cout<<" sharp  seems ok 1 "<<endl;

p3=fracodotsharp(p1,p2);
p6=odot(p3,p2);
p7=fracodotsharp(p6,p2);



if( p3==p7)    cout<<" sharp seems ok 2 "<<endl;
else
    {
        cout<<"p1"<<p1<<endl;
        cout<<"p2"<<p2<<endl;
        cout<<"p3"<<p3<<endl;
        cout<<"p4"<<p4<<endl;
        cout<<"p5"<<p5<<endl;
        cout<<"p6"<<p6<<endl;
        cout<<"p7"<<p7<<endl;

}



p3=odot(p1,p2);
p4=fracodotflat(p3,p1);
p6=fracodotflat(p3,p2);
p5=odot(p4,p1);
p7=odot(p6,p2);


if(p3==p5 && p3==p7)    cout<<" flat  seems ok 1 "<<endl;
else
    {
        cout<<"p1"<<p1<<endl;
        cout<<"p2"<<p2<<endl;
        cout<<"p3"<<p3<<endl;
        cout<<"p4"<<p4<<endl;
        cout<<"p5"<<p5<<endl;
        cout<<"p6"<<p6<<endl;
        cout<<"p7"<<p7<<endl;

}



p3=fracodotflat(p1,p2);
p6=odot(p3,p2);
p7=fracodotflat(p6,p2);



if( p3==p7)    cout<<" flat seems ok 2 "<<endl;
else
    {
        cout<<"p1"<<p1<<endl;
        cout<<"p2"<<p2<<endl;
        cout<<"p3"<<p3<<endl;
        cout<<"p4"<<p4<<endl;
        cout<<"p5"<<p5<<endl;
        cout<<"p6"<<p6<<endl;
        cout<<"p7"<<p7<<endl;

}

cout<<"--------"<< k <<"-------"<<endl;


k++;
}
 k=0;

p1.init(2,6)(6,7);
p2.init(9,13);
serie1.init(p1,p2,temp_gd(1,6));
p3.init(3,0)(4,6);
p4.init(6,9);
 serie2.init(p3,p4,temp_gd(1,3));

 temp_serie=fracodotsharp(serie2,serie1);
 temp_serie2=odot(temp_serie,serie1);
    temp_seriecheck=fracodotsharp(temp_serie2,serie1);
 cout<<"serie1"<<serie1<<endl;
   cout<<"serie2"<<serie2<<endl;
cout<<"fracodot (serie1,serie2)"<<temp_serie<<endl;
cout<<"odot ("<<temp_serie2<<endl;
cout<<"fracodot (serie1,serie2)"<<temp_seriecheck<<endl;
getchar();

srand(time(NULL));
while(k<15)
{ p1=epsilon;
p2=epsilon;
p3=epsilon;
p4=epsilon;
a=b=c=d=e=f=g=h=0;
    for (i=0;i<20;i++)
{   a=rand()%10+a;
    b=rand()%10+b;
    gd1.init(a,b);
    p1.add(gd1);
    p1.simpli();

    c=rand()%10+c;
    d=rand()%10+d;
    gd1.init(c,d);
    p2.add(gd1);
    p2.simpli();

    e=rand()%10+e;
    f=rand()%10+f;
    gd1.init(e,f);
    p3.add(gd1);
    p3.simpli();

    g=rand()%10+g;
    h=rand()%10+h;
    gd1.init(g,h);
    p4.add(gd1);
    p4.simpli();

}


temp_gd.init(rand()%10+1,rand()%10+1);
   serie1.init(p1,p2,temp_gd);
   temp_gd.init(rand()%10+1,rand()%10+1);
   serie2.init(p3,p4,temp_gd);

   temp_serie = odot(serie2,serie1);
   system("cls");
    cout<<"serie1"<<serie1<<endl;
   cout<<"serie2"<<serie2<<endl;
    cout<<"odot (serie1,serie2)"<<temp_serie<<endl;
   getchar();
 //  cout<<"!!!!!!!!!!!!!!temp_serie"<<temp_serie<<endl;

   temp_serie2=fracodotflat(temp_serie,serie1);
   //cout<<"!!!!!!!!!!!!!!!!temp_serie2"<<temp_serie2<<endl;
   //getchar();
   temp_seriecheck=odot(temp_serie2,serie1);
//cout<<"!!!!!!!!!!!!!temp_seriecheck"<<temp_seriecheck<<endl;

    cout<<"fracodot (serie1,serie2)"<<temp_serie2<<endl;
    cout<<"odot (serie2,serie1)"<<temp_seriecheck<<endl;

   if(temp_serie==temp_seriecheck) cout<<"it seems ok for odot and odotsharp k= "<<k<<endl;


    temp_serie = fracodotflat(serie2,serie1);
    temp_serie2=odot(temp_serie,serie1);
    temp_seriecheck=fracodotflat(temp_serie2,serie1);
  if(temp_serie==temp_seriecheck) cout<<"it seems ok for odotsharp and odot k= "<<k<<endl;
getchar();
/*temp_serie = fracodotsharp(serie2,serie1);

   temp_serie2=odot(temp_serie,serie1);

   temp_seriecheck=fracodotsharp(temp_serie2,serie1);
   if(temp_serie==temp_seriecheck) cout<<"it seems ok for odotsharp and odot k="<<k<<endl;
   getchar();
   cout<<"serie1"<<serie1<<endl;
   cout<<"serie2"<<serie2<<endl;
  cout<<"odotsharp (serie2,serie1)"<<temp_serie<<endl;
  */
  k++;
}

}
