Program Listing for File DispersalCoordinator.h¶
↰ Return to documentation for file (necsim/DispersalCoordinator.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 DISPERSALCOORDINATOR_H
#define DISPERSALCOORDINATOR_H
#include <cstring>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <cmath>
#include <memory>
#include "RNGController.h"
#include "Map.h"
#include "Step.h"
#include "Landscape.h"
#include "ActivityMap.h"
namespace necsim
{
class DispersalCoordinator
{
protected:
// Our map of dispersal probabilities (if required)
// This will contain cummulative probabilities across rows
// So dispersal is from the y cell to each of the x cells.
Map<double> dispersal_prob_map;
// This object is only used if there are multiple density maps over time.
Map<double> raw_dispersal_prob_map;
// Our random number generator for dispersal distances
// This is a pointer so that the random number generator is the same
// across the program.
shared_ptr<RNGController> NR;
// Pointer to the landscape object for getting density values.
shared_ptr<Landscape> landscape;
// Pointer to the reproduction map object for obtaining reproduction probabilities
shared_ptr<ActivityMap> reproduction_map;
// Pointer to the generation counter for the simulation
double *generation;
// function ptr for our getDispersal function
typedef void (DispersalCoordinator::*dispersal_fptr)(Step &this_step);
dispersal_fptr doDispersal;
// Function pointer for end checks
typedef bool (DispersalCoordinator::*end_fptr)(const unsigned long &density,
long &oldx,
long &oldy,
long &oldxwrap,
long &oldywrap,
const long &startx,
const long &starty,
const long &startxwrap,
const long &startywrap);
// once setup will contain the end check function to use for this simulation.
end_fptr checkEndPointFptr;
unsigned long xdim;
unsigned long ydim;
bool full_dispersal_map;
public:
DispersalCoordinator();
~DispersalCoordinator();
void setRandomNumber(shared_ptr<RNGController> NR_ptr);
bool isFullDispersalMap() const;
void setMaps(const shared_ptr<Landscape> &landscape_ptr, shared_ptr<ActivityMap> repr_map_ptr);
void setMaps(const shared_ptr<Landscape> &landscape_ptr);
void setGenerationPtr(double *generation_ptr);
void setDispersal(const string &dispersal_method,
const string &dispersal_file,
const unsigned long &dispersal_x,
const unsigned long &dispersal_y,
const double &m_probin,
const double &cutoffin,
const double &sigmain,
const double &tauin,
const bool &restrict_self);
void setDispersal(shared_ptr<SimParameters> simParameters);
void importDispersal(const unsigned long &dispersal_dim, const string &dispersal_file);
void setRawDispersalMap();
void addDensity();
void addReproduction();
void fixDispersal();
void fixDispersalRow(unsigned long row);
bool checkDispersalRow(unsigned long row);
void verifyDispersalMapDensity();
void verifyDispersalMapSetup();
void updateDispersalMap();
#ifdef DEBUG
void assertReferenceMatches(unsigned long expected);
void validateNoSelfDispersalInDispersalMap();
#endif // DEBUG
void disperseNullDispersalMap(Step &this_step);
void disperseDispersalMap(Step &this_step);
void calculateCellCoordinates(Step &this_step, const unsigned long &col_ref);
unsigned long calculateCellReference(Step &this_step) const;
unsigned long calculateCellIndex(const Cell &cell) const;
void disperseDensityMap(Step &this_step);
void disperseNearestHabitat(Step &this_step);
void setEndPointFptr(const bool &restrict_self);
bool checkEndPoint(const unsigned long &density,
long &oldx,
long &oldy,
long &oldxwrap,
long &oldywrap,
const long &startx,
const long &starty,
const long &startxwrap,
const long &startywrap);
bool checkEndPointDensity(const unsigned long &density,
long &oldx,
long &oldy,
long &oldxwrap,
long &oldywrap,
const long &startx,
const long &starty,
const long &startxwrap,
const long &startywrap);
bool checkEndPointRestricted(const unsigned long &density,
long &oldx,
long &oldy,
long &oldxwrap,
long &oldywrap,
const long &startx,
const long &starty,
const long &startxwrap,
const long &startywrap);
bool checkEndPointDensityReproduction(const unsigned long &density,
long &oldx,
long &oldy,
long &oldxwrap,
long &oldywrap,
const long &startx,
const long &starty,
const long &startxwrap,
const long &startywrap);
bool checkEndPointDensityRestrictedReproduction(const unsigned long &density,
long &oldx,
long &oldy,
long &oldxwrap,
long &oldywrap,
const long &startx,
const long &starty,
const long &startxwrap,
const long &startywrap);
void disperse(Step &this_step);
double getSelfDispersalValue(const Cell &cell) const;
double sumDispersalValues(const Cell &cell) const;
void reimportRawDispersalMap();
void removeSelfDispersal();
};
}
#endif // DISPERSAL_H