Beispiel #1
0
void get_operator()
{
  muta();
  if ( isoperator(curent_char()) == FALSE )
      eroare("operator asteptat");
  atom.nume[0] = curent_char();
  atom.nume[1] = '\0';
  atom.nume[2] = '\0';

  atom.cod = COD_OPERATOR; 
  switch (atom.nume[0])
    {
    case '+':
      // daca urmatorul caracter e '+' -> '++' 
      if ( view_next_char() == '+')
	atom.nume[1] = next_char();
      break;
    case '-':
      // daca e '-' -> '--' 
      if (  view_next_char() ==  '-' )
	atom.nume[1] = next_char();
      break;
    case '>':
      // daca e '>' -> '>>' , daca e '=' -> '>='
      if ( view_next_char() == '>' || view_next_char() == '=')
	atom.nume[1] = next_char();
      break;
    case '<':
      // daca urm. e '<' -> '<<', daca e '=' -> '<='
      if ( view_next_char() == '<' || view_next_char() == '=')
	atom.nume[1] = next_char();
      break;
    case '=':
      // daca e '=' -> '=='
      if ( view_next_char() == '=')
	atom.nume[1] = next_char();
      break;
    case '!':
      // deca e '=' -> '!='
      if ( view_next_char() == '=')
	atom.nume[1] = next_char();
      break;
    case '&':
      // daca e '&' -> '&&'
      if ( view_next_char() == '&')
	atom.nume[1] = next_char();
      break;
    case '|':
      // daca e '|' -> '||'
      if ( view_next_char() == '|')
	atom.nume[1] = next_char();
      break;
    }
  next_char();
}
Beispiel #2
0
/* hace una evaluaion, seleccion, cruzamiento y mutacion */
void evolucionar_poblacion(poblacion *p, float proba_cruzamiento,float proba_mutacion)
{
	/* assumes the whole poblacion has been es_evaluado */
	if ((proba_cruzamiento < 0) || (proba_cruzamiento > 1) || (proba_mutacion < 0) || (proba_mutacion > 1))
    {
		printf("Probabilidades de cruzamiento y mutacion deben estar entre [0,1]\n");
		exit(1);
	}
	cruza(p,proba_cruzamiento);
	muta(p,proba_mutacion);
	haz_evaluacion(p);
}
Beispiel #3
0
void get_number()
{
  int i;
  muta();
  if ( isxdigit ( curent_char() ) == 0)
      eroare ("numar asteptat");
  atom.cod = COD_NUMAR;
  i = 0;
  do
    {
      atom.nume [i] = curent_char();
      next_char();
      i++;
    }
  while ( isxdigit(curent_char()) && i < MARIME_IDENTIFICATOR);
  atom.nume[i]='\0';
  if ( i == MARIME_IDENTIFICATOR && isxdigit(curent_char()) )
      eroare("numar prea mare (lung al dracu)");
}
Beispiel #4
0
void get_name()
{
  int i;
  muta();
  if ( isalpha( curent_char() ) == 0 )
      eroare ("nume de identificator asteptat");
  atom.cod = COD_NUME;
  i = 0;
  do
    {
      atom.nume[i] = curent_char();
      next_char();
      i++;
    }
  while ( isalnum(curent_char())  && i < MARIME_IDENTIFICATOR);
  atom.nume[i]='\0';
  if ( i == MARIME_IDENTIFICATOR && isalnum(curent_char()) )
      eroare ("nume de identificator prea lung");
}
Beispiel #5
0
void crear_soluciones(struct Generacion *generacion) {


int main(int argc, const char **argv){

    int entrada = 0;
    struct Stack clases;
    struct Stack plazas;
    struct Generacion generacion;

    srand(time(NULL));

    /* Entrada de datos */
    init(&clases);
    while( (entrada = cuantos("Alumnos")) > 0)
        push(entrada, &clases);

    init(&plazas);
    while( ( entrada = cuantos("Plazas")) > 0)
        push(entrada, &plazas);

    generacion.n_clases    = clases.cima;
    generacion.n_autobuses = plazas.cima;

    /* Algoritmo */
    crear_soluciones(&generacion);
    for (int g=0; g<GENERACIONES; g++)
        evalua(&generacion);
        ordena(&generacion);
        recombina(&generacion);
        muta(&generacion);


    /* House keeping */
    for (int i=0; i<INDIVIDUOS; i++)
        free(generacion.solucion[i].n_autobus);
    free(clases.data);
    free(plazas.data);

    return EXIT_SUCCESS;
}