#include"population.h"

Population::Population() {

	// elements of class Population
	N = 0; 
	Nm = 0; 
	Nf = 0;
	Noff0 = 0;
	Nm_off0 = 0;
	Nf_off0 = 0;
	Noff1 = 0;
	Nm_off1 = 0;
	Nf_off1=0;
	Noff2 = 0;
	Nm_off2 = 0;
	Nf_off2 = 0;
	Noff3 = 0;
	Nm_off3 = 0;
	Nf_off3 = 0;


	//m_emi = 0;
	//f_emi = 0;
	//m_imi = 0;
	//f_imi = 0;

	gcount_m_emi = 0;
	gcount_f_emi=0; 
	gcount_m_imi = 0;
	gcount_f_imi=0;

	m_emi_pg = 0.0;
	f_emi_pg = 0.0;
	m_imi_pg = 0.0;
	f_imi_pg = 0.0;

	// 
	sel_Nm = 0;
	sum_dev_cov=0.0 ; // sum of deviances multiplied
	sum_dev_sqrd_RS = 0.0; // sum of deviances squaredm_gme
	cov_mgME_RS = 0.0;
	var_RS = 0.0;

	// output variables during adult stage
	sum_gme=0.0; 
	m_gme = 0.0;
	sum_gmc = 0.0;
	m_gmc = 0.0;

	sum_squared_deviances_gme = 0.0;
	v_gme = 0.0;
	sum_squared_deviances_gmc = 0.0;
	v_gmc = 0.0;

	sum_deviance_traits = 0.0;
	cov_traits = 0.0;

	sum_unmated = 0;
	prop_unmated = 0.0;

}

Population::~Population() {
	
}


// define functions at population level

void Population::outpop(int rep, int gen, int x, int y, double K, double beta, std::ofstream *out)// output population
{
	*out << rep << "\t" << gen << "\t" << x << "\t" << y << "\t" << K << "\t" << beta << "\t" << Nf << "\t" << Nm <<
		"\t" << m_gme <<  "\t" << v_gme << "\t" <<m_gmc << "\t" <<v_gmc << "\t" <<cov_traits << "\t" << prop_unmated <<
		"\t" << m_emi_pg << "\t" << f_emi_pg << "\t" << m_imi_pg << "\t" << f_imi_pg << endl;
}

void Population::outrs(int rep, int gen, int x, int y, std::ofstream *out)// output population
{
	*out << rep << "\t" << gen-1 << "\t" << x << "\t" << y << "\t" << var_RS <<"\t"<<cov_mgME_RS <<  endl;
}

void Population::outind(int rep, int gen, int x, int y, int s,int disp, double gme,double gmc, std::ofstream *out) {
	*out << rep << "\t" << gen << "\t" << x << "\t" << y << "\t" << s << "\t" << disp << "\t" << gme << "\t" << gmc << endl;

} // output individual
