Program Listing for File PGGHost.h

Return to documentation for file (source/pgg_mode/PGGHost.h)

#ifndef PGGHOST_H
#define PGGHOST_H

#include "../default_mode/Host.h"
#include "PGGWorld.h"


class PGGHost: public Host {
protected:

  double sourcepool = 0;

  emp::Ptr<PGGWorld> my_world = NULL;

public:
  PGGHost(emp::Ptr<emp::Random> _random, emp::Ptr<PGGWorld> _world, emp::Ptr<SymConfigBase> _config,
  double _intval =0.0, emp::vector<emp::Ptr<Organism>> _syms = {},
  emp::vector<emp::Ptr<Organism>> _repro_syms = {},
  double _points = 0.0) : Host(_random, _world, _config, _intval,_syms, _repro_syms, _points) {my_world = _world;}


  PGGHost(const PGGHost &) = default;


  PGGHost(PGGHost &&) = default;


  PGGHost() = default;

  std::string const GetName() {
    return  "PGGHost";
  }

  double GetPool() {return sourcepool;}


  void SetPool(double _in) {sourcepool= _in;}


  void AddPool(double _in) {sourcepool += _in;}


  void DistribResources(double resources) {
    Host::DistribResources(resources);

    for(size_t i=0; i < syms.size(); i++){
      double hostPool = syms[i]->ProcessPool();
      this->AddPool(hostPool);
    }
    if(syms.size()>0){this->DistribPool();}
  } //end DistribResources


  void DistribPool(){
    //to do: marginal return
    int num_sym = syms.size();
    double bonus = my_config->PGG_SYNERGY();
    double sym_piece = (double) sourcepool / num_sym;
    for(size_t i=0; i < syms.size(); i++){
        syms[i]->AddPoints(sym_piece*bonus);
    }
    this->SetPool(0);
  }

  emp::Ptr<Organism> MakeNew(){
    emp::Ptr<PGGHost> host_baby = emp::NewPtr<PGGHost>(random, my_world, my_config, GetIntVal());
    return host_baby;
  }

};//PGGHost

#endif