/* 
 * File:   main.cpp
 * Author: lubajz
 *
 * Created on 12. prosinec 2009, 12:28
 */

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

/*#include <unistd.h> //pridano
#include <sys/wait.h>
#include <spawn.h>*/
#include <unistd.h>

#include "GAMSInOut.h"
#include "Exceptions.h"

/*
 * 
 */
int main(int argc, char** argv) {
    //int nVariables = 2;

    try {
        SCENARIOS S("datafarming.txt", 3, 6);

        S.averageSolution1->data[0] = 134;
        S.averageSolution1->data[1] = 57;
        S.averageSolution1->data[2] = 308;

        S.averageSolution2[0]->data[0] = 350;
        S.averageSolution2[0]->data[4] = 6000;

        S.averageSolution2[1]->data[0] = 100;
        S.averageSolution2[1]->data[4] = 6000;

        S.averageSolution2[2]->data[3] = 180;
        S.averageSolution2[2]->data[4] = 6000;
/*
        S.scenarios[0]->solution1->data[0] = 183.33;
        S.scenarios[0]->solution1->data[1] = 66.66;
        S.scenarios[0]->solution1->data[2] = 250;
        S.scenarios[0]->solution2->data[0] = 350;
        S.scenarios[0]->solution2->data[1] = 0;
        S.scenarios[0]->solution2->data[2] = 0;
        S.scenarios[0]->solution2->data[3] = 0;
        S.scenarios[0]->solution2->data[4] = 6000;
        S.scenarios[0]->solution2->data[5] = 0;

        S.scenarios[1]->solution1->data[0] = 120;
        S.scenarios[1]->solution1->data[1] = 80;
        S.scenarios[1]->solution1->data[2] = 300;
        S.scenarios[1]->solution2->data[0] = 100;
        S.scenarios[1]->solution2->data[1] = 0;
        S.scenarios[1]->solution2->data[2] = 0;
        S.scenarios[1]->solution2->data[3] = 0;
        S.scenarios[1]->solution2->data[4] = 6000;
        S.scenarios[1]->solution2->data[5] = 0;

        S.scenarios[2]->solution1->data[0] = 100;
        S.scenarios[2]->solution1->data[1] = 25;
        S.scenarios[2]->solution1->data[2] = 375;
        S.scenarios[2]->solution2->data[0] = 0;
        S.scenarios[2]->solution2->data[1] = 0;
        S.scenarios[2]->solution2->data[2] = 0;
        S.scenarios[2]->solution2->data[3] = 180;
        S.scenarios[2]->solution2->data[4] = 6000;
        S.scenarios[2]->solution2->data[5] = 0;

*/
        S.printAllScenarios();
        S.checkIntegrity(1e-7);
        PHA P(&S, "farming.gms", 1e-9, 0.25);  //  eps, rho
        P.runPHA(1, 1);  //  rho *= A, sleep






 /*       S.scenarios[0]->weights->data[0] = 1.11;
        S.averageSolution->data[1] = 2.055;
        S.printAllScenarios();
        S.checkIntegrity(1e-7);
        S.makeGAMSSourceFiles("nutricniproblem.gms");

// pokusy se spoustenim a cekanim

        //printf("run mpi\n");
        //getchar();
        //system("gnome-terminal --execute mpirun -np 5 parallelGAMSrun");

        //sleep(5);


       
   //     printf("zastaveno");
  //      getchar();

// konec pokusu
     

        MATRIX m(3, 3);
        VECTOR v(2);
        SCALAR s(0);

        S.readMatrixDataFromLSTFile("scenario1.lst", "x", m);
        m.printMatrix();

        S.readVectorDataFromLSTFile("scenario1.lst", "y", v);
        v.printVector();
        
        S.readObjValueFromLSTFile("scenario1.lst", "z", s);
        s.printScalar();
*/
      
    }
    catch (SumProbabilitiesException e) {
        e.displayMessage();
    }
    catch (NumParametersException e) {
        e.displayMessage();
    }
    catch (FileNotExists e) {
        e.displayMessage();
    }
    catch (NoOccurenceOfVariableInLSTFile e) {
        e.displayMessage();
    }
    catch (GeneralException e){
        e.displayMessage();
    }
    catch(...) {
        printf(" > ERROR! An unspecified exception occured.");
    }
    
    return (EXIT_SUCCESS);
}

