Commit 3b7a0aa7 authored by amitjans's avatar amitjans
Browse files

Merge branch 'feedback' into 'main'

Added ex04 feedback

See merge request !4
parents 5645c3eb 3a4fe4a8
Pascal: Looks good overall, well done. A few comments:
The operators
T operator*(const T a, const Z2 b)
T operator*(const Z2 b, const T a)
are symmetric. As such, you should implement them by reusing, e.g.
template<class T>
T operator*(const Z2 b, const T a) {
return a * b;
There's a more efficient way to implement the power function, check the
Whenever you write a template, you must specify the corresponding concepts.
/* Programming Techniques for Scientific Simulations, HS 2021
* Exercise 4.1
......@@ -2,6 +2,14 @@
* Simpson library header
This will only work with objects of the specific type "MyFunc". You should
have used templates instead.
Note that your operator() can be const.
#ifndef SIMPSON_HPP // IMPORTANT! To avoid duplications.
#include <math.h>
......@@ -49,4 +57,4 @@ double integrate(const double a,
each bin of the corresponding interpolating parabola
......@@ -2,33 +2,65 @@
#ifndef __PENNA_H__
#define __PENNA_H__
Pascal: This should really be two files.
You're defining things instead of just declaring everything.
Note that the type 'unsigned long' is only guaranteed to be at least 32-bit.
See here:
If you want a type with guaranteed fixed width, you should check here:
In your constructor, what type does '~0' have?
What is the purpose of this constructor?
A genome should probably be able to mutate(), and we also may want to get the
number_of_bad_genes_up_to(unsigned short i)
class Genome {
using gentype = const unsigned long;
static const unsigned short gene_number = 64; // number B of bits of genome
Genome(const unsigned int i = 0) { // ctor
gentype temp = (i > 0) ? (gentype)1 << i : 0; // set the ith bit of temp to 1
gentype mask = ~(~0 << gene_number);
genome_ = mask & temp; // set all bits over "gene_number" to 0
static void set_mutation_rate(unsigned short); // setter
static void get_mutation_rate(unsigned short); // getter
static Genome clone() const;
gentype genome_;
static unsigned short mutation_rate_ = 2;
I would say anything related to the total population of the animals should not
be stored in an individual animal (e.g. get_max_population and the like).
I don't think something like an 'unsigned float' exists.
An animal also has an age. You may also want to have a function that ages the
Why are you providing a default value to the genome of the animal? We probably
want to be able to construct an animal from a genome.
Why do you have all these static values, if you're then trying to change them
all whenever an animal is constructed?
class Fish {
using intval = const unsigned int;
using floatval = const unsigned float;
Fish(intval T, intval N, intval R, floatval M) : threshold_(T), max_population_(N), mutation_rate_(R), reproduction_age_(M) {} // ctor
static void set_threshold(intval); // setters
......@@ -41,11 +73,11 @@ class Fish {
static void get_reproduction_age(intval);
static Fish generate_baby() const;
Genome genome_{};
static intval threshold_; // max number of deleterious mutations before dying
static intval max_population_;
static floatval mutation_rate_; // number of bits flip when child is born
static floatval mutation_rate_; // number of bits flip when child is born
static intval reproduction_age_; // minimum age of reproduction
Supports Markdown
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