Skip to content

Commit

Permalink
Panmictic model now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
highperformancecoder committed Jul 22, 2024
1 parent 1f05534 commit 4b78ce3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion graphcode
Submodule graphcode updated 1 files
+7 −3 graphcode.h
1 change: 1 addition & 0 deletions include/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ endif
# do it this way to help Makefile dependencies work
ECOLIBS=$(ECOLAB_HOME)/lib/libecolab$(ECOLIBS_EXT).a

# why is boost_thread required here?
LIBS+=-L$(ECOLAB_HOME)/lib -lecolab$(ECOLIBS_EXT) -lboost_thread
FLAGS+=-I. -I$(ECOLAB_HOME)/include -DHASH_TCL_hash

Expand Down
6 changes: 3 additions & 3 deletions models/ecolab_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void EcolabPoint::condense(const array<bool>& mask, size_t mask_true)
void ModelData::condense(const array<bool>& mask, size_t mask_true) /* remove extinct species */
{
auto map = enumerate( mask );
auto mask_off = mask[ interaction.row ] && mask[ interaction.col ];
array<bool> mask_off = mask[ interaction.row ] && mask[ interaction.col ];

create = pack(create, mask, mask_true);
species = pack(species, mask, mask_true);
Expand All @@ -124,9 +124,9 @@ void PanmicticModel::condense()
{
auto mask=density != 0;
size_t mask_true=sum(mask);
if (species.size()==mask_true) return; /* no change ! */
EcolabPoint::condense(mask, mask_true);
if (mask.size()==mask_true) return; /* no change ! */
ModelData::condense(mask,mask_true);
EcolabPoint::condense(mask, mask_true);
}


Expand Down
17 changes: 10 additions & 7 deletions models/ecolab_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ using classdesc::Object;

struct ConnectionPlot: public Object<ConnectionPlot, CairoSurface>
{
const array<int>& density;
const sparse_mat& connections;
ConnectionPlot(const array<int>& density, const sparse_mat& connections):
density(density), connections(connections) {}
array<int> density;
sparse_mat connections;
bool redraw(int x0, int y0, int width, int height) override;
void requestRedraw() const {if (surface) surface->requestRedraw();}
};
Expand All @@ -31,7 +29,7 @@ struct ModelData
array<double> repro_rate, mutation, migration;
sparse_mat interaction;
sparse_mat_graph foodweb;
unsigned long long tstep=1, last_mut_tstep=0, last_mig_tstep=0;
unsigned long long tstep=0, last_mut_tstep=0, last_mig_tstep=0;
//mutation parameters
float sp_sep=0.1, mut_max=0, repro_min=0, repro_max=1, odiag_min=0, odiag_max=1;

Expand All @@ -41,7 +39,7 @@ struct ModelData
species=pcoord(nsp);

// bugger you, g++!
if (!/*model_data::*/create.size()) /*model_data::*/create.resize(species.size(),0);
if (!/*ModelData::*/create.size()) /*ModelData::*/create.resize(species.size(),0);
if (!mutation.size()) mutation.resize(species.size(),0);
if (!migration.size()) migration.resize(species.size(),0);
}
Expand All @@ -66,7 +64,12 @@ struct EcolabPoint

struct PanmicticModel: public ModelData, public EcolabPoint
{
ConnectionPlot connectionPlot{density,interaction};
ConnectionPlot connectionPlot;
void updateConnectionPlot() {
connectionPlot.density=density;
connectionPlot.connections=interaction;
connectionPlot.requestRedraw();
}
void makeConsistent() {ModelData::makeConsistent(density.size());}
void generate(unsigned niter);
void generate() {generate(1);}
Expand Down
7 changes: 4 additions & 3 deletions models/default_ecolab_model.py → models/panmictic_ecolab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ecolab_model import ecolab
from ecolab_model import panmictic_ecolab as ecolab
from random import random
# initial number of species
nsp=100
Expand Down Expand Up @@ -33,19 +33,20 @@ def randomList(num, min, max):
from ecolab import ecolabHome
connectionPlot=Tk()
connectionPlot.eval('load '+ecolabHome()+'/lib/ecolab.so')
connectionPlot.eval('image create cairoSurface connectionCanvas -surface ecolab_model ecolab.connectionPlot')
connectionPlot.eval('image create cairoSurface connectionCanvas -surface ecolab_model panmictic_ecolab.connectionPlot')
ttk.Label(connectionPlot, image='connectionCanvas').pack()
windows.append(ref(connectionPlot))
ecolab.updateConnectionPlot()

def step():
ecolab.generate()
ecolab.mutate()
ecolab.updateConnectionPlot()
ecolab.condense()
nsp=len(ecolab.species)
statusBar.configure(text=f't={ecolab.tstep()} nsp:{nsp}')
plot('No. species',ecolab.tstep(),nsp)
penPlot('Density',ecolab.tstep(),ecolab.density()._properties, ecolab.species()._properties)
ecolab.connectionPlot.requestRedraw()

gui(step)

Expand Down
2 changes: 1 addition & 1 deletion models/pred-prey.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ecolab_model import ecolab
from ecolab_model import panmictic_ecolab as ecolab
ecolab.species([1,2])
ecolab.density([100,100])
ecolab.create([0,0])
Expand Down

0 comments on commit 4b78ce3

Please sign in to comment.