1 /*
2  *  cGradientCount.h
3  *  Avida
4  *
5  *  Copyright 2010-2011 Michigan State University. All rights reserved.
6  *  http://avida.devosoft.org/
7  *
8  *
9  *  This file is part of Avida.
10  *
11  *  Avida is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
12  *  as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
13  *
14  *  Avida is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public License along with Avida.
18  *  If not, see <http://www.gnu.org/licenses/>.
19  *
20  *  Authors: Aaron P Wagner <apwagner@msu.edu>
21  *
22  */
23 
24 #ifndef cGradientCount_h
25 #define cGradientCount_h
26 
27 #include "cSpatialResCount.h"
28 
29 class cWorld;
30 
31 
32 class cGradientCount : public cSpatialResCount
33 {
34 private:
35   cWorld* m_world;
36 
37   // Configuration Arguments
38   int m_peakx;
39   int m_peaky;
40   int m_height;
41   int m_spread;
42   double m_plateau;
43   int m_decay;
44   int m_max_x;
45   int m_max_y;
46   int m_min_x;
47   int m_min_y;
48   double m_move_a_scaler;
49   int m_updatestep;
50   int m_halo;
51   int m_halo_inner_radius;
52   int m_halo_width;
53   int m_halo_anchor_x;
54   int m_halo_anchor_y;
55   int m_move_speed;
56   double m_plateau_inflow;
57   double m_plateau_outflow;
58   double m_cone_inflow;
59   double m_cone_outflow;
60   double m_gradient_inflow;
61   int m_is_plateau_common;
62   double m_floor;
63   int m_habitat;
64   int m_min_size;
65   int m_max_size;
66   int m_config;
67   int m_count;
68   double m_initial_plat;
69 
70   int m_geometry;
71 
72   // Internal Values
73   bool m_initial;
74 
75   double m_move_y_scaler;
76 
77   int m_counter;
78   int m_move_counter;
79   int m_topo_counter;
80   int m_movesignx;
81   int m_movesigny;
82 
83   int m_old_peakx;
84   int m_old_peaky;
85 
86   int m_halo_dir;
87   int m_changling;
88   bool m_just_reset;
89   double m_past_height;
90   double m_current_height;
91   double m_ave_plat_cell_loss;
92   double m_common_plat_height;
93   int m_skip_moves;
94   int m_skip_counter;
95   tArray<double> m_plateau_array;
96   tArray<int> m_plateau_cell_IDs;
97   tArray<int> m_wall_cells;
98 
99   double m_mean_plat_inflow;
100   double m_var_plat_inflow;
101 
102   bool m_predator;
103   double m_pred_odds;
104   int m_guarded_juvs_per_adult;
105 
106   bool m_probabilistic;
107   tArray<int> m_prob_res_cells;
108 
109   int m_min_usedx;
110   int m_min_usedy;
111   int m_max_usedx;
112   int m_max_usedy;
113 
114 public:
115   cGradientCount(cWorld* world, int peakx, int peaky, int height, int spread, double plateau, int decay,
116                  int max_x, int max_y, int min_x, int min_y, double move_a_scaler, int updatestep,
117                  int worldx, int worldy, int geometry,int halo, int halo_inner_radius, int halo_width,
118                  int halo_anchor_x, int halo_anchor_y, int move_speed, double plateau_inflow, double plateau_outflow,
119                  double cone_inflow, double cone_outflow, double gradient_inflow, int is_plateau_common,
120                  double floor, int habitat, int min_size, int max_size, int config, int count,
121                  double init_plat);
122   ~cGradientCount();
123 
124   void UpdateCount(cAvidaContext& ctx);
125   void StateAll();
126 
SetGradInitialPlat(double plat_val)127   void SetGradInitialPlat(double plat_val) { m_initial_plat = plat_val; m_initial = true; }
SetGradPeakX(int peakx)128   void SetGradPeakX(int peakx) { m_peakx = peakx; }
SetGradPeakY(int peaky)129   void SetGradPeakY(int peaky) { m_peaky = peaky; }
SetGradHeight(int height)130   void SetGradHeight(int height) { m_height = height; }
SetGradSpread(int spread)131   void SetGradSpread(int spread) { m_spread = spread; }
SetGradPlateau(double plateau)132   void SetGradPlateau(double plateau) { m_plateau = plateau; }
SetGradDecay(int decay)133   void SetGradDecay(int decay) { m_decay = decay; }
SetGradMaxX(int max_x)134   void SetGradMaxX(int max_x) { m_max_x = max_x; }
SetGradMaxY(int max_y)135   void SetGradMaxY(int max_y) { m_max_y = max_y; }
SetGradMinX(int min_x)136   void SetGradMinX(int min_x) { m_min_x = min_x; }
SetGradMinY(int min_y)137   void SetGradMinY(int min_y) { m_min_y = min_y; }
SetGradMoveScaler(double move_a_scaler)138   void SetGradMoveScaler(double move_a_scaler) { m_move_a_scaler = move_a_scaler; }
SetGradUpdateStep(int updatestep)139   void SetGradUpdateStep(int updatestep) { m_updatestep = updatestep; }
SetGradIsHalo(bool halo)140   void SetGradIsHalo(bool halo) { m_halo = halo; }
SetGradHaloInnerRad(int halo_inner_radius)141   void SetGradHaloInnerRad(int halo_inner_radius) { m_halo_inner_radius = halo_inner_radius; }
SetGradHaloWidth(int halo_width)142   void SetGradHaloWidth(int halo_width) { m_halo_width = halo_width; }
SetGradHaloX(int halo_anchor_x)143   void SetGradHaloX(int halo_anchor_x) { m_halo_anchor_x = halo_anchor_x; }
SetGradHaloY(int halo_anchor_y)144   void SetGradHaloY(int halo_anchor_y) { m_halo_anchor_y = halo_anchor_y; }
SetGradMoveSpeed(int move_speed)145   void SetGradMoveSpeed(int move_speed) { m_move_speed = move_speed; }
SetGradPlatInflow(double plateau_inflow)146   void SetGradPlatInflow(double plateau_inflow) { m_plateau_inflow = plateau_inflow; }
SetGradPlatOutflow(double plateau_outflow)147   void SetGradPlatOutflow(double plateau_outflow) { m_plateau_outflow = plateau_outflow; }
SetGradConeInflow(double cone_inflow)148   void SetGradConeInflow(double cone_inflow) { m_cone_inflow = cone_inflow; }
SetGradConeOutflow(double cone_outflow)149   void SetGradConeOutflow(double cone_outflow) { m_cone_outflow = cone_outflow; }
SetGradientInflow(double gradient_inflow)150   void SetGradientInflow(double gradient_inflow) { m_gradient_inflow = gradient_inflow; }
SetGradPlatIsCommon(bool is_plateau_common)151   void SetGradPlatIsCommon(bool is_plateau_common) { m_is_plateau_common = is_plateau_common; }
SetGradFloor(double floor)152   void SetGradFloor(double floor) { m_floor = floor; }
SetGradHabitat(int habitat)153   void SetGradHabitat(int habitat) { m_habitat = habitat; }
SetGradMinSize(int min_size)154   void SetGradMinSize(int min_size) { m_min_size = min_size; }
SetGradMaxSize(int max_size)155   void SetGradMaxSize(int max_size) { m_max_size = max_size; }
SetGradConfig(int config)156   void SetGradConfig(int config) { m_config = config; }
SetGradCount(int count)157   void SetGradCount(int count) { m_count = count; }
158 
159   void SetGradPlatVarInflow(double mean, double variance, int type);
160 
161   void SetPredatoryResource(double odds, int juvsper);
162   void UpdatePredatoryRes(cAvidaContext& ctx);
163 
164   void SetProbabilisticResource(cAvidaContext& ctx, double initial, double inflow, double outflow, double lambda, double theta, int x, int y, int num_cells);
165   void BuildProbabilisticRes(cAvidaContext& ctx, double lambda, double theta, int x, int y, int num_cells);
166   void UpdateProbabilisticRes();
167 
168   void ResetGradRes(cAvidaContext& ctx, int worldx, int worldy);
169 
GetWallCells()170   tArray<int>* GetWallCells() { return &m_wall_cells; }
GetMinUsedX()171   int GetMinUsedX() { return m_min_usedx; }
GetMinUsedY()172   int GetMinUsedY() { return m_min_usedy; }
GetMaxUsedX()173   int GetMaxUsedX() { return m_max_usedx; }
GetMaxUsedY()174   int GetMaxUsedY() { return m_max_usedy; }
175 
176 private:
177   void fillinResourceValues();
178   void updatePeakRes(cAvidaContext& ctx);
179   void moveRes(cAvidaContext& ctx);
180   int setHaloPeakMovement(cAvidaContext& ctx, int current_orbit);
181   void setPeakMoveMovement(cAvidaContext& ctx);
182   void moveHaloPeak(int current_orbit);
183   void movePeak();
184   void generatePeak(cAvidaContext& ctx);
185   void getCurrentPlatValues();
186   void generateBarrier(cAvidaContext& ctx);
187   void generateHills(cAvidaContext& ctx);
188   void updateBounds(int x, int y);
189   void resetUsedBounds();
190   void clearExistingProbRes();
191 };
192 
193 #endif
194