Program Listing for File Pggsym.h¶
↰ Return to documentation for file (source/pgg_mode/Pggsym.h
)
#ifndef PGGSYM_H
#define PGGSYM_H
#include "../default_mode/Symbiont.h"
#include "PggWorld.h"
class PGGSymbiont: public Symbiont {
protected:
double Pgg_donate = 0;
emp::Ptr<PggWorld> my_world = NULL;
public:
PGGSymbiont(emp::Ptr<emp::Random> _random, emp::Ptr<PggWorld> _world, emp::Ptr<SymConfigBase> _config, double _intval=0.0, double _donation = 0.0, double _points = 0.0 ) : Symbiont(_random, _world, _config, _intval, _points),Pgg_donate(_donation)
{my_world = _world;}
PGGSymbiont(const PGGSymbiont &) = default;
PGGSymbiont(PGGSymbiont &&) = default;
PGGSymbiont() = default;
PGGSymbiont & operator=(const PGGSymbiont &) = default;
PGGSymbiont & operator=(PGGSymbiont &&) = default;
double GetDonation() {return Pgg_donate;}
void Setdonation(double _in) {Pgg_donate = _in;}
void mutate(){
Symbiont::mutate();
if (random->GetDouble(0.0, 1.0) <= my_config->MUTATION_RATE()) {
Pgg_donate += random->GetRandNormal(0.0, my_config->MUTATION_SIZE());
if(Pgg_donate < 0) Pgg_donate = 0;
else if (Pgg_donate > 1) Pgg_donate = 1;
}
}
double ProcessPool(){
double symdonation = GetDonation();
double symPortion = GetPoints();
double hostreturn = symdonation*symPortion;
SetPoints(symPortion-hostreturn);
return hostreturn;
}
emp::Ptr<Organism> makeNew() {
emp::Ptr<PGGSymbiont> sym_baby = emp::NewPtr<PGGSymbiont>(random, my_world, my_config, GetIntVal());
sym_baby->SetInfectionChance(GetInfectionChance());
sym_baby->Setdonation(GetDonation());
return sym_baby;
}
std::string PrintSym(emp::Ptr<PGGSymbiont> org){
if (org->GetPoints() < 0) return "-";
double out_val = org->GetIntVal();
double donate_val = org->GetDonation();
// this prints the symbiont with two decimal places for easier reading
std::stringstream temp;
temp << std::fixed << std::setprecision(2) << "Interaction value: " << out_val << " Donation value: " << donate_val;
std::string formattedstring = temp.str();
return formattedstring;
}//Pggsym
};
#endif