Beispiel #1
0
Packet* SimpleGen::generateMessage()
{
	char name[20];
	int src = getId();
	int dest = 31337;
	int priority = intrand(5) + 1;
	int Payload = 1;
	int ByteLength = intuniform(0, 1000);
	int ds = intrand(2);
	packetId += 1;

	// Generate simple message name
	sprintf(name, "msg-%d", packetId);

	//Create new packet
	Packet* packet = new Packet(name);

	// Set properties
	packet->setSessionID(sessionId);
	packet->setPacketID(packetId);
	packet->setSrc(src);
	packet->setDst(dest);
	packet->setSessionID(sessionId);
	packet->setPacketID(packetId);
	packet->setPriority(priority);
	packet->setPayload(Payload);
	packet->setByteLength(ByteLength);
	packet->setDs(ds);
	packet->setCreationTime(simTime().dbl());

	return packet;
}
Beispiel #2
0
void richness(double *v, int *prow, int *pcolumn)
{

    int i,j,k;
    int row, column;
	double tmp;
    double **m;

    row = *prow;
    column = *pcolumn;

    m = vectomat(v,row,column);

    GetRNGstate();
    for(i=0;i<row;i++)
    {
        for (j=0;j<column;j++)
        {
            k=intrand(column);//choose another column (species) at random
            tmp = m[i][j];
            m[i][j] = m[i][k];
            m[i][k] = tmp;
		}
    }
    mattovec(v,m,row,column);
    PutRNGstate();
}
Beispiel #3
0
void frequency(double *v, int *prow, int *pcolumn)
{

    int i,j,k;
    int row, column;
	double tmp;
    double **m;

    row = *prow;
    column = *pcolumn;

    m = vectomat(v,row,column);

    GetRNGstate();
    for(i=0;i<column;i++)
    {
        for (j=0;j<row;j++)
        {
            k=intrand(row);//choose another row (sample) at random
            tmp = m[j][i];
            m[j][i] = m[k][i];
            m[k][i] = tmp;
		}
    }
    mattovec(v,m,row,column);
    PutRNGstate();
}
char *alfabeto_file(char *fileloc, long nbytes, int (*allowchar)(char), int separar){
  FILE *f;
  char *result;
  char *buffer;
  int resultindex, bufferindex;
  long filesize, patronstart;
  int enespacio;

  // para preprocesamiento obtenemos un texto del doble pedido, lo preprocesamos
  // y finalmente lo cortamos a 1MB. Si no es suficiente, repetimos.
  
  f = fopen(fileloc, "rb");

  if(f==NULL){
    fprintf(stderr, "FILE %s not found\n", fileloc);
    exit(-1);
  }

  buffer = (char*)malloc((2*nbytes + 1)*sizeof(char));
  result = (char*)malloc((nbytes + 1)*sizeof(char));
  fseek(f, 0, SEEK_END);
  filesize = ftell(f);

  patronstart = intrand(filesize - 2*nbytes);
  fseek(f, patronstart, SEEK_SET);

  fread(buffer, sizeof(char), 2*nbytes, f);
  buffer[2*nbytes] = 0;
  fclose(f);

  resultindex = 0;
  enespacio=0;

  if(allowchar == NULL){
    free(result);
    return buffer;
  }

  for(bufferindex=0; buffer[bufferindex] != 0 && resultindex < nbytes; bufferindex++){
    if(allowchar(buffer[bufferindex])){
      result[resultindex] = buffer[bufferindex];
      enespacio=0;
      resultindex++;
    } else {
      if(separar){
	if(enespacio) continue;
	enespacio=1;
	result[resultindex] = SEPARADOR;
	resultindex++;
      }
    }
  }
  free(buffer);
  result[resultindex] = 0;
  
  return result;
}
char lengsintetico_rand(){
  long largo = (long)('z'-'a'+1);
  long rand = intrand(2*largo + 2);

  if(rand < largo) return (char)rand + 'A';
  else if(rand < 2*largo) return (char)(rand % largo)  + 'a';
  
  return ' ';
}
Beispiel #6
0
void independentswap(double *v, int *pintervals, int *prow, int *pcolumn)
{
    long int swap;
    int swapped;
    int i,j,k,l;
    int row, column;
    int intervals;
	double tmp;
    double **m;

    row = *prow;
    column = *pcolumn;
    intervals = *pintervals;

    m = vectomat(v,row,column);

    GetRNGstate();
    for(swap=0;swap<intervals;swap++)
    {
        swapped = 0;
        while(swapped==0) {
            i=intrand(row);//Choose a random row
            while((j=intrand(row))==i);//make sure that you do not randomly choose the same row as before
            k=intrand(column);//Choose a random column
            while((l=intrand(column))==k);//make sure that you do not randomly choose the same column as before
            if((m[i][k]>0.0 && m[j][l]>0.0 && m[i][l]+m[j][k]==0.0)||(m[i][k]+m[j][l]==0.0 && m[i][l]>0.0 && m[j][k]>0.0))
            {
                //currently swaps abundances within columns (=species)
                //should have a switch to swap abundances within rows, columns, or random
                tmp = m[i][k];
                m[i][k] = m[j][k];
                m[j][k] = tmp;
                tmp = m[i][l];
                m[i][l] = m[j][l];
                m[j][l] = tmp;
                swapped = 1;
            }
        }
    }
    mattovec(v,m,row,column);
    PutRNGstate();
}
char *patron_text(int potenciade2, char *texto, int txtlen){
  int tamano;
  int rnd;

  char *result;

  tamano = 2 << (potenciade2 -1);
  result = (char*)malloc((tamano+1)*sizeof(char));
  if(result==NULL){
    printf("no hay memoria..\n");
    exit(-1);
  }

  rnd = intrand(txtlen - tamano);
  memcpy(result, texto + rnd, tamano);
  result[tamano] = 0;

  return result;
}
Beispiel #8
0
void
arrive (int new_job)		/* Function to serve as both an arrival event of a job
				   to the system, as well as the non-event of a job's
				   arriving to a subsequent station along its
				   route. */
{
    int station;

    /* If this is a new arrival to the system, generate the time of the next
       arrival and determine the job type and task number of the arriving
       job. */


    if (new_job == 1)
    {

        event_schedule (sim_time + expon (mean_interarrival, STREAM_INTERARRIVAL), EVENT_ARRIVAL);
        job_type = intrand (prob_distrib_job_type, STREAM_JOB_TYPE);
        task = 1;
    }

    /* Determine the station from the route matrix. */

    station = route[job_type][task];

    /* Check to see whether all machines in this station are busy. */

    if (num_machines_busy[station] == num_machines[station])
    {

        /* All machines in this station are busy, so place the arriving job at
           the end of the appropriate queue. Note that the following data are
           stored in the record for each job:
           1. Time of arrival to this station.
           2. Job type.
           3. Current task number. */

        transfer[1] = sim_time;
        transfer[2] = job_type;
        transfer[3] = task;
        list_file (LAST, station);
    }

    else
    {

        /* A machine in this station is idle, so start service on the arriving
           job (which has a delay of zero). */

        sampst (0.0, station);	/* For station. */
        sampst (0.0, num_stations + job_type);	/* For job type. */
        ++num_machines_busy[station];
        timest ((double) num_machines_busy[station], station);

        /* Schedule a service completion.  Note defining attributes beyond the
           first two for the event record before invoking event_schedule. */

        transfer[3] = job_type;
        transfer[4] = task;
        event_schedule (sim_time + erlang (2, mean_service[job_type][task], STREAM_SERVICE), EVENT_DEPARTURE);
    }
}
// tiempos y ocupacion deben poder aguantar la cantidad de elementos en cs.
// en particular deben ser de tamaño 23 para el experimento default.
static void _run_once(const char *estructura,
		      struct cadena_struct *cs,
		      long double *tiempos_insercion,
		      unsigned long long *ocupacion,
		      long double *tiempos_busqueda_normal,
		      long double *tiempos_busqueda_cargados,
		      long double *tiempos_eliminacion
		      )
{
  struct timeval inicio;
  struct timeval fin;
  abb abb;
  avl avl;
  splaytree stree;

  if(strcmp(estructura, "abb") == 0) abb_new(&abb);
  if(strcmp(estructura, "avl") == 0) avl_new(&avl);
  if(strcmp(estructura, "splaytree") == 0) splaytree_new(&stree);

  int k;
  int potencia = 0;

  long double sumatiempo = 0.0;

  gettimeofday(&inicio, NULL);
  for (k=0; k<cs->num_elems; k++) {
    char *lacadena = get_cadena(cs, k);
    if(strcmp(estructura, "abb") == 0) abb_insertar(&abb, lacadena, lacadena, TAMANO_CADENA+1);
    if(strcmp(estructura, "avl") == 0) avl_insertar(&avl, lacadena, lacadena, TAMANO_CADENA+1);
    if(strcmp(estructura, "splaytree") == 0) splaytree_insertar(&stree, lacadena, lacadena, TAMANO_CADENA+1);

    if(k+1 == 1<<potencia){
      // por ahora reportamos resultados en pantallax.
      gettimeofday(&fin, NULL);
      // un hack para un comportamiento molesto... el primer elemento asumimos que se inserta en tiempo 0
      if(k==0) tiempos_insercion[potencia] = 0.0;
      else {
	sumatiempo += elapsed_time(&fin, &inicio);
	tiempos_insercion[potencia] = sumatiempo;
      }
      
      if(strcmp(estructura, "abb") == 0) ocupacion[potencia] = abb_espacio(&abb);
      if(strcmp(estructura, "avl") == 0) ocupacion[potencia] = avl_espacio(&avl);
      if(strcmp(estructura, "splaytree") == 0) ocupacion[potencia] = splaytree_espacio(&stree);
      potencia++;
      gettimeofday(&inicio, NULL);
    }
  }

  // terminamos las inserciones. Lo buscamos todo
  sumatiempo = 0.0;
  potencia = 0;
  gettimeofday(&inicio, NULL);
  
  for (k=0; k < cs->num_elems; k++) {
    char *lacadena = get_cadena(cs, k);
    if(strcmp(estructura, "abb") == 0) abb_buscar(&abb, lacadena);
    if(strcmp(estructura, "avl") == 0) avl_buscar(&avl, lacadena);
    if(strcmp(estructura, "splaytree") == 0) splaytree_buscar(&stree, lacadena);

    if(k+1 == 1<<potencia){
      gettimeofday(&fin, NULL);
      sumatiempo += elapsed_time(&fin, &inicio);
      tiempos_busqueda_normal[potencia] = sumatiempo;
      potencia++;
      gettimeofday(&inicio, NULL);
    }
  }
  
  // fin búsquedas
  sumatiempo = 0.0;
  potencia = 0;
  gettimeofday(&inicio, NULL);

  for (k=0; k < BUSCAR_CADENAS_RAND; k++) {
    int indicerand = 0;
    int undecimo = (int)cs->num_elems/10;
    if(drand48() < 0.9) indicerand = (int)intrand(undecimo);
    else indicerand = undecimo + intrand(cs->num_elems - undecimo - 1);

    char *lacadena = get_cadena(cs, indicerand);

    if(strcmp(estructura, "abb") == 0) abb_buscar(&abb, lacadena);
    if(strcmp(estructura, "avl") == 0) avl_buscar(&avl, lacadena);
    if(strcmp(estructura, "splaytree") == 0) splaytree_buscar(&stree, lacadena);

    if(k+1 == 1<<potencia){
      gettimeofday(&fin, NULL);
      sumatiempo += elapsed_time(&fin, &inicio);
      tiempos_busqueda_cargados[potencia] = sumatiempo;
      potencia++;
      gettimeofday(&inicio, NULL);
    }
  }

  sumatiempo = 0.0;
  potencia = 0;
  gettimeofday(&inicio, NULL);

  for (k=0; k < cs->num_elems; k++) {
    char *lacadena = get_cadena(cs, k);

    if(strcmp(estructura, "abb") == 0) abb_eliminar(&abb, lacadena);
    if(strcmp(estructura, "avl") == 0) avl_eliminar(&avl, lacadena);
    if(strcmp(estructura, "splaytree") == 0) splaytree_eliminar(&stree, lacadena);

    if (k+1 == 1<<potencia) {
      gettimeofday(&fin, NULL);
      sumatiempo += elapsed_time(&fin, &inicio);
      tiempos_eliminacion[potencia] = sumatiempo;
      potencia++;
      gettimeofday(&inicio, NULL);
    }
  }
  
  
  if(strcmp(estructura, "abb") == 0) abb_dispose(&abb);
  if(strcmp(estructura, "avl") == 0) avl_dispose(&avl);
  if(strcmp(estructura, "splaytree") == 0) splaytree_dispose(&stree);
}