Changeset 421 for experiments


Ignore:
Timestamp:
08/03/15 12:06:54 (9 years ago)
Author:
oriona
Message:

refactoring, removed unused params, creatures and food chanfe to forams and nutirents

Location:
experiments/frams/foraminifera/data/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • experiments/frams/foraminifera/data/scripts/foraminifera.expdef

    r418 r421  
    66user1:
    77genes which are not encoded in Ff genotype:
    8 Vamin - Minimum stored energy necessary for reproduction
    9 amin - minimal age for reproduction
     8minenergy - Minimum stored energy necessary for reproduction
     9minage - minimal age for reproduction
    1010
    1111user2:
     
    2020- xxx.get(...) changed to xxx[...]
    2121- xxx.set(...,...) changed to xxx[...]=...
    22 - function placeRandomlyNotColliding(cr) explicitly called when adding a new creature, and removed collision checking from onCreaturesBorn() which is also called when "growing" (since "growing" is implemented as creating a new creature in place of the old one, so onCreaturesBorn() is also called)
     22- function placeRandomlyNotColliding(cr) explicitly called when adding a new creature, and removed collision checking from onForamsBorn() which is also called when "growing" (since "growing" is implemented as creating a new creature in place of the old one, so onForamsBorn() is also called)
    2323- use creature's center (not the bbox corner) when growing
    2424- added "S" receptor to visualize the difference between diplo and haplo generations
     
    2626*/
    2727
    28 global foodenergywaiting;
     28global nutrientenergywaiting;
    2929global reprocounter;
    3030
     
    3535function onExpDefLoad()
    3636{
    37 
    3837        // define genotype and creature groups
    3938        GenePools.clear();
     
    4443
    4544        var pop = Populations[0];
    46         pop.name = "Creatures";
     45        pop.name = "Forams";
    4746        pop.en_assim = 0;
    4847        pop.nnsim = 0;
     
    5554        pop.perfperiod = 25;
    5655
    57         pop = Populations.addGroup("Food");
     56        pop = Populations.addGroup("Nutrients");
    5857        pop.nnsim = 0;
    5958        pop.enableperf = 0;
     
    6362        pop.othermask = 0x10000;
    6463
    65         //TODO remove unused params
    66 
    6764        //radius of the chamber
    6865        ExpParams.rads = [1.2, 0.6];
    69         //ExpParams.rads = [2, 2];
    7066        //inital genotypes
    71         ExpParams.genh = "//0\np:sh=1,sx=" + ExpParams.rads[0] + ",sy=" + ExpParams.rads[0] + ",sz=" + ExpParams.rads[0] + ", rz=3.14159265358979";
    72         ExpParams.gend = "//0\np:sh=1,sx=" + ExpParams.rads[1] + ",sy=" + ExpParams.rads[1] + ",sz=" + ExpParams.rads[1] + ", rz=3.14159265358979";
    73         ExpParams.gend += "\nn:p=0,d=\"S\"";
     67        ExpParams.genh = createForamGenotype(ExpParams.rads[0]);
     68        ExpParams.gend = createForamGenotype(ExpParams.rads[1])+"\nn:p=0,d=\"S\"";
     69        ExpParams.creath = -0.99; //just above the bottom
    7470        ExpParams.e_meta = 0.1;
    7571        ExpParams.feedrate = 0.5;
    7672        ExpParams.feede0 = 100;
    7773        ExpParams.feedtrans = 3;
    78         ExpParams.creath = -0.99; //just above the bottom
    79         ExpParams.foodgen = "//0\np:sh=2,sx=0.1,sy=0.1,sz=0.1\nn:d=T,p=0"; //TODO food size as param
     74        ExpParams.nutrientsize = 0.1;
     75        ExpParams.nutrientgen = "//0\np:sh=2,sx="+ExpParams.nutrientsize+",sy="+ExpParams.nutrientsize+",sz="+ExpParams.nutrientsize+"\nn:d=T,p=0";
    8076        ExpParams.autorestart = 0;
    81         ExpParams.psize = 10;
     77        ExpParams.popsize = 10;
    8278        //ExpParams.logging = 1; //uncomment to enable logging simulation parameters to log files
    8379
    8480        //number of offspring
    85         ExpParams.ofnumh = 40;
    86         ExpParams.ofnumd = 25;
     81        ExpParams.energy0h = 40;
     82        ExpParams.energy0d = 25;
    8783        //minial volume for reproduction
    88         ExpParams.v_min_d = 300;
    89         ExpParams.v_min_h = 300;
     84        ExpParams.minenerg = [300, 300];
    9085        //minimal age for reproduction
    91         ExpParams.age_min_d = 100;
    92         ExpParams.age_min_h = 100;
     86        ExpParams.minage = [100, 100];
    9387        //crossover probability
    9488        ExpParams.crossprob = 0.4;
    9589        //mutation probability
    9690        ExpParams.mutationprob = 0.2;
    97         ExpParams.repro_time = 200;
    98         ExpParams.repro_thr = 1;
    99 
    100         //grwoth speed in time steps
    101         ExpParams.growth_step = 50; //50
     91        ExpParams.repro_time = 45;
     92
     93        //grwoth speed in simulation steps
     94        ExpParams.growth_step = 50;
    10295
    10396        ExpState.totaltestedcr = 0;
    104         ExpState.food = "";
    105         foodenergywaiting = ExpParams.feede0;
     97        ExpState.nutrient = "";
     98        nutrientenergywaiting = ExpParams.feede0;
    10699        reprocounter = 0;
    107100
    108         ExpParams.wsize = 50;
     101        ExpParams.worldsize = 50;
    109102        World.wrldwat = 50;
    110         World.wrldsiz = ExpParams.wsize;
     103        World.wrldsiz = ExpParams.worldsize;
    111104        World.wrldbnd = 1;
    112105}
     
    119112        Populations[1].clear();
    120113
    121         for (var i = 0; i < ExpParams.psize; i++)
     114        for (var i = 0; i < ExpParams.popsize; i++)
    122115        {
    123116                var cr = Populations[0].add(ExpParams.genh);
    124117                cr.name = "Initial creature" + i;
    125118                placeCreatureRandomly(cr, 0, 0);
    126                 cr.energy0 = ExpParams.v_min_h - ExpParams.repro_thr;
     119                cr.energy0 = ExpParams.energy0h;
    127120                cr.energy = cr.energy0;
    128                 cr.user1 = {"vamin" : ExpParams.v_min_h, "amin": ExpParams.age_min_h};
    129                 cr.user2 = {"Va" : ExpParams.v_min_h - ExpParams.repro_thr, "gen" : 0, "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit" : ExpParams.v_min_h - ExpParams.repro_thr};
     121                cr.user1 = {"minenergy" : ExpParams.minenerg[0], "minage": ExpParams.minage[0]};
     122                cr.user2 = {"Va" : ExpParams.energy0h, "gen" : 0, "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit" : ExpParams.energy0h};
    130123        }
    131124        ExpState.totaltestedcr = 0;
    132         foodenergywaiting = ExpParams.feede0;
     125        nutrientenergywaiting = ExpParams.feede0;
    133126}
    134127
     
    142135        Loader.run();
    143136
    144         Simulator.print("Loaded " + Populations[0].size + " creatures and " + Populations[1].size + " food objects");
     137        Simulator.print("Loaded " + Populations[0].size + " Forams and " + Populations[1].size + " nutrient objects");
    145138}
    146139
     
    186179                tmpvec.add([cr.center_x, cr.center_y, cr.energy]);
    187180
    188         ExpState.food = tmpvec;
     181        ExpState.nutrient = tmpvec;
    189182        File.writeObject(sim_params.*);
    190         ExpState.food = null; //vectors are only created for saving and then discarded
     183        ExpState.nutrient = null; //vectors are only created for saving and then discarded
    191184
    192185        for (var cr in Populations[0])
     
    196189// -------------------------------- experiment end --------------------------------
    197190
    198 // -------------------------------- creature begin --------------------------------
    199 
    200 function onCreaturesBorn(cr)
     191// -------------------------------- foram begin -----------------------------------
     192
     193function createForamGenotype(radius)
     194{
     195        return "//0\np:sh=1,sx=" + radius + ",sy=" + radius + ",sz=" + radius + ", rz=3.14159265358979";
     196}
     197
     198function onForamsBorn(cr)
    201199{
    202200        cr.idleen = ExpParams.e_meta;
     
    222220}
    223221
    224 function onCreaturesStep(cr)
     222function foramMove(cr)
    225223{
    226224        //TODO moving inside sediment?
    227225        cr.moveAbs(cr.pos_x, cr.pos_y, 0); //adjustment in z axis
     226
    228227        var p = cr.getMechPart(0);
    229         var n = cr.signals.receiveSet("food", ExpParams.food_range);
     228        var n = cr.signals.receiveSet("nutrient", ExpParams.nutrient_range);
    230229
    231230        //if signals are received find the source of the nearest
     
    262261                cr.localDrive = (0.1 * Math.rnd01, 0.1 * Math.rnd01, 0);
    263262        }
     263}
     264
     265function foramGrow(cr)
     266{
     267                //TODO how size is related to the energy?
     268                cr.user2["rsize"] = ExpParams.rads[cr.user2["gen"]] * Math.min(Math.max(float(cr.user2["Va"] / cr.user2["vinit"]) * 0.5, 1.0), 2.5);
     269                var geno = createForamGenotype(cr.user2["rsize"]);
     270                if (cr.user2["gen"] == 1)
     271                {
     272                        geno += "\nn:p=0,d=\"S\""; //TODO why initial genotypes are not used as defined in ExpParams?
     273                        //TODO maybe it would be nice if they rotated so the "S" would show where they are going (direction/intention)
     274                }
     275                var cr2 = Populations[0].add(geno);
     276                cr2.energy0 = cr.energy;
     277                cr2.energy = cr2.energy0;
     278                setGenotype(cr2, cr.user1, cr.user2);
     279                cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
     280
     281                Populations[0].delete(cr);
     282}
     283
     284function onForamsStep(cr)
     285{
     286        foramMove(cr);
    264287
    265288        //energy costs depend on size
     
    270293        }
    271294
     295        //TODO lifespan should not be used, it is set to 0 with every growth_step
    272296        if (cr.lifespan >= ExpParams.max_age)
    273297        {
    274                 //TODO what is max age value? should there be one?
    275                 Populations[0].kill(cr);
    276                 return;
     298                //TODO what is max age value? should there be one
     299                //Populations[0].kill(cr);
     300                //return;
    277301        }
    278302
     
    280304        if (cr.lifespan == cr.user2["growth_step"])
    281305        {
    282                 //TODO how size is related to the energy?
    283                 cr.user2["rsize"] = ExpParams.rads[cr.user2["gen"]] * Math.min(Math.max(float(cr.user2["Va"] / cr.user2["vinit"]) * 0.5, 1.0), 2.5);
    284                 var geno = "//0\np:sh=1,sx=" + cr.user2["rsize"] + ",sy=" + cr.user2["rsize"] + ",sz=" + cr.user2["rsize"] + ", rz=3.14159265358979";
    285                 if (cr.user2["gen"] == 1)
    286                 {
    287                         geno += "\nn:p=0,d=\"S\""; //TODO why initial genotypes are not used as defined in ExpParams?
    288                         //TODO maybe it would be nice if they rotated so the "S" would show where they are going (direction/intention)
    289                 }
    290                 var cr2 = Populations[0].add(geno);
    291                 cr2.energy = cr.energy;
    292                 setGenotype(cr2, cr.user1, cr.user2);
    293                 cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
    294 
    295                 Populations[0].delete(cr);
     306                foramGrow(cr);
    296307        }
    297308        else
     
    301312                if (cr.user2["gen"] == 0)
    302313                {
    303                         properSize = cr.user2["Va"] >= cr.user1["vamin"];
     314                        properSize = cr.user2["Va"] >= cr.user1["minenergy"];
    304315                }
    305316                else
    306317                {
    307                         properSize = cr.user2["Va"] >= cr.user1[0]["vamin"]; //TODO gene selection
     318                        properSize = cr.user2["Va"] >= cr.user1[0]["minenergy"]; //TODO gene selection
    308319                }
    309320
     
    324335}
    325336
    326 function onCreaturesDied(cr)
     337function onForamsDied(cr)
    327338{
    328339        //fossilization
     
    339350        if (cr.user2["gen"] == 0)
    340351        {
    341                 cr.user1 = {"vamin" : new_user1["vamin"], "amin": new_user1["amin"] };
     352                cr.user1 = {"minenergy" : new_user1["minenergy"], "minage": new_user1["minage"] };
    342353        }
    343354        else if (cr.user2["gen"] == 1)
    344355        {
    345                 cr.user1 = [ {"vamin" : new_user1[0]["vamin"], "amin": new_user1[0]["amin"] }, {"vamin" : new_user1[1]["vamin"], "amin": new_user1[1]["amin"] }];
    346         }
    347 
    348 }
    349 
    350 // -------------------------------- creature end --------------------------------
    351 
    352 // -------------------------------- food begin --------------------------------
    353 
    354 function onFoodStep(cr)
    355 {
    356         cr.moveAbs(cr.pos_x % ExpParams.wsize, cr.pos_y % ExpParams.wsize, 0.5);
    357 }
    358 
    359 function addfood()
    360 {
    361         var cr = Populations[1].add(ExpParams.foodgen);
    362 
    363         cr.name = "Food";
     356                cr.user1 = [ {"minenergy" : new_user1[0]["minenergy"], "minage": new_user1[0]["minage"] }, {"minenergy" : new_user1[1]["minenergy"], "minage": new_user1[1]["minage"] }];
     357        }
     358
     359}
     360
     361// --------------------------------foram end -------------------------------------
     362
     363// -------------------------------- nutrient begin --------------------------------
     364
     365function onNutrientsStep(cr)
     366{
     367        cr.moveAbs(cr.pos_x % ExpParams.worldsize, cr.pos_y % ExpParams.worldsize, 0.5);
     368}
     369
     370function addNutrient()
     371{
     372        var cr = Populations[1].add(ExpParams.nutrientgen);
     373
     374        cr.name = "Nutrients";
    364375        cr.idleen = 0;
    365376        cr.energy0 = ExpParams.feede0;
    366377        cr.energy = cr.energy0;
    367         cr.signals.add("food");
     378        cr.signals.add("nutrient");
    368379
    369380        cr.signals[0].value = cr.getMechPart(0);
     
    372383}
    373384
    374 function onFoodCollision()
     385function onNutrientsCollision()
    375386{
    376387        if (Collision.Creature2.user2 != null)
     
    384395}
    385396
    386 // -------------------------------- food end --------------------------------
     397// -------------------------------- nutrient end --------------------------------
    387398
    388399
     
    410421name:Maximal age
    411422type:d 100 1000 500
    412 
    413 prop:
    414 id:wsize
     423group:Foraminifera
     424
     425prop:
     426id:worldsize
    415427name:World size
    416428type:d 10 1000 20
     
    420432name:Growth step
    421433type:d -1 10000 1000
     434group:Foraminifera
     435help:You can turn off growth by setting this param to -1
    422436
    423437prop:
     
    425439name:Haploid and diploid radius
    426440type:x
    427 
    428 prop:
    429 id:age_min_h
    430 name:Min reproduction age of haploid forams
    431 type:d 100 10000 300
    432 group:Foraminifera
    433 
    434 prop:
    435 id:age_min_d
    436 name:Min reproduction age of diploid forams
    437 type:d 100 10000 200
    438 group:Foraminifera
    439 
    440 prop:
    441 id:v_min_h
    442 name:Min reproduction energy of haploid forams
    443 type:f 10 10000 300
    444 group:Foraminifera
    445 
    446 prop:
    447 id:v_min_d
    448 name:Min reproduction energy of diploid forams
    449 type:f 10 10000 150
    450 group:Foraminifera
    451 
    452 prop:
    453 id:repro_thr
    454 name:Energy creatures need to gather to reproduce
    455 type:d 1 1000 1
    456 
    457 prop:
    458 id:food_range
    459 name:Range of food smell
     441group:Foraminifera
     442
     443prop:
     444id:minage
     445name:Min reproduction age of forams
     446type:x
     447group:Foraminifera
     448
     449prop:
     450id:minenerg
     451name:Min reproduction energy of forams
     452type:x
     453group:Foraminifera
     454
     455prop:
     456id:nutrient_range
     457name:Range of nutrient smell
    460458type:d 0 10000 10000
    461459
     
    466464
    467465prop:
    468 id:psize
    469 name:Initial population size
     466id:popsize
     467name:Initial forams population size
    470468type:d 1 1000 100
    471 
    472 prop:
    473 id:logging
    474 name:Log statistics to file
    475 type:d 0 1 0
    476 
    477 prop:
    478 id:ofnumh
     469group:Foraminifera
     470
     471prop:
     472id:energy0h
    479473name:Number of offspring from haploid forams
    480474type:d
     
    482476
    483477prop:
    484 id:ofnumd
     478id:energy0d
    485479name:Number of offspring from diploid forams
    486480type:d
     
    491485name:Probability of reproduction
    492486type:f 0 1 0.9
     487group:Foraminifera
    493488
    494489prop:
     
    496491name:Crossover probability
    497492type:f 0 1 0
     493group:Foraminifera
    498494
    499495prop:
     
    501497name:Mutation probability
    502498type:f 0 1 0
     499group:Foraminifera
    503500
    504501prop:
     
    519516type:f -1 50
    520517help:~
    521 Vertical position (above the surface) where new creatures are revived.
     518Vertical position (above the surface) where new Forams are revived.
    522519Negative values are only used in the water area:
    523520  0   = at the surface
     
    541538prop:
    542539id:feede0
    543 name:Food's energy
     540name:Nutrients's energy
    544541group:Energy
    545542type:f 0 1000
     
    552549
    553550prop:
    554 id:foodgen
    555 name:Food's genotype
     551id:nutrientgen
     552name:Nutrients's genotype
    556553group:Energy
    557554type:s 1
     555
     556prop:
     557id:nutrientsize
     558name:Nutrients's size
     559group:Energy
     560type:f 0.1
     561
     562prop:
     563id:nutrientPop
     564name:Nutrients population size
     565group:Energy
     566type:d 1 1000 10
     567
     568state:
     569id:nutrient
     570name:Nutrients locations
     571help:vector of vectors [x,y,energy]
     572type:x
     573flags:32
    558574
    559575prop:
     
    573589state:
    574590id:totaltestedcr
    575 name:Evaluated creatures
    576 help:Total number of the creatures evaluated in the experiment
     591name:Evaluated Forams
     592help:Total number of the Forams evaluated in the experiment
    577593type:d
    578594flags:16
    579595
    580596prop:
    581 id:foodPop
    582 name:Food size
    583 type:d 1 1000 10
    584 
    585 state:
    586 id:food
    587 name:Food locations
    588 help:vector of vectors [x,y,energy]
    589 type:x
    590 flags:32
     597id:logging
     598name:Log statistics to file
     599type:d 0 1 0
  • experiments/frams/foraminifera/data/scripts/foraminifera.inc

    r418 r421  
    66function reproduce_haploid(parent, parent2)
    77{
    8         var number = parent.user2["Va"] / ExpParams.ofnumd + parent2.user2["Va"] / ExpParams.ofnumd;
     8        var number = parent.user2["Va"] / ExpParams.energy0d + parent2.user2["Va"] / ExpParams.energy0d;
    99
    1010        for (var j = 0; j < number; j++)
    1111        {
    12                 createOffspring(ExpParams.gend, ExpParams.ofnumd, [parent.user1, parent2.user1], {"Va" : ExpParams.ofnumd, "gen" : 1 , "growth_step" : ExpParams.growth_step, "rsize": ExpParams.rads[1], "vinit": ExpParams.ofnumd}); //TODO genes from both generations in user1
     12                createOffspring(ExpParams.gend, ExpParams.energy0d, [parent.user1, parent2.user1], {"Va" : ExpParams.energy0d, "gen" : 1 , "growth_step" : ExpParams.growth_step, "rsize": ExpParams.rads[1], "vinit": ExpParams.energy0d}); //TODO genes from both generations in user1
    1313        }
    1414}
     
    1616function reproduce_diploid(parent)
    1717{
    18         var number = parent.user2["Va"] / ExpParams.ofnumh;
     18        var number = parent.user2["Va"] / ExpParams.energy0h;
    1919        for (var j = 0; j < number / 2; j++)
    2020        {
     
    2323                if (Math.rnd01 < ExpParams.crossprob)
    2424                {
    25                         crossover(parent, "vamin");
     25                        crossover(parent, "minenergy");
    2626                        crossed = 1;
    2727                }
     
    2929                for (var k = 0; k < 2; k++)
    3030                {
    31                         createOffspring(ExpParams.genh, ExpParams.ofnumh, {"vamin" : ExpParams.v_min_h, "amin": ExpParams.age_min_h}, {"Va" : ExpParams.ofnumh, "gen" : 0 , "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit": ExpParams.ofnumh});
     31                        createOffspring(ExpParams.genh, ExpParams.energy0h, {"minenergy" : ExpParams.minenerg[0], "minage": ExpParams.minage[0]}, {"Va" : ExpParams.energy0h, "gen" : 0 , "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit": ExpParams.energy0h}); //TODO different vamin and amin for haploids and diploids?
    3232                }
    3333
     
    3535                if (crossed == 1)
    3636                {
    37                         crossover(parent, "vamin");
     37                        crossover(parent, "minenergy");
    3838                        crossed = 0;
    3939                }
     
    6161function onStep()
    6262{
    63         var haploids = 0;
    64         var diploids = 0;
    65         var e_inc_h = 0.0;
    66         var e_inc_d = 0.0;
    67         var e_nut = 0.0;
    68         var size_h = 0.0;
    69         var size_d = 0.0;
    70         var vmin_h = 0.0;
    71         var vmin_d = 0.0;
    72 
    73         for (var i = 0; i < Populations[0].size; i++)
    74         {
    75                 var cr = Populations[0].get(i);
    76                 if (cr.user2["gen"] == 0)
    77                 {
    78                         haploids += 1;
    79                         e_inc_h += cr.energy;
    80                         size_h += ExpParams.rads[0]; //TODO change of size dependent on gene
    81                         vmin_h += cr.user1["vamin"];
    82                 }
    83                 else if (cr.user2["gen"] == 1)
    84                 {
    85                         diploids += 1;
    86                         e_inc_d += cr.energy;
    87                         size_d += ExpParams.rads[1]; //TODO change of size dependent on gene
    88                         vmin_d += cr.user1[0]["vamin"];
    89                 }
    90         }
    91 
    92         for (var i = 0; i < Populations[1].size; i++)
    93         {
    94                 var cr = Populations[1].get(i);
    95                 e_nut += cr.energy;
    96         }
    97 
    98         if (haploids < 2 && diploids == 0)
    99         {
    100                 Simulator.print("no more creatures, stopped.");
    101                 Simulator.stop();
    102         }
    103 
    104         var l1 = [haploids, diploids, Populations[1].size];
    105         var l2 = [e_inc_h, e_inc_d, e_nut];
    106         var dp = diploids;
    107         var hp = haploids;
    108         if (dp == 0) dp = 0.000001;
    109         if (hp == 0) hp = 0.000001;
    110         var l3 = [size_h / hp, vmin_h / hp, size_d / dp, vmin_d / dp];
    11163
    11264        if (ExpParams.logging == 1)
    11365        {
    114                 log(l1, "log.txt");
    115                 log(l2, "log2.txt");
    116                 log(l3, "log3.txt");
     66                createStatistics();
    11767        }
    118         //food growth ---------------------------------------------
    119         foodenergywaiting = foodenergywaiting + ExpParams.feedrate;
    120         if (foodenergywaiting > ExpParams.feede0)
     68
     69        //nutrient growth ---------------------------------------------
     70        nutrientenergywaiting = nutrientenergywaiting + ExpParams.feedrate;
     71        if (nutrientenergywaiting > ExpParams.feede0)
    12172        {
    122                 for (var i = 0; i < ExpParams.foodPop; i++)
     73                for (var i = 0; i < ExpParams.nutrientPop; i++)
    12374                {
    124                         addfood();
     75                        addNutrient();
    12576                }
    12677
    127                 foodenergywaiting = 0.0;
     78                nutrientenergywaiting = 0.0;
    12879                Simulator.checkpoint();
    12980        }
     
    183134}
    184135
     136function createStatistics()
     137{
     138        var haploids = 0;
     139        var diploids = 0;
     140        var e_inc_h = 0.0;
     141        var e_inc_d = 0.0;
     142        var e_nut = 0.0;
     143        var size_h = 0.0;
     144        var size_d = 0.0;
     145        var vmin_h = 0.0;
     146        var vmin_d = 0.0;
     147
     148        for (var i = 0; i < Populations[0].size; i++)
     149        {
     150                var cr = Populations[0].get(i);
     151                if (cr.user2["gen"] == 0)
     152                {
     153                        haploids += 1;
     154                        e_inc_h += cr.energy;
     155                        size_h += ExpParams.rads[0]; //TODO change of size dependent on gene
     156                        vmin_h += cr.user1["minenergy"];
     157                }
     158                else if (cr.user2["gen"] == 1)
     159                {
     160                        diploids += 1;
     161                        e_inc_d += cr.energy;
     162                        size_d += ExpParams.rads[1]; //TODO change of size dependent on gene
     163                        vmin_d += cr.user1[0]["minenergy"];
     164                }
     165        }
     166
     167        for (var i = 0; i < Populations[1].size; i++)
     168        {
     169                var cr = Populations[1].get(i);
     170                e_nut += cr.energy;
     171        }
     172
     173        var l1 = [haploids, diploids, Populations[1].size];
     174        var l2 = [e_inc_h, e_inc_d, e_nut];
     175        var dp = diploids;
     176        var hp = haploids;
     177        if (dp == 0) dp = 0.000001;
     178        if (hp == 0) hp = 0.000001;
     179        var l3 = [size_h / hp, vmin_h / hp, size_d / dp, vmin_d / dp];
     180
     181        log(l1, "log_sizes.txt");
     182        log(l2, "log_energy.txt");
     183        log(l3, "log_sizes_v.txt");
     184}
    185185// -------------------------------- step end --------------------------------
Note: See TracChangeset for help on using the changeset viewer.