merge successful with staging
[biocity.git] / src / World_scenarios_base.cpp
blob97eccc83d6c9743ef643d830b3d99a7d7bb9c610
1 /*
2 * Definition of base package of scenarios
3 */
5 #include "FuncSelect.hh"
7 void World::scen_single_pop_init( )
9 using single_pop::movement_circle;
11 using single_pop::reproduction;
12 using single_pop::range;
14 using single_pop::dist_life;
15 using single_pop::life_a;
16 using single_pop::life_b;
17 using single_pop::life_c;
19 using single_pop::repr_inhibit;
21 ConfReader conf( "scenarios/scen_single_pop.conf" );
22 if ( conf.success() )
24 conf.field_double( "movement_circle", &movement_circle);
26 conf.field_double( "reproduction", &reproduction );
27 conf.field_double( "range", &range);
28 conf.field_string( "dist_life", &dist_life);
29 conf.field_double( "life_a", &life_a);
30 conf.field_double( "life_b", &life_b);
31 conf.field_double( "life_c", &life_c);
33 conf.field_int( "repr_inhibit", &repr_inhibit );
36 cout<<"#dist_life: "<< dist_life<<endl;
39 void World::scen_single_pop( )
41 using namespace single_pop;
43 double currx,curry,rx,ry;
44 calc_proximity( range );
45 list<Organism*>::iterator i1 = citizens.begin();
47 int type1,type2;
48 for ( int i = 0; i < population; i++ )
50 unif_circle( &rx, &ry, rgen);
51 rx*=movement_circle;
52 ry*=movement_circle;
54 currx = (*i1)->get_x();
55 curry = (*i1)->get_y();
56 if ( currx + rx > dim_x || currx + rx < 0 ) { rx *= -1; }
57 if ( curry + ry > dim_y || curry + ry < 0 ) { ry *= -1; }
59 (*i1)->change_pos( currx + rx, curry + ry);
61 i1++;
64 //Begin: Reproduction Loop
65 i1 = citizens.begin();
66 double will_reproduce;
67 int curr_pop = population;
68 for ( int i = 0 ; i < curr_pop; i++)
70 int currtype = (*i1)->get_type();
71 will_reproduce = gsl_rng_uniform( rgen );
72 double test_cond = reproduction/
73 (1 + repr_inhibit*(*i1)->get_proximity() );
75 if (will_reproduce < test_cond )
77 (*i1)->set_offspring( 1 );
79 i1++;
81 //END: Reproduction Loop
83 // See if any citizens are on the verge
84 // of dying.
85 i1 = citizens.begin( );
86 double death = 0;
87 double death_prob = 0;
88 double death_params[4];
89 int death_params_len = 4;
90 while ( i1 != citizens.end() )
92 if ( (*i1)->get_state() == 1 )
94 death_params[0] = (*i1)->get_age();
95 death_params[1] = life_a;
96 death_params[2] = life_b;
97 death_params[3] = life_c;
98 FuncSelect death_dist( dist_life, death_params, death_params_len, NULL );
99 death = death_dist.evaluate();
100 death_prob = gsl_rng_uniform( rgen );
101 if (death_prob < death )
103 (*i1)->set_state( 0 );
106 i1++;