Commit 28a34225 authored by Ignacio Labarca Figueroa's avatar Ignacio Labarca Figueroa
Browse files

Feedback Exercise 4

parent 411f6306
#include "genome.hpp"
/* Ignacio:
There are some missing parts. You also mixed a little members that should be static
maybe, because they apply to the whole population. Have a look at the master solution.
At least you have a good idea of basic things that belong to Animal and Genome.
Good idea to include the counter as static member in this class.
*/
class Animal {
public:
Animal() {}; // constructor that initializes the genome sequence
static int counter; // count the animals alive ~ population
static int counter; // count the animals alive ~ population
~Animal() {}; // destructor when an animal dies
void give_birth(); // have a child (only one is allowed)
void prob_life(); // after the threshold, an individual is alive only with a certain probability
......@@ -14,5 +21,5 @@ class Animal {
int reproduction_age; // minimum age to have a child
int life_threshold; // threshold for mutations allowed before death risks
int max_population; // maximum numbers of individuals in the population
};
\ No newline at end of file
};
......@@ -7,9 +7,11 @@ class Genome {
Genome(bool child) {}; // creation of a child starting from a mother
void mutation(int position); // change a single bit in a particual position of a sequence
~Genome() {}; // destructor when an animal dies
private:
// mutation rate should be included here.
int B; // span of time considered in the simulation
// Isn't this part of a program more than the class?
std::vector<int> sequence; // vector containing the genes
};
\ No newline at end of file
};
......@@ -16,6 +16,22 @@ Post-conditions
*/
/* Ignacio:
Just a comment. You defined your class here, probably because you directly modified the
arguments of integration to accept Func_Obj.
An alternative is to use templates for the function type.
template<typename F, typename T>
where F stands for functions. F needs a well defined call operator, so then
you don't need to modify so much in the simpson integrator.
Moreover, you can define your class Func_Obj in another file, which is
reasonable, considering that this is not strictly related to simpson integrator.
*/
class Func_Obj {
private:
double lambda;
......@@ -23,12 +39,12 @@ class Func_Obj {
public:
Func_Obj(double lambda_value) : lambda(lambda_value) { }
// This operator overloading enables calling
// This operator overloading enables calling
// operator function () on objects of increment
double operator () (double x) const {
return exp(-lambda*x);
}
double operator () (double x) const {
return exp(-lambda*x);
}
// you need friend! Otherwise the class std::ostream can't access Func_obj members
friend std::ostream &operator<<( std::ostream &out, Func_Obj &F_O) {
out << "( Lambda: " << F_O.lambda << " )\n";
......@@ -76,5 +92,3 @@ double integration(const double a, const double b, const int N, Func_Obj my_obj(
return result*delta/3.0;
}
*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment