diff --git a/models/default_ecolab_model.py b/models/default_ecolab_model.py index 5506577..6c9ca88 100644 --- a/models/default_ecolab_model.py +++ b/models/default_ecolab_model.py @@ -26,7 +26,16 @@ def randomList(num, min, max): ecolab.migration(nsp*[1e-5]) from plot import plot, penPlot -from GUI import gui, statusBar +from GUI import gui, statusBar, windows + +from tkinter import Tk,ttk +from weakref import ref +from ecolab import ecolabHome +connectionPlot=Tk() +connectionPlot.eval('load '+ecolabHome()+'/lib/ecolab.so') +connectionPlot.eval('image create cairoSurface connectionCanvas -surface ecolab_model ecolab.connectionPlot') +ttk.Label(connectionPlot, image='connectionCanvas').pack() +windows.append(ref(connectionPlot)) def step(): ecolab.generate() @@ -36,7 +45,8 @@ def step(): 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/ecolab_model.cc b/models/ecolab_model.cc index 7e3a931..d72d9eb 100644 --- a/models/ecolab_model.cc +++ b/models/ecolab_model.cc @@ -21,6 +21,8 @@ using array_ns::pcoord; #include "ecolab_model.h" #include "pythonBuffer.h" #include "plot.h" + +#include "object.cd" #include "ecolab_model.cd" #include "ecolab_epilogue.h" @@ -306,3 +308,64 @@ array ecolab_model::lifetimes() } +bool ConnectionPlot::redraw(int x0, int y0, int width, int height) +{ + if (!surface) return false; + const double scale=4; + int low_colour, high_colour; + auto& row=connections.row; + auto& col=connections.col; + ecolab::array enum_clusters(connections.diag.size()); + enum_clusters=1; + enum_clusters=enumerate(enum_clusters); + for (unsigned i=0; i map(density.size()), mask; + map=-1; + for (int i=0; i<=max(enum_clusters); i++) + { + mask = enum_clusters==i; + map = merge( mask, enumerate(mask)+max(map)+1, map); + } + + auto cairo=surface->cairo(); + for (unsigned i=0; i - +#include using classdesc::Object; /* ecolab cell */ @@ -53,6 +53,16 @@ struct model_data: public ecolab_point sparse_mat_graph foodweb; }; +struct ConnectionPlot: public Object +{ + const array& density; + const sparse_mat& connections; + ConnectionPlot(const array& density, const sparse_mat& connections): + density(density), connections(connections) {} + bool redraw(int x0, int y0, int width, int height) override; + void requestRedraw() const {if (surface) surface->requestRedraw();} +}; + class ecolab_model: public model_data { void mutate_model(array); @@ -65,6 +75,8 @@ class ecolab_model: public model_data //mutation parameters float sp_sep, mut_max, repro_min, repro_max, odiag_min, odiag_max; + ConnectionPlot connectionPlot{density,interaction}; + ecolab_model() {repro_min=0; repro_max=1; mut_max=0; odiag_min=0; odiag_max=1; tstep=0; last_mut_tstep=0; last_mig_tstep=0;}