Skip to content

Commit 88c189e

Browse files
Correct the random scaling on salt generation.
Enable high migration adjustment.
1 parent 691f272 commit 88c189e

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

models/ecolab_model.cc

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ void SpatialModel::generate(unsigned niter)
636636
unsigned SpatialModel::migrate()
637637
{
638638
/* each cell gets a distinct random salt value */
639-
hostForAll([=,this](EcolabCell& c) {c.salt=c.rand();});
639+
hostForAll([=,this](EcolabCell& c) {c.salt=Float(c.rand()-c.rand.min())/(c.rand.max()-c.rand.min());});
640640

641641
prepareNeighbours();
642642

@@ -660,37 +660,36 @@ unsigned SpatialModel::migrate()
660660
auto& nbr=*n->as<EcolabCell>();
661661
Float salt=c.id<nbr.id? c.salt: nbr.salt;
662662
array<Float> m=(tstep-last_mig_tstep) * migration * (nbr.density - c.density);
663-
delta[c.idx()]+=m + array<Float>((m!=0.0)*(2*(m>0.0)-1)) * salt;
663+
delta[c.idx()]+=m+ array<Float>((m!=0.0)*(2*(m>0.0)-1)) * salt;
664664
}
665665
});
666666

667667
array<int> ssum(species.size(),0);
668668
size_t totalMigration=0;
669669
hostForAll([&,this](EcolabCell& c) {
670-
// // adjust delta so that density remains +ve
671-
// array<int> adjust=delta[c.idx()]+c.density;
672-
// adjust*=-(adjust<0);
673-
// if (sum(adjust)>0)
674-
// {
675-
// // distribute adjust among neighbours
676-
// array<int> totalDiff(c.density.size(),0);
677-
// for (auto& n: c)
678-
// {
679-
// auto& nbr=*n->as<EcolabCell>();
680-
// totalDiff+=nbr.density-c.density;
681-
// }
682-
// // adjust adjust to be divisible by totalDiff
683-
// adjust-=adjust%totalDiff;
684-
// for (auto& n: c)
685-
// {
686-
// auto& nbr=*n->as<EcolabCell>();
687-
// delta[nbr.idx()]+=((nbr.density-c.density)/totalDiff)*adjust;
688-
// }
689-
// delta[c.idx()]-=adjust;
690-
// }
691-
692-
//c.density+=delta[c.idx()];
693-
cout<<delta[c.idx()]<<endl;
670+
// adjust delta so that density remains +ve
671+
array<int> adjust=delta[c.idx()]+c.density;
672+
adjust*=-(adjust<0);
673+
if (sum(adjust)>0)
674+
{
675+
// distribute adjust among neighbours
676+
array<int> totalDiff(c.density.size(),0);
677+
for (auto& n: c)
678+
{
679+
auto& nbr=*n->as<EcolabCell>();
680+
totalDiff+=nbr.density-c.density;
681+
}
682+
// adjust adjust to be divisible by totalDiff
683+
adjust-=adjust%totalDiff;
684+
for (auto& n: c)
685+
{
686+
auto& nbr=*n->as<EcolabCell>();
687+
delta[nbr.idx()]+=((nbr.density-c.density)/totalDiff)*adjust;
688+
}
689+
delta[c.idx()]-=adjust;
690+
}
691+
692+
c.density+=delta[c.idx()];
694693
totalMigration+=sum(abs(delta[c.idx()]));
695694
#if !defined(NDEBUG)
696695
#pragma omp critical

models/spatial_ecolab.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
array_urand.seed(10+myid())
1414

1515
# initial number of species
16-
nsp=100
16+
nsp=30
1717

1818
ecolab.repro_min(-0.1)
1919
ecolab.repro_max(0.1)
@@ -28,8 +28,8 @@ def randomList(num, min, max):
2828

2929
ecolab.species(range(nsp))
3030

31-
numX=3
32-
numY=3
31+
numX=1
32+
numY=2
3333
ecolab.setGrid(numX,numY)
3434
ecolab.partitionObjects()
3535

@@ -47,7 +47,7 @@ def randomList(num, min, max):
4747
ecolab.interaction.val(randomList(len(ecolab.interaction.val), ecolab.odiag_min(), ecolab.odiag_max()))
4848

4949
ecolab.mutation(nsp*[ecolab.mut_max()])
50-
ecolab.migration(nsp*[1e-20])
50+
ecolab.migration(nsp*[1e-3])
5151

5252
from plot import plot
5353
from GUI import gui, statusBar, windows
@@ -91,7 +91,6 @@ def step():
9191
for i in range(epoch//10000):
9292
stepImpl()
9393
if myid()==0:
94-
print(migrations)
9594
nsp=len(ecolab.species)
9695
statusBar.configure(text=f't={ecolab.tstep()} nsp:{nsp}')
9796
plot('No. species',ecolab.tstep(),nsp,200*(ecolab.tstep()%epoch<0.5*epoch))

0 commit comments

Comments
 (0)