Changeset 487


Ignore:
Timestamp:
03/27/16 00:12:20 (9 years ago)
Author:
oriona
Message:

Method for definig new species added.

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

Legend:

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

    r486 r487  
    3333global changePeriod;
    3434global phase;
     35global species_genes;
    3536
    3637@include "foraminifera.inc"
     
    5253        pop.death = 1;
    5354        pop.energy = 1;
    54         pop.selfmask = 0x10001;
    55         pop.othermask = 0x20001;
     55        pop.selfmask = 0;
     56        pop.othermask = 0;
    5657        //pop.selfmask = 0x20002; pop.othermask = 0x10002;
    5758        pop.perfperiod = 25;
     59        pop.bodysim = 0;
    5860
    5961        pop = Populations.addGroup("Nutrients");
     
    6264        pop.death = 1;
    6365        pop.energy = 1;
    64         pop.selfmask = 0x20002;
    65         pop.othermask = 0x10000;
     66        pop.selfmask = 0;
     67        pop.othermask = 0;
    6668        //pop.othermask = 0x10002;
     69        pop.bodysim = 0;
    6770
    6871        pop = Populations.addGroup("ReticulopodiaNutrients");
     
    7174        pop.death = 0;
    7275        pop.energy = 0;
    73         pop.selfmask = 0x20002;
    74         pop.othermask = 0x10000;
     76        pop.selfmask = 0;
     77        pop.othermask = 0;
     78        pop.bodysim = 0;
    7579
    7680        //world
     
    9094        //ExpProperties.visualize = 1; //uncomment to visualize reticulopodia and indicate nutrients positions
    9195
    92         //ExpProperties.logging = 1; //uncomment to enable logging simulation parameters to log files
     96        //ExpProperties.logging = 1; //uncomment to enable logging simulation parameters to log files   
    9397
    9498        //reproduction
     
    100104        ExpProperties.divisionCost = 15.6;
    101105        reprocounter = 0;
     106
     107        species_genes = [];
    102108
    103109        init_chambers();
     
    143149        changePeriod = 0;
    144150        phase = "high";
    145         ExpProperties.foodperiod = 21600;
     151        ExpProperties.foodperiod = 3600;
    146152        ExpProperties.foodPeriodChange = 0;
    147153        ExpProperties.nutrientradius = micronsToFrams(10);
     
    195201}
    196202
     203function getGene(cr, gen_id, gen_set)
     204{
     205        if (cr.data->lifeparams->gen == 0)
     206                return cr.data->genes[gen_id];
     207        else
     208                return cr.data->genes[gen_set][gen_id];
     209}
     210
    197211function addForam(species, iter, chambernum, ploid)
    198212{
    199         var geno = createForamGenotype(ploid, species, chambernum);
     213        var geno = createForamMorphology(species_genes[species]->morphotype, ploid, chambernum);
    200214        var cr = Populations[0].add(geno);
    201215        cr.name = "Initial creature" + species + "_" + iter;
     
    203217        cr.energy0 = energyFromVolume(max_chamber_volume[ploid][chambernum],0);
    204218        cr.energy = cr.energy0;
    205         setGenotype({"opt" : 0, "cr" : cr, "species" : species});
     219        setGenotype({"opt" : 0, "cr" : cr, "species" : species, "energy0" : cr.energy0, "genes" : species_genes[species]});
    206220        if (ploid == 1)
    207221        {
     
    219233        }       
    220234        //add new foram with random energy bewtween starting energy and reproduction treshold
    221         addForam(species, iter, Math.rndUni(0,getProperty(ploid, "min_repro_energ")),ploid);
     235        addForam(species, iter, Math.rndUni(0,species_genes[species]->min_repro_energies[ploid]),ploid);
     236}
     237
     238//new species can be added as a dictionary with parameter values that are different than default values
     239function addSpecies(new_genes)
     240{
     241        species_genes.add({"min_repro_energies" : [4,6], "energies0" : [20, 1.25], "hibernation" : 0, "morphotype" : 0});
     242        for (var i = 0; i < new_genes.size; i++)
     243        {
     244                var key = new_genes.getKey(i);
     245                species_genes[species_genes.size-1][key] = new_genes[key];
     246        }
    222247}
    223248
     
    228253        Populations[2].clear(); //reticulopodia and nutrients
    229254
    230         for (var i = 0; i < ExpProperties.foramPop; i++)
    231         {
    232                 addInitialForam(0, i); 
    233                 //addInitialForam(1, i);
     255        if (species_genes.size == 0)
     256        {
     257                addSpecies({}); //default
     258        }
     259
     260        for (var spec = 0; spec < species_genes.size; spec++)
     261        {
     262                for (var i = 0; i < ExpProperties.foramPop; i++)
     263                {
     264                        addInitialForam(spec, i);       
     265                }
    234266        }
    235267        o = Populations[0][0].getMechPart(0).orient.clone();
    236268        ExpState.totaltestedcr = 0;
    237         nutrientenergywaiting = ExpProperties.energy_nut;
    238269}
    239270
     
    361392        if ((chamber_num+1) < chambers[cr.data->lifeparams->species].size)
    362393        {
    363                 var geno = createForamGenotype(cr.data->lifeparams->gen, cr.data->lifeparams->species, chamber_num+1);
     394                var geno = createForamMorphology(getGene(cr, "morphotype", 0), cr.data->lifeparams->gen, chamber_num+1);
    364395                var cr2 = Populations[0].add(geno);
    365396
     
    367398                cr2.energy = cr2.energy0;
    368399
    369                 setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : 2});
     400                setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : 2, "energy0" : cr.energy0});
    370401                cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
    371402                setForamMeta(cr2);
     
    442473}
    443474
     475function fence(pos)
     476{
     477        return Math.min(Math.max(0,pos),World.wrldsiz);
     478}
     479
    444480function foramMove(cr)
    445481{
     
    447483
    448484        //adjustment in z axis
    449         cr.moveAbs(cr.pos_x, cr.pos_y, 0);
     485        cr.moveAbs(fence(cr.pos_x), fence(cr.pos_y), 0);
    450486
    451487        //are there any nutrients in zone 1 or 2?
     
    459495
    460496        //no nutrients in zone 2
    461         var hibernation = 0;
    462         if (cr.data->lifeparams->gen == 0) hibernation =  cr.data->genes->hibernation;
    463         else hibernation =  cr.data->genes[0]->hibernation;
    464         //hibernation
    465         if (hibernation == 1)
     497        if (getGene(cr, "hibernation",0) == 1)
    466498        {
    467499                reverseHib(cr);
     
    469501        }
    470502        //random move
    471         else if (cr.lifespan%int(dir_change/ExpProperties.secPerStep) == 0)
     503        else if (Simulator.stepNumber%int(dir_change/ExpProperties.secPerStep) == 0)
    472504        {
    473505                cr.data->lifeparams->dir = randomDir();
     
    732764function createStatistics()
    733765{       
    734         var number = [[0, 0],[0,0]]; // [species][gen]
    735         var e_inc = [[0, 0],[0,0]];
     766        var number = [];
     767        var e_inc = [];
    736768        var e_nut = 0.0;
     769
     770        for (var s = 0; s < species_genes.size; s++)
     771        {
     772                number.add([0,0]);// [haplo][diplo]
     773                e_inc.add([0,0]);
     774        }
    737775
    738776        for (var i = 0; i < Populations[0].size; i++)
     
    752790        }
    753791
    754         var log_numbers = [number[1][0], number[1][1], number[0][0], number[0][1], Populations[1].size];
    755         var log_energies = [e_inc[1][0], e_inc[1][1], e_inc[0][0], e_inc[0][1], e_nut];
     792        var log_numbers = [];
     793        var log_energies = [];
     794
     795        for (var s = 0; s < species_genes.size; s++)
     796        {
     797                for (var p = 0; p < 2; p++)
     798                {
     799                        log_numbers.add(number[s][p]);
     800                        log_energies.add(e_inc[s][p]);
     801                }
     802        }
     803       
     804        log_numbers.add(Populations[1].size);
     805        log_energies.add(e_nut);
    756806
    757807        log(log_numbers, "forams_log.txt");
  • experiments/frams/foraminifera/data/scripts/foraminifera.inc

    r486 r487  
    2828}
    2929
    30 function createForamGenotype(gen, species, chamber_num)
     30function createForamMorphology(morphotype, gen, chamber_num)
    3131{
    3232        var rad = getProperty(gen, "chamber_proculus");
    33         var geno = "//0\np:" + chambers[species][0] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ", rz=3.14159265358979,vr=" + colors[gen];
    34 
    35         chamber_num = Math.min(chamber_num, chambers[species].size - 1);
     33        var geno = "//0\np:" + chambers[morphotype][0] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ", rz=3.14159265358979,vr=" + colors[gen];
     34
     35        chamber_num = Math.min(chamber_num, chambers[morphotype].size - 1);
    3636
    3737        for (var i = 0; i < chamber_num; i++)
    3838        {
    3939                rad = getProperty(gen, "chamber_proculus") + getProperty(gen, "chamber_difference") * (i + 1);
    40                 geno += "\n" + "p:" + chambers[species][i+1] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ",vr=" + colors[gen];
     40                geno += "\n" + "p:" + chambers[morphotype][i+1] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ",vr=" + colors[gen];
    4141        }
    4242
     
    4646        }
    4747
    48         if (species == 0) geno += "\nn:p=0,d=\"S\"";
     48        if (morphotype == 0) geno += "\nn:p=0,d=\"S\"";
    4949
    5050        return geno;
     
    5555        if (mode->opt == 0) //initial
    5656        {
    57                 mode->cr.data->genes = {"min_repro_energies" : [energyFromVolume(max_chamber_volume[0][getProperty(0, "min_repro_energ")],0), energyFromVolume(max_chamber_volume[1][getProperty(1, "min_repro_energ")],0)], "hibernation" : mode->species};
    58                 mode->cr.data->lifeparams = {"max_energy_level" : getProperty(0,"energies0"), "gen" : 0,  "hibernated" : 0, "species" : mode->species, "reproduce" : 0, "dir" : randomDir(), "chamber_growth" : -1, "division_time" : -1};
     57                mode->cr.data->genes = String.deserialize(String.serialize(mode->genes));
     58                mode->cr.data->lifeparams = {"max_energy_level" : mode->energy0, "gen" : 0,  "hibernated" : 0, "species" : mode->species, "reproduce" : 0, "dir" : randomDir(), "chamber_growth" : -1, "division_time" : -1};
    5959        }
    6060        else if (mode->opt  == 1) //child
    6161        {
    62                 mode->cr.data->lifeparams = {"max_energy_level" : getProperty(1 - mode->parent_lifeparams->gen,"energies0"), "gen" : 1 - mode->parent_lifeparams->gen,  "hibernated" : 0, "species" : mode->parent_lifeparams->species, "reproduce" : 0, "dir" : randomDir(), "chamber_growth" : -1, "division_time" : -1};
    63                 mode->cr.data->genes = mode->parent_genes;
     62                mode->cr.data->lifeparams = {"max_energy_level" : mode->energy0, "gen" : 1 - mode->parent_lifeparams->gen,  "hibernated" : 0, "species" : mode->parent_lifeparams->species, "reproduce" : 0, "dir" : randomDir(), "chamber_growth" : -1, "division_time" : -1};
     63                mode->cr.data->genes = String.deserialize(String.serialize(mode->parent_genes));
    6464        }
    6565        else //grow
     
    8181        //Simulator.print("parent: " + parent_energy + " result: " + result + " number " + number);
    8282        return {"energy" : result, "number" : number};
     83}
     84
     85function getEnergy0(radius)
     86{
     87        return energyFromVolume(micronsToFrams(radius),1);
    8388}
    8489
     
    8893        if (clone == 1)
    8994        {
    90                 var offspring = gametsDivision(parent.energy,getProperty(0,"energies0"));
     95                var offspring = gametsDivision(parent.energy,getEnergy0(getGene(parent,"energies0",0)[0]));
    9196                energy0 = offspring->energy;
    9297                number = offspring->number;
     
    97102        else
    98103        {
    99                 var offspring1 = gametsDivision(parent.energy,getProperty(1,"energies0"));
    100                 var offspring2 = gametsDivision(parent2.energy,getProperty(1,"energies0"));
     104                var offspring1 = gametsDivision(parent.energy,getEnergy0(getGene(parent,"energies0", 0)[1]));
     105                var offspring2 = gametsDivision(parent2.energy,getEnergy0(getGene(parent2,"energies0", 0)[1]));
    101106                energy0 = (offspring1->energy+offspring2->energy);
    102107                number = ExpProperties.gametSuccessRate*(offspring1->number+offspring2->number)/2;
     
    109114        for (var j = 0; j < number; j++)
    110115        {
    111                 createOffspring(createForamGenotype(gen, parent.data->lifeparams->species, 0), energy0, new_genes, parent.data->lifeparams);
     116                createOffspring(createForamMorphology(getGene(parent, "morphotype", 0), gen, 0), energy0, new_genes, parent.data->lifeparams);
    112117        }
    113118}
     
    115120function reproduce_diploid(parent)
    116121{
    117         var energy0 = getProperty(0,"energies0");
     122        var energy0 =getEnergy0( getGene(parent,"energies0", 0)[0]);
    118123        var number = ((1 - (getProperty(parent.data->lifeparams->gen, "e_repro_cost"))) * parent.energy) / energy0;
    119124
     
    132137                for (var k = 0; k < 2; k++)
    133138                {
    134                         createOffspring(createForamGenotype(1 - parent.data->lifeparams->gen, parent.data->lifeparams->species, 0), energy0, parent.data->genes[0], parent.data->lifeparams);
     139                        createOffspring(createForamMorphology(getGene(parent, "morphotype", 0), 1 - parent.data->lifeparams->gen, 0), energy0, parent.data->genes[0], parent.data->lifeparams);
    135140                }
    136141
     
    236241}
    237242
    238 
    239 
    240243function foramReproduce(cr)
    241244{
    242         var properEnergy = 0;
    243         var reproduced = 0;
    244 
    245         if (cr.data->lifeparams->gen == 0)
    246         {
    247                 properEnergy = ( cr.energy >= cr.data->genes->min_repro_energies[cr.data->lifeparams->gen] );
    248         }
    249         else
    250         {
    251                 properEnergy = ( cr.energy >= cr.data->genes[0]->min_repro_energies[cr.data->lifeparams->gen] ); //TODO gene selection
    252         }
     245        var properEnergy = cr.energy >= energyFromVolume(max_chamber_volume[0][getGene(cr, "min_repro_energies",0)[cr.data->lifeparams->gen]],0);
     246        var reproduced = 0;     
    253247
    254248        //if creature has proper energy
     
    289283        cr.energy0 = energy;
    290284        cr.energy = cr.energy0;
    291         setGenotype({"cr" : cr, "parent_genes" : parent_genes, "parent_lifeparams" : parent_lifeparams, "opt" : 1});
     285        setGenotype({"cr" : cr, "parent_genes" : parent_genes, "parent_lifeparams" : parent_lifeparams, "opt" : 1, "energy0" : cr.energy0});
    292286        placeRandomlyNotColliding(cr);
    293287}
Note: See TracChangeset for help on using the changeset viewer.