Example #1
0
int main () {
	srand(time(NULL));
	
	for(int i=0;i<POINTS;++i)
	{
		polars[i]=float(rand())*M_PI*2.0f/float(RAND_MAX);
	}
	sort(polars, polars+POINTS);
	
	for(int i=0;i<POINTS;++i)
	{
		pps1[i].polar=polars[i];
		pps1[i].radial=float(rand())*300.0f/float(RAND_MAX);
		pps2[i].polar=polars[i];
		pps2[i].radial=float(rand())*300.0f/float(RAND_MAX);
	}
	
	Polygon p1(POINTS, new Point[POINTS]);
	Polygon p2(POINTS, new Point[POINTS]);
	
	for(int i=0;i<POINTS;++i)
	{
		p1.points[i]=pps1[i].to_cartesian();
		p2.points[i]=pps2[i].to_cartesian();
		p2.points[i].x+=200.0f;
	}
	
	SectionPolygon sp1=*p1.to_sectionpolygon();
	SectionPolygon sp2=*p2.to_sectionpolygon();
	
	Map map;
	
	map.AddPart(sp1);
	map.AddPart(sp2);
	
	SectionPolygonWithHoles* rp=map.GetMap();
	
	printf("%d\n%d 1 0 0 0\n", rp->size+2, POINTS);
	for(int i=0;i<POINTS;++i)
	{
		printf("%lf %lf\n", p1.points[i].x, p1.points[i].y);
	}
	printf("%d 0 1 0 0\n", POINTS);
	for(int i=0;i<POINTS;++i)
	{
		printf("%lf %lf\n", p2.points[i].x, p2.points[i].y);
	}
	
	for(int i=0;i<rp->size;++i)
	{
		printf("%d 0 0 1 0\n", rp->polygons[i]->size);
		for(int j=0;j<rp->polygons[i]->size;++j)
		{
			printf("%lf %lf\n", rp->polygons[i]->sections[j].f.x, rp->polygons[i]->sections[j].f.y);
		}
	}
	
	
}
/*FUNCTIONS OF CLASS HOST
 *Constructs a host for the initialization of the population: it fills the MHC genes with a randomly picked allele from the population
 * and creates KIRs that match their own MHC according to the specificity*/
Host::Host(int loci_kir, int loci_mhc, double _mutationRate, bool _tuning, int numberOfExtraKirs,Map& kirMap, MHCGenePool& mhcPool, bool hla) {

	InitializeHostParameters(_mutationRate,_tuning, loci_kir, loci_mhc);
	//fill the mhc Genes
	for(int i = 0; i <lociMHC*TWO; i++)
	{
		Gene firstGene;
		int mhc1 = mhcPool.RandomlyPickGene(hla);
		firstGene.SetGeneID(mhc1);
		mhcGenes.push_back(firstGene);
	}

/*
	Gene secondGene;
	secondGene.SetGeneID(mhc2);
	mhcGenes.push_back(secondGene);*/

	//create random KIRs with random specificity for ONE haplotype
	// (at the beginning of the simulation, the size of the map should equal the LOCI_NUMBER)
	map< pair<int,int>, pair <int, int> > ::iterator it;
	for(it = kirMap.GetMap().begin(); it != kirMap.GetMap().end(); it ++)
	{
		int id = it->first.first;
		int geneType = it->first.second;
		int L = it->second.first;
		int pseudo = it->second.second;
		KIRGene kir;
		kir.SetGeneSpecificity(L);
		kir.SetGeneID(id);
		kir.SetPseudogene(pseudo);
		kir.SetGeneType(geneType);
		kir.SetGeneFunctionality(false);
		kir.SetGeneExpression(false);
		kirGenes.push_back(kir);
		//cout << "printing genes in host first constructor" <<endl;
		//kir.PrintGenes();
	}

	int size = kirGenes.size();
	//make sure that the first haplotype has number lociKIR (regardless of the Map size!)
	while(size < lociKIR)
	{
		KIRGene bla = kirGenes.at(size-1);
		kirGenes.push_back(bla);
		size ++;
	}

	//copy the first kirs into the other haplotype (all individuals are homozygous!)
	for(int i=0; i<lociKIR; i++)
	{
		KIRGene kir = kirGenes.at(i);
		kirGenes.push_back(kir);

	}

	if(tuning == true)
		EducateKIRs();
	ExpressKIRs(numberOfExtraKirs);
	//CountFunctionalKIRs();
	age = RandomNumber(1,70); //population initialized with a random age between 1 and 70
	//cout <<inhibitoryKIRs << "|" <<activatingKIRs <<"|"<<CountExpressedKIRs() <<endl;
}