|
2 | 2 | from mobspy import modules
|
3 | 3 |
|
4 | 4 | if __name__ == '__main__':
|
5 |
| - from mobspy import * |
6 | 5 |
|
7 |
| - |
8 |
| - # Replace parameters using units |
9 |
| - Color, Location = BaseSpecies() |
10 |
| - Color.red, Color.blue |
11 |
| - Location.here, Location.there |
12 |
| - Something = Color*Location |
13 |
| - |
14 |
| - 2*Something >> 3*Something [lambda r1, r2: 1*u.decimeter**2/u.h if Location(r1) == Location(r2) else 0.5*u.decimeter**2/u.h] |
15 |
| - |
16 |
| - S = Simulation(Something) |
17 |
| - S.volume = 1*u.m**2 |
18 |
| - print(S.compile()) |
19 |
| - |
20 |
| - # print(A.get_characteristics()) |
| 6 | + A = BaseSpecies() |
| 7 | + p1, p2 = ModelParameters([1], [1 / u.hour, 2 / u.hour, 3 / u.hour]) |
| 8 | + A >> Zero[p1 * p2] |
| 9 | + A(100) |
| 10 | + S = Simulation(A) |
| 11 | + S.run(duration=5 * u.hour, plot_data=False, level=-1) |
| 12 | + print(S.results) |
| 13 | + |
| 14 | + exit() |
| 15 | + |
| 16 | + """ |
| 17 | + This is the Tree model from the paper |
| 18 | + We have a population of Trees |
| 19 | + The Trees can die, age, have different colors and be in two different forests |
| 20 | + The colors can change randomly from time to time |
| 21 | + All old Trees can reproduce, but the Three is born green and young |
| 22 | + """ |
| 23 | + Ager, Mortal, Colored, Location = BaseSpecies() |
| 24 | + Colored.green, Colored.yellow, Colored.brown |
| 25 | + Location.dense, Location.sparse |
| 26 | + Ager.young >> Ager.old[1 / 10 / u.year] |
| 27 | + Mortal >> Zero [lambda r1: 0.1 / u.year if r1.old else 0] |
| 28 | + Tree = Ager * Colored * Mortal * Location |
| 29 | + |
| 30 | + # replication |
| 31 | + Tree.old >> Tree + Tree.green.young[0.1/u.year] |
| 32 | + |
| 33 | + # competition |
| 34 | + Tree.dense.old + Tree.dense.young >> Tree.dense.old[1e-10 * u.decimeter ** 2 / u.year] |
| 35 | + |
| 36 | + # reproduction |
| 37 | + bf = 1e-10 * u.decimeter ** 2 / u.year |
| 38 | + rep_r = lambda t1, t2: 5 * bf if (Location(t1) == Location(t2) and Colored(t1) == Colored(t2)) else bf |
| 39 | + 2 * Tree >> 2 * Tree + Tree.yound[rep_r] |
| 40 | + |
| 41 | + # color cycling |
| 42 | + colors = ['green', 'yellow', 'brown'] |
| 43 | + for color, next_color in zip(colors, colors[1:] + colors[:1]): |
| 44 | + Tree.c(color) >> Tree.c(next_color)[10/u.year] |
| 45 | + |
| 46 | + # initial conditions |
| 47 | + Tree.dense(50), Tree.dense.old(50), Tree.sparse(50), Tree.sparse.old(50) |
| 48 | + # initial conditions |
| 49 | + Tree.dense(50), Tree.dense.old(50), Tree.sparse(50), Tree.sparse.old(50) |
| 50 | + MySim = Simulation(Tree) |
| 51 | + MySim.run(volume = 1 * u.meter ** 2, unit_x='year', |
| 52 | + duration=100 * u.years, repetitions=3, output_concentration=False, |
| 53 | + simulation_method='stochastic', save_data=False, plot_data=False) |
| 54 | + MySim.plot_stochastic(Tree.dense, Tree.sparse, Tree.brown) |
21 | 55 |
|
22 | 56 |
|
0 commit comments