Program Listing for File ActivityMap.h

Return to documentation for file (necsim/ActivityMap.h)

//This file is part of necsim project which is released under MIT license.
//See file **LICENSE.txt** or visit https://opensource.org/licenses/MIT) for full license details.

#ifndef ACTIVITYMAP_H
#define ACTIVITYMAP_H

#include <cstring>
#include <string>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <memory>
#include "Map.h"
#include "RNGController.h"

using namespace random_numbers;
namespace necsim
{
    class ActivityMap
    {
    protected:
        // Matrix containing the relative activity probabilities
        Map<double> activity_map;
        // Path to the map file
        string map_file;
        // Maximum value across the map
        double max_val;
        // If true,
        bool null_map;
        // The fine map offsets and the sample map dimensions
        unsigned long offset_x, offset_y, x_dim, y_dim;
        // Random number generator
        shared_ptr<RNGController> random;

        // Function pointer for our reproduction map checker
        typedef bool (ActivityMap::*rep_ptr)(const unsigned long &x, const unsigned long &y, const long &xwrap,
                                             const long &ywrap);

        // once setup will contain the end check function to use for this simulation.
        rep_ptr activity_map_checker_fptr;
    public:
        ActivityMap() : activity_map(), offset_x(0), offset_y(0), x_dim(0), y_dim(0),
                        random(make_shared<RNGController>()), activity_map_checker_fptr(nullptr)
        {
            map_file = "none";
            max_val = 0;
            null_map = true;
        }

        bool isNull();

        void import(string file_name, unsigned long size_x, unsigned long size_y, shared_ptr<RNGController> random_in);

        void setActivityFunction();

        void setOffsets(const unsigned long &x_offset, const unsigned long &y_offset, const unsigned long &xdim,
                        const unsigned long &ydim);

        bool rejectionSampleNull(const unsigned long &x, const unsigned long &y, const long &xwrap, const long &ywrap);

        bool rejectionSample(const unsigned long &x, const unsigned long &y, const long &xwrap, const long &ywrap);

        double getVal(const unsigned long &x, const unsigned long &y, const long &xwrap, const long &ywrap);

        bool actionOccurs(const unsigned long &x, const unsigned long &y, const long &xwrap, const long &ywrap);

        void standardiseValues();

        double get(const unsigned long &rows, const unsigned long &cols);

        double getMean() const;

        ActivityMap &operator=(const ActivityMap &rm);

        friend ostream &operator<<(ostream &os, ActivityMap &r);

        friend istream &operator>>(istream &is, ActivityMap &r);

    };

}
#endif //ACTIVITYMAP_H