Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Biology

 

STL

 

Biology contains some classes that are related to biology.

Technical facts

 

 

 

 

 

 

./CppBiology/CppBiology.pri

 

INCLUDEPATH += \
    ../../Classes/CppBiology

SOURCES += \
    ../../Classes/CppBiology/biology.cpp

HEADERS  += \
    ../../Classes/CppBiology/biology.h

OTHER_FILES += \
    ../../Classes/CppBiology/Licence.txt

 

 

 

 

 

./CppBiology/biology.h

 

//---------------------------------------------------------------------------
/*
Biology, biology-related functions and classes
Copyright (C) 2014-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppBiology.htm
//---------------------------------------------------------------------------
#ifndef RIBI_BIOLOGY_H
#define RIBI_BIOLOGY_H

#include <iosfwd>
#include <string>
#include <vector>

namespace ribi {

///Biology contains biology-related classes and functions
struct Biology
{
  explicit Biology() noexcept;
  typedef double DnDt;
  typedef double PopSize;

  /// What is the growth of a logistically-growing population?
  ///
  /// dN              N - K
  /// -- = N * r * ( ------- )
  /// dt                N
  ///
  /// N: Current population size
  /// K: Carrying capacity: the stable population size if r > 1.0
  /// r: intrinsic growth rate, the average number of offspring an individual has
  /// t: time
  DnDt LogisticGrowth(const PopSize carrying_capacity, const PopSize current_population_size, const double intrinsic_growth_rate);

  private:

  #ifndef NDEBUG
  void Test() noexcept;
  #endif
};

} //~namespace ribi

#endif // RIBI_BIOLOGY_H

 

 

 

 

 

./CppBiology/biology.cpp

 

//---------------------------------------------------------------------------
/*
Biology, biology-related functions and classes
Copyright (C) 2014-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppBiology.htm
//---------------------------------------------------------------------------
#include "biology.h"

#include <cassert>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include "testtimer.h"
#pragma GCC diagnostic pop

ribi::Biology::Biology() noexcept
{
  #ifndef NDEBUG
  Test();
  #endif //NDEBUG
}

ribi::Biology::DnDt ribi::Biology::LogisticGrowth(
  const PopSize carrying_capacity,
  const PopSize current_population_size,
  const double intrinsic_growth_rate)
{
  return  intrinsic_growth_rate * current_population_size
  * ( (carrying_capacity - current_population_size) / carrying_capacity );
}

#ifndef NDEBUG
void ribi::Biology::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);

  {
    const PopSize K{1.0};
    const double r{2.0};
    assert(LogisticGrowth(K,0.5 * K,r) > 0.0);
    assert(LogisticGrowth(K,2.0 * K,r) < 0.0);
  }
}
#endif // NDEBUG

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml