Beispiel #1
0
//
// operator <<= (CUTS_Virtual_Env &, const CUTS::schemas::EnvConfig &)
//
bool
operator <<= (CUTS_Virtual_Env & env, const CUTS::schemas::EnvConfig & config)
{
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("%T (%t) - %M - loading environment's configuration\n")));

  if (config.variables_p ())
    env.env_table () <<= config.variables ();

  if (config.startup_p ())
    std::for_each (config.startup ().begin_process (),
                   config.startup ().end_process (),
                   install_process (env, true));

  if (config.shutdown_p ())
    std::for_each (config.shutdown ().begin_process (),
                   config.shutdown ().end_process (),
                   install_process (env, false));

  return true;
}
Beispiel #2
0
void create_assembled_pool(Params *p, double **pool, int divpool, double fert)
{
    restart:;
    // define and initialize the ecosystem list
    //-----------------------------------------
    sll ecosys;
    sll_init(&ecosys,(void*)free_species);

    // create the basal resources
    //---------------------------
    basal(p,&ecosys,fert);

    // assemble until the targetted diversity is reached
    //--------------------------------------------------
    int a = divpool + EAM_NBNUT + EAM_NBDET;
    int counter = EAM_STOP_UNSUCCESS_ASSEMBLY*divpool;
    while(ecosys.length != a)
    {
	ParamSP *sp = (void*)species(p,2);
	install_process(p,&ecosys,sp);
	sll_rm(&ecosys,extinct_condition);
	++(p->num);
	--counter;
	if(counter == 0)
	{
	    sll_rm_all(&ecosys);
	    //create_assembled_pool(p, pool, divpool, fert);
	    goto restart;
	}

    }

    // remove the resources
    //---------------------
    sll_rm(&ecosys,is_resource);


    // create the subpool matrix and fill it with the selected species
    //----------------------------------------------------------------
    sllnode *node = ecosys.head;
    for (int i = 0; node != NULL; i++, node = node->next)
    {
        ParamSP sp = *(ParamSP*)(node->data);
	sp.d = EAM_N0SP;
	tr_sp_array(&sp,pool[i]);
    }

    // free the memory
    //----------------
    sll_rm_all(&ecosys);
}
Beispiel #3
0
void assembly_run(Params *p, double nfert, double **regpool, int poolsize, char *folder, char *replicate_identity)
{
    // Define and initialize the history and ecosystem lists
    //------------------------------------------------------
    sll history;
    sll_init(&history,(void*)free_seq);
    sll ecosys;
    sll_init(&ecosys,(void*)free_species);

    // create the basal resources
    //---------------------------
    basal(p,&ecosys,nfert);


    // create and initialize the presence matrix (ne pas oublier de mettre les espèces au minimum pour l'invasion)
    //------------------------------------------
    unsigned int **presence = (unsigned int**)mat_alloc(2,poolsize,sizeof(unsigned int));
    for(int i = 0 ; i < poolsize ; ++i)
    {
        presence[0][i] = regpool[i][1];
        presence[1][i] = 0;
    }

    // get the initial values of the sequence
    //---------------------------------------
    seqlevel *seq0 = fill_seq(&ecosys,0,0);
    seq0->success = 0;
    sll_add_head(&history,seq0);

    // assemble until any species can install (or all are already installed)
    //----------------------------------------------------------------------
    int a = poolsize + EAM_NBNUT + EAM_NBDET;                              /* expected ecosystem size */
    int stop_endcycles = poolsize * EAM_STOP_ENDCYCLE;                     /* variable to stop the sequence if infinite */
    int endcycles = 0;                                                     /* 0 if endpoint / 1 if endcycle */ 
    int unsucc = EAM_STOP;                                                 /* check the success of the invader */
    int invasion = 1;                                                      /* invasion number */

    while(ecosys.length != a)
    {
        int b = get_int(p->rng,0,poolsize);                                /* select randomly the number of the species in the regional pool */
        if(presence[1][b] == 0)                                            /* if the species is not already in the ecosystem */
	{
	    ParamSP *sp = (ParamSP*)malloc(sizeof(ParamSP));
	    tr_sp_struct(regpool[b],sp);
	    install_process(p,&ecosys,sp);                                  /* install the species */
	    seqlevel *seq = fill_seq(&ecosys,invasion,presence[0][b]);      /* create and initialize a sequence node */
	    sll_rm(&ecosys,extinct_condition);                              /* remove the extincted species */
	    presence_absence(&ecosys,presence,poolsize);                    /* fill the presence-absence matrix */
	    unsucc = (presence[1][b] == 0) ? unsucc-1 : EAM_STOP;          /* upgrade the counter of unsuccessfull installations */
	    seq->success =  presence[1][b];                                /* fill the success of invader installation in the sequence node */
	    sll_add_head(&history,seq);                                    /* add the sequence node to the assembly history */
	    ++invasion;                                                    /* upgrade the invasion number */
	    --stop_endcycles;                                              /* upgrade the endcycle detector */
	}
	if(unsucc == 0) break;
        if(stop_endcycles == 0)                                              /* break the loop if its an endcycle */
	{
	    endcycles = 1;
	    break;
	}
    }


    // print the outputs : subpool / final community / sequence / abundances history / identity history
    //------------------
    print_final_community(&ecosys,folder,replicate_identity);
    print_id_history(&history,poolsize,folder,replicate_identity);
    print_final_biomasses_history(&history,poolsize,folder,replicate_identity);
    print_sequence(&history,folder,replicate_identity);
    char *buffer = (char*)malloc(100);
    sprintf(buffer, "%s/%s_endcycle.txt",folder,replicate_identity);
    FILE *out = fopen(buffer,"w");
    fprintf(out,"%d",endcycles);
    fclose(out);

    // free the memory
    //----------------
    mat_free((void**)presence,2);
    sll_rm_all(&history);
    sll_rm_all(&ecosys);
    free(buffer);

}