void ExperimentRun::start()
    {
        if(true) {//NEAT::Globals::getSingleton()->getParameterValue("MultiObjective") > 0.5) {
            boost::filesystem::remove(outputFileName);
            boost::filesystem::remove(outputFileName+string(".gz"));
        }
        cout << "Experiment started\n";
#ifndef _DEBUG
        try
        {
#endif

            int maxGenerations = int(NEAT::Globals::getSingleton()->getParameterValue("MaxGenerations"));

            started=running=true;

            clock_t start,current,reference;
            start  = clock();
            reference = clock();

			
			//resuming an old experiment, want to produce next gen right away because last one already evaluated
			if ((population->getGenerationCount()-1) > 0) { 
                mutex::scoped_lock scoped_lock(*populationMutex);

                cout << "PRODUCING NEXT GENERATION\n";
                produceNextGeneration();
                cout << "DONE PRODUCING\n";							
			}
			
			int startGen = population->getGenerationCount()-1;
			
            for (int generations=(population->getGenerationCount()-1);generations<maxGenerations;generations++)
            {            
                current = clock();
                double time = (double(current)-double(reference))/CLOCKS_PER_SEC;
                if(time >= 3600.0 ) { //if at least an hour elapsed
                    double elapsed = (double(current)-double(start))/CLOCKS_PER_SEC;
                    printf("TIME_STATS: best fitness = %5.5f, generation = %d, elapsed time = %5.5f s\n", population->getBestAllTimeIndividual()->getFitness(), generations - 1,elapsed);
                    reference = clock();
                }

                if (generations>startGen)
                {
                    mutex::scoped_lock scoped_lock(*populationMutex);
                    //set IDs before reproducing so maintain ancestry -- NO LONGER NEEDED SINCE IDs will have been set in finishEvaluations
					//population->getGeneration()->setIDs();

                    cout << "PRODUCING NEXT GENERATION\n";
                    produceNextGeneration();
                    cout << "DONE PRODUCING\n";

//                    cout << "DUMPING REPRODUCED FROM PREVIOUS GENERATION\n";
//                    population->dumpReproducedFromPreviousGeneration(outputFileName/*+string(".backup.xml")*/,true,true);
//                    cout << "DONE DUMPING\n";
                }

                if (experiments[0]->performUserEvaluations())
                {
#ifdef HCUBE_NOGUI
                    throw CREATE_LOCATEDEXCEPTION_INFO("ERROR: TRIED TO USE INTERACTIVE EVOLUTION WITH NO GUI!");
#else
                    frame->getUserEvaluationFrame()->updateEvaluationPanels();
                    running=false;
                    while (!running)
                    {
                        boost::xtime xt;
                        boost::xtime_get(&xt, boost::TIME_UTC);
                        xt.sec += 1;
                        boost::thread::sleep(xt); // Sleep for 1/2 second
                        //cout << "Sleeping while user evaluates!\n";
                    }
#endif
                }
                else
                {
                    while (!running)
                    {
                        boost::xtime xt;
                        boost::xtime_get(&xt, boost::TIME_UTC);
                        xt.sec += 1;
                        boost::thread::sleep(xt); // Sleep for 1/2 second
                    }
                    evaluatePopulation();
                }

                cout << "Finishing evaluations\n";
                finishEvaluations();
                cout << "Evaluations Finished\n";
            }

            //if want to dump all will be taken care of from finishEvaluations now for all gens
            //cout << "DUMPING ALL INDIVIDUALS FROM FINAL GENERATION\n";
            //population->getGeneration()->setIDs();
            //population->dump(outputFileName/*+string(".backup.xml")*/,true,true);
            //cout << "DONE DUMPING\n";

            cout << "Experiment finished\n";

            //cout << "Saving Dump...";
            //population->dump(outputFileName,true,false);
            //cout << "Done!\n";


            if(true) {//NEAT::Globals::getSingleton()->getParameterValue("MultiObjective") > 0.5) {
                //need to combine files into one
                //TiXmlDocument doc();
                TiXmlElement *root = new TiXmlElement("Genetics");
                NEAT::Globals::getSingleton()->dump(root);


                /*
                stringstream ss;
                //root->Print(ss,0);


                ss << root;
                string s = ss.str();

                */
                cout << "Merging Output Files...";

                TiXmlPrinter rootPrinter;
                root->Accept( &rootPrinter );
                string s = rootPrinter.CStr();

                ofstream out( outputFileName.c_str() );
                string lastGenFileName = outputFileName + string(".lastgen.xml");
                ofstream out2( lastGenFileName.c_str() );

                out << s.substr(0, s.length() - 3) << ">" <<endl;
                out2 << s.substr(0, s.length() - 3) << ">" <<endl;

                int maxGenerations = int(NEAT::Globals::getSingleton()->getParameterValue("MaxGenerations"));
                for(int i=0; i<maxGenerations; i++) {
                    stringstream ss;
                    ss << i;
                    TiXmlDocument doc( outputFileName + string("-") + ss.str() + string(".backup.xml.gz") );
                    doc.LoadFileGZ();
                    TiXmlPrinter printer;
                    doc.Accept(&printer);
                    out << printer.CStr() << endl;
                    if( i == (maxGenerations - 1))
                        out2 << printer.CStr() << endl;
                }
                out << "</Genetics>" << endl;
                out2 << "</Genetics>" << endl;
                out.close();
                out2.close();
                cout << "Done!\n";
                cout << "Compressing Merged File...";
                stringstream ss;
                ss << "gzip " << outputFileName;
                std::system(ss.str().c_str());
                stringstream ssLastGen;
                ssLastGen << "gzip " << lastGenFileName;
                std::system(ssLastGen.str().c_str());

                cout << "Done!\n";
                cout << "Deleting backup files...";
                for(int i=0; i<maxGenerations; i++) {
                    stringstream ss2;
                    ss2 << outputFileName << "-" << i << ".backup.xml.gz";
                    boost::filesystem::remove(ss2.str());
                }
                boost::filesystem::remove(outputFileName + string("-root.backup.xml"));
                cout << "Done!\n";


            } else {
                cout << "Saving best individuals...";
                string bestFileName = outputFileName.substr(0,outputFileName.length()-4)+string("_best.xml");
                population->dumpBest(bestFileName,true,true);
                cout << "Done!\n";

                cout << "Deleting backup file...";
                boost::filesystem::remove(outputFileName+string(".backup.xml"));
                cout << "Done!\n";
            }
#ifndef _DEBUG
        }
        catch (const std::exception &ex)
        {
			cout << "CAUGHT ERROR AT " << __FILE__ << " : " << __LINE__ << endl;
            CREATE_PAUSE(ex.what());
        }
        catch (...)
        {
			cout << "CAUGHT ERROR AT " << __FILE__ << " : " << __LINE__ << endl;
            CREATE_PAUSE("AN UNKNOWN EXCEPTION HAS BEEN THROWN!");
        }
#endif
    }
  void ExperimentRun::start()
  {
    cout << "Experiment started\n";
		

#ifndef DEBUG_EXPRUN
    try
      {
#endif
        int maxGenerations = int(NEAT::Globals::getSingleton()->getParameterValue("MaxGenerations"));
			
        started=running=true;
			
        for (int generations=(population->getGenerationCount()-1);generations<GET_PARAMETER("MaxGenerations");generations++)
          {
            cout << "CURRENT SUBEXPERIMENT: " << currentSubExperiment << " Generation:" << generations << endl;

            if (generations>0) 
              {
                // TODO: replace OR with experiments[currentSubExperiment].getExperimentName() == "HYBRID"
                if(experiments[currentSubExperiment]->getExperimentName() == "HYBRID" && switchSubExperiment(generations))
                  //					if((experimentType == EXPERIMENT_LEGSWING_HYBRID || experimentType == EXPERIMENT_BITMIRRORING_HYBRID || experimentType == EXPERIMENT_TARGETWEIGHTS_HYBRID) && switchSubExperiment(generations))
                  {
                    cout << "\n\n"
                         << "************************\n"
                         << "Switching SubExperiment:  Hyper -> FT\n"
                         << "************************\n\n";
                    // copy population from (currentSubExperiment-1)%totalSubExperiments to currentSubExperiment using HyperNEAT to P-NEAT converter
                    population = shared_ptr<NEAT::GeneticPopulation>(experiments[currentSubExperiment]->createInitialPopulation(population, experiments[(currentSubExperiment + 1) % totalSubExperiments]));
                    //TODO: check that this copying works
						
                    //THESE CAN COME OUT when Hyper -> NEAT works
                    cout << "changing the following three parameter settings from the HyperNEAT settings of:" << endl;
                    cout << "MutateAddNodeProbability: " << NEAT::Globals::getSingleton()->getParameterValue("MutateAddNodeProbability") << endl;
                    cout << "MutateAddLinkProbability: " << NEAT::Globals::getSingleton()->getParameterValue("MutateAddLinkProbability") << endl;
                    cout << "MutateDemolishLinkProbability: " << NEAT::Globals::getSingleton()->getParameterValue("MutateDemolishLinkProbability") << endl;
                    NEAT::Globals::getSingleton()->setParameterValue("MutateAddNodeProbability",0.0);
                    NEAT::Globals::getSingleton()->setParameterValue("MutateAddLinkProbability",0.0);
                    NEAT::Globals::getSingleton()->setParameterValue("MutateDemolishLinkProbability",0.0);
                    cout << endl << "to the FT-NEAT values of: " << endl;
                    cout << "MutateAddNodeProbability: " << NEAT::Globals::getSingleton()->getParameterValue("MutateAddNodeProbability") << endl;
                    cout << "MutateAddLinkProbability: " << NEAT::Globals::getSingleton()->getParameterValue("MutateAddLinkProbability") << endl;
                    cout << "MutateDemolishLinkProbability: " << NEAT::Globals::getSingleton()->getParameterValue("MutateDemolishLinkProbability") << endl << endl;
						
                    if(experiments[currentSubExperiment]->getHybrid_FTMutateOnlyProbability() != -1.0)
                      NEAT::Globals::getSingleton()->setParameterValue("MutateOnlyProbability", experiments[currentSubExperiment]->getHybrid_FTMutateOnlyProbability());
						
                    if(experiments[currentSubExperiment]->getHybrid_FTMutateLinkProbability() != -1.0)
                      NEAT::Globals::getSingleton()->setParameterValue("MutateLinkProbability", experiments[currentSubExperiment]->getHybrid_FTMutateLinkProbability());
						
                    //THESE CAN COME OUT ONCE THIS WORKS
                    cout << "MutateOnlyProbability" << NEAT::Globals::getSingleton()->getParameterValue("MutateOnlyProbability") << endl;
                    cout << "MutateLinkProbability" << NEAT::Globals::getSingleton()->getParameterValue("MutateLinkProbability") << endl;
                  } else {
                  mutex::scoped_lock scoped_lock(*populationMutex);
                  cout << "\nPRODUCING NEXT GENERATION\n";
                  produceNextGeneration(); 
                }
              }
				
            if (experiments[currentSubExperiment]->performUserEvaluations())
              {
                throw CREATE_LOCATEDEXCEPTION_INFO("ERROR: TRIED TO USE INTERACTIVE EVOLUTION WITH NO GUI!");
              }
            else
              {
                while (!running)
                  {
                    boost::xtime xt;

                    boost::xtime_get(&xt, boost::TIME_UTC_);

                    xt.sec += 1;
                    // boost::thread::sleep(xt); // Sleep for 1/2 second
                    usleep(500000);
                  }
#ifdef INTERACTIVELYEVOLVINGSHAPES
                stringstream genNum; 
                genNum << setw(5) << std::setfill('0') << generations;
                population->dumpLast(outputFileName +"_"+ genNum.str()+".xml",true,false); //print out xml file each generation
#endif
					
										
                cout << "about to evaluatePopulation\n";					
                evaluatePopulation();
              }
				
#ifdef DEBUG_EXPRUN
            cout << "Finishing evaluations\n";
#endif
            finishEvaluations();
            experimentRunPrintToGenChampFile();
				
#ifdef DEBUG_EXPRUN
            cout << "Evaluations Finished\n";
#endif
          }
        cout << "Experiment finished\n";
			
        
			
        cout << "Saving Dump...";
        population->dump(outputFileName+string("_pop.xml"),true,false);
        cout << "Done!\n";

			
        cout << "Saving best individuals...";
        string bestFileName = outputFileName.substr(0,outputFileName.length()-4)+string("_best.xml");
        population->dumpBest(bestFileName,true,true);
        cout << "Done!\n";
			
        cout << "Skippped deleting backup files because of problem with boost!";
        //cout << "Deleting backup file...";
        //boost::filesystem::remove(outputFileName+string(".backup.xml.gz"));
        //cout << "Done!\n";
			
#ifndef DEBUG_EXPRUN
      }
    catch (const std::exception &ex)
      {
        cout << "CAUGHT ERROR AT " << __FILE__ << " : " << __LINE__ << endl;
        CREATE_PAUSE(ex.what());
      }
    catch (...)
      {
        cout << "CAUGHT ERROR AT " << __FILE__ << " : " << __LINE__ << endl;
        CREATE_PAUSE("AN UNKNOWN EXCEPTION HAS BEEN THROWN!");
      }
#endif
  }