diff --git a/graphcode b/graphcode index 9840bc6..b4205ab 160000 --- a/graphcode +++ b/graphcode @@ -1 +1 @@ -Subproject commit 9840bc60ebfe254951d8ffcfffcabd86cfea6005 +Subproject commit b4205abf9fddd01dcb417b073b652e9ff83e456f diff --git a/include/Makefile b/include/Makefile index 6fc9807..8ecc6cd 100644 --- a/include/Makefile +++ b/include/Makefile @@ -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 diff --git a/models/ecolab_model.cc b/models/ecolab_model.cc index fda3ae4..7d1bf38 100644 --- a/models/ecolab_model.cc +++ b/models/ecolab_model.cc @@ -102,7 +102,7 @@ void EcolabPoint::condense(const array& mask, size_t mask_true) void ModelData::condense(const array& mask, size_t mask_true) /* remove extinct species */ { auto map = enumerate( mask ); - auto mask_off = mask[ interaction.row ] && mask[ interaction.col ]; + array mask_off = mask[ interaction.row ] && mask[ interaction.col ]; create = pack(create, mask, mask_true); species = pack(species, mask, mask_true); @@ -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); } diff --git a/models/ecolab_model.h b/models/ecolab_model.h index 9b2e3e0..fd09b2c 100644 --- a/models/ecolab_model.h +++ b/models/ecolab_model.h @@ -16,10 +16,8 @@ using classdesc::Object; struct ConnectionPlot: public Object { - const array& density; - const sparse_mat& connections; - ConnectionPlot(const array& density, const sparse_mat& connections): - density(density), connections(connections) {} + array density; + sparse_mat connections; bool redraw(int x0, int y0, int width, int height) override; void requestRedraw() const {if (surface) surface->requestRedraw();} }; @@ -31,7 +29,7 @@ struct ModelData array 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; @@ -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); } @@ -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);} diff --git a/models/default_ecolab_model.py b/models/panmictic_ecolab.py similarity index 89% rename from models/default_ecolab_model.py rename to models/panmictic_ecolab.py index 6c9ca88..e30beb4 100644 --- a/models/default_ecolab_model.py +++ b/models/panmictic_ecolab.py @@ -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 @@ -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) diff --git a/models/pred-prey.py b/models/pred-prey.py index 152a4f1..b7d2d4c 100644 --- a/models/pred-prey.py +++ b/models/pred-prey.py @@ -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])