int main(int argc, char* argv[]) {

	if (argc < 5) {
		std::cout << argv[0] << " <numberOfGenerations> <sizeOfPopulation> <numberOfAtoms> <percentageMutation>" << std::endl;
		return EXIT_FAILURE;
	}

	std::fstream out;
	out.open("../results/ga-out", std::ios::out);
	assert(out.is_open());

	int maxDistance = 1000;
	int numberOfGenerations = std::stoi(argv[1]);
	int sizeOfPopulation = std::stoi(argv[2]);
	int numberOfAtoms = std::stoi(argv[3]);
	int percentage = std::stoi(argv[4]);

	Randomize* randomize = new Randomize();
	Evolution* evolution = new Evolution();

	out << "genetico" << std::endl;
	out << numberOfAtoms << std::endl;

	//	generate random generation
	Generation* pGen = randomize->randomGeneration(maxDistance, sizeOfPopulation, numberOfAtoms);
	Molecule** pMol = pGen->molecules();
	//	calculate potential
	for (int i = 0; i < sizeOfPopulation; i++) {
		Molecule* m = pMol[i];
		m->setPotential(evolution->lennardJones(m));
	}
	//	ordering molecules
	QuickSort<Molecule>::sort(pMol, 0, sizeOfPopulation - 1);
	Atom** pAtom = pMol[0]->atoms();
	for (int i = 0; i < pMol[0]->numberOfAtoms(); i++) {
		out << "Au" << "\t" << pAtom[i]->_x << "\t" << pAtom[i]->_y << "\t" << pAtom[i]->_z << std::endl;
	}



	//	calculates next generations
	Molecule* idv1 = NULL;
	Molecule* idv2 = NULL;
	Generation* nGen = NULL;
	Molecule** nMol = NULL;
	int generationID = 1;
	while (numberOfGenerations > 0) {
		//		create new generation
		nGen = new Generation(generationID);
		for (int i = 0; i < sizeOfPopulation; i++) {
			//			select individuals
			idv1 = pMol[randomize->randomInt(sizeOfPopulation)];
			idv2 = pMol[randomize->randomInt(sizeOfPopulation)];
			//			create new individual
			nGen->addMolecule(*evolution->reprodution(idv1, idv2, maxDistance, percentage));
		}

		delete pGen;
		pGen = nGen;
		pMol = pGen->molecules();
		//	calculate potential
		for (int i = 0; i < sizeOfPopulation; i++) {
			Molecule* m = pMol[i];
			m->setPotential(evolution->lennardJones(m));
		}
		//	ordering molecules
		QuickSort<Molecule>::sort(pMol, 0, sizeOfPopulation - 1);
		pAtom = pMol[0]->atoms();
		for (int j = 0; j < pMol[0]->numberOfAtoms(); j++) {
			out << "Au" << "\t" << pAtom[j]->_x << "\t" << pAtom[j]->_y << "\t" << pAtom[j]->_z << std::endl;
		}
		//		increment
		generationID++;
		numberOfGenerations--;
	}

	out.close();

	delete pGen;
	//	delete nGen;

	delete randomize;
	delete evolution;

	return EXIT_SUCCESS;
}