Beispiel #1
0
int main(POSSIBLY_UNUSED(int argc), char **argv)
{
	char tdir[PATH_MAX];
	struct fast_log_buf *fb;
	timer_t timer;
	time_t t;

	EXPECT_ZERO(utility_ctx_init(argv[0])); /* for g_fast_log_mgr */
	t = mt_time() + 600;
	EXPECT_ZERO(mt_set_alarm(t, "ostor_unit timed out", &timer));
	fb = fast_log_create(g_fast_log_mgr, "main");
	EXPECT_NOT_ERRPTR(fb);

	EXPECT_ZERO(get_tempdir(tdir, sizeof(tdir), 0755));
	EXPECT_ZERO(register_tempdir_for_cleanup(tdir));
	EXPECT_ZERO(ostoru_test_open_close(tdir));

	EXPECT_ZERO(get_tempdir(tdir, sizeof(tdir), 0755));
	EXPECT_ZERO(register_tempdir_for_cleanup(tdir));
	EXPECT_ZERO(ostoru_simple_test(tdir, fb, 100));

	EXPECT_ZERO(get_tempdir(tdir, sizeof(tdir), 0755));
	EXPECT_ZERO(register_tempdir_for_cleanup(tdir));
	EXPECT_ZERO(ostoru_simple_test(tdir, fb, 1));

	EXPECT_ZERO(get_tempdir(tdir, sizeof(tdir), 0755));
	EXPECT_ZERO(register_tempdir_for_cleanup(tdir));
	EXPECT_ZERO(ostoru_threaded_test(tdir, 10));

	EXPECT_ZERO(mt_deactivate_alarm(timer));
	fast_log_free(fb);
	process_ctx_shutdown();

	return EXIT_SUCCESS;
}
Beispiel #2
0
int main(POSSIBLY_UNUSED(int argc), char **argv)
{
	timer_t timer;
	time_t t;

	EXPECT_ZERO(utility_ctx_init(argv[0]));
	t = mt_time() + 600;
	EXPECT_ZERO(mt_set_alarm(t, "msgr_unit timed out", &timer));
	EXPECT_ZERO(get_localhost_ipv4(&g_localhost));
	EXPECT_ZERO(msgr_test_init_shutdown(0));
	EXPECT_ZERO(msgr_test_init_shutdown(1));
	EXPECT_ZERO(msgr_test_simple_send(1));
	EXPECT_ZERO(msgr_test_simple_send(100));
	EXPECT_ZERO(msgr_test_conn_timeout());
	EXPECT_ZERO(msgr_test_conn_shutdown());
	EXPECT_ZERO(mt_deactivate_alarm(timer));
	process_ctx_shutdown();

	return EXIT_SUCCESS;
}
Beispiel #3
0
int main(){

auto seed = 10;
std::mt19937 mt_time(seed);
std::uniform_real_distribution<double> dist(0,1);

std::ofstream outputFile;
outputFile.open("Output.txt");


int NUMBER_OF_CELLS = 10000;
int NUMBER_OF_MUTATIONS = 10;

std::vector<double> r(NUMBER_OF_MUTATIONS, 1);
std::vector<double> u(NUMBER_OF_MUTATIONS, 0.1);
u.at(0) = 0;
u.push_back(0);

//r.at(9) = 0.5;

Population pop_test(NUMBER_OF_MUTATIONS,NUMBER_OF_CELLS);
Rates rates_test(pop_test.Get_Population(),r,u);

double time = 0;
bool fixxed = false;

int iterations = 25 ;
int z = 0;

std::vector< std::vector <double>> averageArray;
int finalTime = 250000;
double stepTime = 1;
double timeRows = finalTime/stepTime;

averageArray.resize(timeRows, std::vector<double>(NUMBER_OF_MUTATIONS+1, 0));
PopulateAverageArrayTimes(averageArray, stepTime);


while(z < iterations){
	
	//if( z%100 ==0){
	
		std::cout << z  << std::endl;
	//}

	Population pop_test(NUMBER_OF_MUTATIONS,NUMBER_OF_CELLS);
	Rates rates_test(pop_test.Get_Population(),r,u);
	std::vector< std::vector <double>> outputArray;
	bool avgWriteTest = true;
	int avgCounter = 0;

	fixxed = false;
	time = 0;

	while (!fixxed) {

	//	std::vector <double> outputRow(NUMBER_OF_MUTATIONS + 1, 0);
	//	outputRow.at(0) = time;

		if ( pop_test.Fixation_Test() ) {
			std::cout << "Fixed!" << std::endl;
			fixxed = pop_test.Fixation_Test();

	//		outputRow.at(NUMBER_OF_MUTATIONS) = NUMBER_OF_CELLS;

	//		outputArray.push_back(outputRow);
			
			averageArray.at(avgCounter).at(NUMBER_OF_MUTATIONS) = NUMBER_OF_CELLS;
			
			break;
		}
		
			//std::cout << "Counter: " << avgCounter << "\t" << avgWriteTest << std::endl;

		if(avgWriteTest){
			for (int g = 1; g < NUMBER_OF_MUTATIONS+1; g++) {

	//			outputRow.at(g) = pop_test.Get_Population().at(g-1);
				averageArray.at(avgCounter).at(g) = averageArray.at(avgCounter).at(g) +  pop_test.Get_Population().at(g-1);
//				std::cout << pop_test.Get_Population().at(g-1) << std::endl;

			}
			avgCounter ++;
		}

	//	outputArray.push_back(outputRow);

		double random_1 = dist(mt_time);

		double delta = (1 / rates_test.Get_a0()) * log(1/random_1);

		auto change = rates_test.Get_Population_Change();
		
		pop_test.Update(change);

		rates_test.Update(pop_test.Get_Population());

		time = time + delta;
		
	//	std::cout << "Time: " << time << "\t Step" << averageArray.at(avgCounter).at(0) << std::endl;
			
		avgWriteTest = time > averageArray.at(avgCounter).at(0); 
		
		//std::cout << avgWriteTest << std::endl; 
	}

	z++;
		
}

outputFile.close();

int resizeValue;

for(int row = 0; row < averageArray.size(); row++){

	double maxSizeSum = 0;

	for( int col = 1; col < averageArray.at(0).size(); col ++){

		averageArray.at(row).at(col) =  averageArray.at(row).at(col) /iterations ; 
		maxSizeSum += averageArray.at(row).at(col); 
	}

	if( maxSizeSum == 0) {
		
		 resizeValue = row;
		 break;
	}

}

averageArray.resize(resizeValue);
//std::cout << resizeValue << std::endl;

for(int row = 0; row < averageArray.size(); row++){
	for( int col = 0; col < averageArray.at(0).size(); col ++){

		std::cout << averageArray.at(row).at(col) << "\t"; 

	}

	std::cout << std::endl; 
}

Do_Statistics(averageArray);


return 0;

}
Beispiel #4
0
int main(){

//########## Parameters to set ########## 

int NUMBER_OF_CELLS = 100;
int NUMBER_OF_MUTATIONS = 10;

int iterations = 100 ;

double rFlat = 1;
double uFlat = 0.5; 

std::string rLandscape = "FLAT";

double rTrap = 1.00;
int rTrapStart = 25;
int rTrapEnd = 35;

std::string uLandscape = "MANUAL";

double uTrap = 0.10;
double uTrapStart = 3;
double uTrapEnd = 5;

//#######################################


clock_t t;
t = clock(); 

auto seed =  std::chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 mt_time(seed);
std::uniform_real_distribution<double> dist(0,1);

std::string fileNameID = std::to_string(seed);

//########## Write parameters to file ##########

std::ofstream parameterOutputFile; 
parameterOutputFile.open(fileNameID + "_Parameters.txt");

parameterOutputFile << "Number of cells: \t " << NUMBER_OF_CELLS << std::endl;
parameterOutputFile << "Number of mutations: \t " << NUMBER_OF_MUTATIONS << std::endl;
parameterOutputFile << "Number of iteration: \t " << iterations << std::endl;
parameterOutputFile << "Fitness Landscape: \t " << rLandscape << std::endl;
parameterOutputFile << "Mutation Landscape: \t " << uLandscape << std::endl;
parameterOutputFile << "Fitness Flat Value: \t " << rFlat << std::endl;
parameterOutputFile << "Mutation Flat Value: \t " << uFlat << std::endl;
//#############################################



Population pop_test(NUMBER_OF_MUTATIONS,NUMBER_OF_CELLS, rFlat, uFlat);

if( (uLandscape.compare("ANTITRAP") || uLandscape.compare("TRAP")) == 0 ){

	pop_test.Modify_MutationLandscape(uTrap, uTrapStart, uTrapEnd);

	parameterOutputFile << "Mutation Trap Value: \t " << uTrap << std::endl;
	parameterOutputFile << "Mutation Trap Start: \t " << uTrapStart << std::endl;
	parameterOutputFile << "Mutation Trap End: \t " << uTrapEnd << std::endl;
}
if( uLandscape.compare("MANUAL") == 0 ){

	std::cout << "Manual Entered " << std::endl;

	std::vector<double> uManual;

		for(int x = 0 ; x<NUMBER_OF_MUTATIONS; x++){
			std::cout << x << std::endl;

			//Here is where you specfiy the function that the mutation landscape needs to follow. 
			auto f = [](int x, int NUMBER_OF_MUTATIONS){return (((double)x/NUMBER_OF_MUTATIONS) * 1 + 0.01)  ; };


			uManual.push_back( f(x, NUMBER_OF_MUTATIONS));
			
			parameterOutputFile << "Mutation Manual Value: \t " << uManual.at(x) << std::endl;

		}

	pop_test.Manual_MutationLandscape(uManual);
}




if( rLandscape.compare("FLAT") != 0){

	pop_test.Modify_FitnessLandscape(rTrap, rTrapStart, rTrapEnd);

	parameterOutputFile << "Fitness Trap Value: \t " << rTrap << std::endl;
	parameterOutputFile << "Fitness Trap Start: \t " << rTrapStart << std::endl;
	parameterOutputFile << "Fitness Trap End: \t " << rTrapEnd << std::endl;
}

parameterOutputFile.close();

std::vector<double> r = pop_test.Get_FitnessLandscape();
std::vector<double> u = pop_test.Get_MutationLandscape();

Rates rates_test(pop_test.Get_Population(),r,u);

double time = 0;
bool fixxed = false;
int z = 0;

std::string fitnessLandscape = "Flat";  
std::string outputFileName = std::to_string(NUMBER_OF_MUTATIONS) + "Mutations" + std::to_string(NUMBER_OF_CELLS) + "Cells" + std::to_string(iterations) + "Iterations" + fitnessLandscape;

//########## Initialise the average array ########## 

std::vector< std::vector <double>> averageArray;
int finalTime = 250000;
double stepTime = 1;
double timeRows = finalTime/stepTime;

averageArray.resize(timeRows, std::vector<double>(NUMBER_OF_MUTATIONS+1, 0));
PopulateAverageArrayTimes(averageArray, stepTime);

//std::cout << "Initialisation time: " << (float)(clock() - t) << std::endl;


std::ofstream fixationTimeFile;
fixationTimeFile.open(fileNameID + "_FixationTimes.txt");

std::ofstream populationFile;
populationFile.open(fileNameID +"_Populations.txt"); 

while(z < iterations){
	

	std::cout << fileNameID +  " Iteration number: " <<  z << std::endl;

	Population pop_test(NUMBER_OF_MUTATIONS,NUMBER_OF_CELLS, 1, 0.1);
	Rates rates_test(pop_test.Get_Population(),r,u);
	std::vector< std::vector <double>> outputArray;
	bool avgWriteTest = true;
	int avgCounter = 0;

	fixxed = false;
	time = 0;

//	std::cout << "Made it to the loop" << std::endl;

	while (!fixxed) {

//std::cout << "One reaction: " << std::endl;
//t = clock();
 
		if ( pop_test.Fixation_Test() ) {
			//std::cout << "Fixation Time: " <<  averageArray.at(avgCounter).at(0)  << std::endl;
			fixationTimeFile <<  averageArray.at(avgCounter).at(0)  << std::endl;
			fixxed = pop_test.Fixation_Test();
			
//t = clock();
			while(avgCounter < averageArray.size()){
				averageArray.at(avgCounter).at(NUMBER_OF_MUTATIONS) = averageArray.at(avgCounter).at(NUMBER_OF_MUTATIONS) +  NUMBER_OF_CELLS;
				avgCounter ++ ;
			}
//std::cout << "Filling average array " << (float)(clock() - t)/ CLOCKS_PER_SEC << std::endl;
			break;
		}
		

//std::cout << "Fixation test took: " << (float)(clock() - t) << std::endl;
//t = clock(); 

		if(avgWriteTest){
			for (int g = 1; g < NUMBER_OF_MUTATIONS+1; g++) {

				averageArray.at(avgCounter).at(g) = averageArray.at(avgCounter).at(g) +  pop_test.Get_Population().at(g-1);

			}
			avgCounter ++;
		}

//std::cout << "Average write test took: " << (float)(clock() - t) << std::endl;
//t = clock();
 
		double random_1 = dist(mt_time);

		double delta = (1 / rates_test.Get_a0()) * log(1/random_1);

//std::cout << "Time  update took: " << (float)(clock() - t) << std::endl;
//t = clock(); 
		auto change = rates_test.Get_Population_Change();
		
		pop_test.Update(change);

//std::cout << "population update took: " << (float)(clock() - t) << std::endl;
//t = clock(); 
		rates_test.Update(pop_test.Get_Population());

//std::cout << "Rates update took: " << (float)(clock() - t) << std::endl;
//t = clock(); 
		time = time + delta;
		
			
		avgWriteTest = time > averageArray.at(avgCounter).at(0); 
		
//std::cout << "Write test update took: " << (float)(clock() - t) << std::endl;
	}

	z++;

		
}


int resizeValue;

for(int row = 0; row < averageArray.size(); row++){

	double maxSizeSum = 0;

	for( int col = 1; col < averageArray.at(0).size(); col ++){

		averageArray.at(row).at(col) =  averageArray.at(row).at(col) /iterations ; 
		maxSizeSum += averageArray.at(row).at(col); 
	}

	if(averageArray.at(row).at(NUMBER_OF_MUTATIONS) == NUMBER_OF_CELLS) {
		
		 resizeValue = row + 1;
		 break;
	}

}

averageArray.resize(resizeValue);


for(int row = 0; row < averageArray.size(); row++){
	for( int col = 0; col < averageArray.at(0).size(); col ++){

		populationFile << averageArray.at(row).at(col) << "\t"; 

	}

	populationFile << std::endl; 
}

Do_Statistics(averageArray, fileNameID);


std::cout << "\a" ;

return 0;

}