#include <ctime>
#include <string>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "graph.h"
using namespace std;

#include <process.h>
#include <windows.h>
float GetMyCPUTime()
{
    HANDLE hProcess;    // specifies the process of interest
    FILETIME lpCreationTime;    // when the process was created
    FILETIME lpExitTime;    // when the process exited
    FILETIME lpKernelTime;    // time the process has spent in kernel mode
    FILETIME lpUserTime;
    LARGE_INTEGER t1, t2;

    hProcess = GetCurrentProcess();
    GetProcessTimes(hProcess, &lpCreationTime, &lpExitTime, &lpKernelTime, &lpUserTime);
    memcpy(&t1, &lpUserTime, sizeof(FILETIME));
    memcpy(&t2, &lpKernelTime, sizeof(FILETIME));
    return ((float)(t1.QuadPart+t2.QuadPart)/10000000);
}

Graph *graph;

int main(int argc, char *argv[])
{
  if (argc<3) 
  {
    cerr << "USAGE: " << argv[0] << " <input PLA file> <output PLA file>";
    return 1;
  }
	float t1 = GetMyCPUTime();
	//float t2;
	float t3;

	graph = new Graph();
	graph->ConstructFromPLAFile(argv[1]);
//	t2 = GetMyCPUTime();
//	cout << "Graph constructing duration: " << (double) (t2-t1) << "s" << endl;

//	graph->ClearRedundant();
//	cout << graph->GenerateStreamForPLA(); cout << endl;
//	graph->Orthogonalization(false);
	graph->Minimization(false);
//	Graph *h = graph->Complement();
	
	

	ofstream f; 
	f.open(argv[2]);
	if (!f.is_open())
	{
		cerr << "Cannot open file: ";
		return false;
	}
	else
	{
		f << graph->GenerateStreamForPLA();
		f.close();
	}

//	string result;
//	result = graph->GenerateStreamForPLA();
//	graph->Simplification();
//	result = graph->BranchAndBoundTautology();
//	result = graph->BruteForceTautology();
	t3 = GetMyCPUTime();
//	cout << result << endl;
//	cout << graph->GenerateStreamForPLA();
	cout << "Task duration: " << (double) (t3-t1) << "s" << endl;
  return 0;
}
