//
// main.cpp
//
#include "interface.h"

#ifdef graphicOut
  #include <qapplication.h>
  #include "form1.h"
#endif

#ifdef consoleOut
  #include "parser.h"
  #include "CGeneration.h"
  #include "CString.h"
#endif

int main( int argc, char ** argv )
{
  #ifdef graphicOut
  QApplication a( argc, argv );
  Form1 w;
  w.show();
  a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
  return a.exec();
  #endif

  #ifdef consoleOut
  if (argc!=12)
  {
    cout << "satGen <sat_instance> <populationSize> <eliteCount> <generationCount> <crossoverProbability> <mutationProbability> <reproductionMethod> <crossoverMethod> <fitnessSelected> <maxGenBestSolutionUnchanged> <tournamentSize>" << endl;
    return 0;
  }

  int fitnessSel=parseInt(argv[9]);
  if (fitnessSel==1)
  {
    cout << "Weigted SAT implemented completely only in graphic version of satGen. All weights and penalty value set to default." << endl;
    return 0;
  }

    InnerForm *inner;
    CGeneration *cgen;

    try{
      inner=new InnerForm();
      parseCNF(argv[1], inner);
//      inner->print();

      cgen=new CGeneration(inner, parseInt(argv[2]), parseInt(argv[3]), parseInt(argv[4]), fitnessSel, parseInt(argv[10]));
    }catch(const char *msg){
      cout << msg << endl;
      return 1;
    }
    cgen->evolution(parseInt(argv[5])/100, parseInt(argv[6])/100, parseInt(argv[7]), parseInt(argv[8]), parseInt(argv[11]));


//CGeneration *cgen=new CGeneration(inner, 12, 2, 145, 0);
//cgen->evolution(0.7, 0.01, 2, 3);

// reproduction method
// 0=roulette
// 1=tournament
// 2=random

// crossover method
// 0=simple
// 1=two-point
// 2=uniform
// 3=improvement

// fitness
// 0=number of sat clauses
// 1=weighted sat

  delete cgen;
  delete inner;

  return 0;
  #endif
}
