Java Code Examples for java.lang.Math#ceil()

The following examples show how to use java.lang.Math#ceil() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AG.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
/** Inicialization of the population */
public void Initialize() {
  int i, j;

  last = (int) ( (prob_cruce * long_poblacion) - 0.5);

  Trials = 0;

  if (prob_mutacion < 1.0) {
    Mu_next = (int) Math.ceil(Math.log(Randomize.Rand()) / Math.log(1.0 - prob_mutacion));
  }
  else {
    Mu_next = 1;
  }

  for (j = 0; j < n_genes; j++) {
    New[0].GeneSel[j] = '1';
  }
  New[0].n_e = 1;

  for (i = 1; i < long_poblacion; i++) {
    for (j = 0; j < n_genes; j++) {
      if (Randomize.RandintClosed(0, 1) == 0) {
        New[i].GeneSel[j] = '0';
      }
      else {
        New[i].GeneSel[j] = '1';
      }
    }

    New[i].n_e = 1;
  }
}
 
Example 2
Source File: AG.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
void Mutacion_Uniforme() {
  int posiciones, i, j;
  double m;

  posiciones = n_genes * long_poblacion;

  if (prob_mutacion > 0) {
    while (Mu_next < posiciones) {
      /* we determinate the chromosome and the GeneSel */
      i = Mu_next / n_genes;
      j = Mu_next % n_genes;

      /* we mutate the GeneSel */
      if (New[i].GeneSel[j] == '0') {
        New[i].GeneSel[j] = '1';
      }
      else {
        New[i].GeneSel[j] = '0';
      }

      New[i].n_e = 1;

      /* we calculate the next position */
      if (prob_mutacion < 1) {
        m = Randomize.Rand();
        Mu_next += (int) Math.ceil(Math.log(m) / Math.log(1.0 - prob_mutacion));
      }
      else {
        Mu_next += 1;
      }
    }
  }

  Mu_next -= posiciones;
}
 
Example 3
Source File: MegaSdk.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public int[] str_to_a32(String b) {
    double str_len = (double) b.length();
    double mult = 4.0;
    double rounded_val = Math.ceil(str_len / mult);
    
    int pad_length = ((int) rounded_val) * 4;
    String pad_with = "\0";
    // Add padding, we need a string with a length multiple of 4
    b = str_pad(b, pad_length, pad_with);
    return unpack(b.getBytes());
}
 
Example 4
Source File: Ceil.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
public Object ceil(Object param)
	throws ParseException
{
	if (param instanceof Number)
	{
		return new Double(Math.ceil(((Number)param).doubleValue()));
	}

	throw new ParseException("Invalid parameter type");
}
 
Example 5
Source File: DrawCommand.java    From fabric-carpet with MIT License 4 votes vote down vote up
private static int drawSphere(CommandContext<ServerCommandSource> ctx, boolean solid) throws CommandSyntaxException
{
    BlockPos pos;
    int radius;
    BlockStateArgument block;
    Predicate<CachedBlockPosition> replacement;
    try
    {
        pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
        radius = getArg(ctx, IntegerArgumentType::getInteger, "radius");
        block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
        replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
    }
    catch (ErrorHandled ignored) { return 0; }

    int affected = 0;
    ServerWorld world = ctx.getSource().getWorld();

    double radiusX = radius+0.5;
    double radiusY = radius+0.5;
    double radiusZ = radius+0.5;

    final double invRadiusX = 1 / radiusX;
    final double invRadiusY = 1 / radiusY;
    final double invRadiusZ = 1 / radiusZ;

    final int ceilRadiusX = (int) Math.ceil(radiusX);
    final int ceilRadiusY = (int) Math.ceil(radiusY);
    final int ceilRadiusZ = (int) Math.ceil(radiusZ);

    BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);
    List<BlockPos> list = Lists.newArrayList();

    double nextXn = 0;

    forX: for (int x = 0; x <= ceilRadiusX; ++x)
    {
        final double xn = nextXn;
        nextXn = (x + 1) * invRadiusX;
        double nextYn = 0;
        forY: for (int y = 0; y <= ceilRadiusY; ++y)
        {
            final double yn = nextYn;
            nextYn = (y + 1) * invRadiusY;
            double nextZn = 0;
            forZ: for (int z = 0; z <= ceilRadiusZ; ++z)
            {
                final double zn = nextZn;
                nextZn = (z + 1) * invRadiusZ;

                double distanceSq = lengthSq(xn, yn, zn);
                if (distanceSq > 1)
                {
                    if (z == 0)
                    {
                        if (y == 0)
                        {
                            break forX;
                        }
                        break forY;
                    }
                    break forZ;
                }

                if (!solid && lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1)
                {
                    continue;
                }

                CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;
                for (int xmod = -1; xmod < 2; xmod += 2)
                {
                    for (int ymod = -1; ymod < 2; ymod += 2)
                    {
                        for (int zmod = -1; zmod < 2; zmod += 2)
                        {
                            affected+= setBlock(world, mbpos,
                                    pos.getX() + xmod * x, pos.getY() + ymod * y, pos.getZ() + zmod * z,
                                    block, replacement, list
                            );
                        }
                    }
                }
                CarpetSettings.impendingFillSkipUpdates = false;
            }
        }
    }
    if (CarpetSettings.fillUpdates)
    {
        list.forEach(blockpos1 -> world.updateNeighbors(blockpos1, world.getBlockState(blockpos1).getBlock()));
    }
    Messenger.m(ctx.getSource(), "gi Filled " + affected + " blocks");
    return affected;
}
 
Example 6
Source File: AG_Tun.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
/** Inicialization of the population */
public void Initialize() {
  int i, j, temp, mitad_Pob;
  double Valor_Inicial_Sigma = 0.001;


  if (prob_mutacion < 1.0) {
    Mu_next = (int) Math.ceil(Math.log(Randomize.Rand()) / Math.log(1.0 - prob_mutacion));
  }
  else {
    Mu_next = 1;
  }

  Trials = 0;

  /* Los conjuntos difusos de los antecedentes de las reglas constituyen la
     primera parte del primer cromosoma de la poblacion inicial.
     Se inicializa C1 en el primer cromosoma. */
  New[0].n_e = 1;
  primer_gen_C2 = 0;

  for (i = 0; i < base_reglas.n_reglas; i++) {
    for (j = 0; j < tabla.n_var_estado; j++) {
      New[0].Gene[primer_gen_C2] = base_reglas.BaseReglas[i].Ant[j].x0;
      New[0].Gene[primer_gen_C2 + 1] = base_reglas.BaseReglas[i].Ant[j].x1;
      New[0].Gene[primer_gen_C2 + 2] = base_reglas.BaseReglas[i].Ant[j].x3;
      primer_gen_C2 += 3;
    }
  }

  /* Se establecen los intervalos en los que varia cada gen de la primera
     parte en la primera generacion */
  for (i = 0; i < primer_gen_C2; i += 3) {
    intervalos[i].min = New[0].Gene[i] - (New[0].Gene[i + 1] - New[0].Gene[i]) / 2.0;
    intervalos[i].max = New[0].Gene[i] + (New[0].Gene[i + 1] - New[0].Gene[i]) / 2.0;

    intervalos[i + 1].min = New[0].Gene[i + 1] - (New[0].Gene[i + 1] - New[0].Gene[i]) / 2.0;
    intervalos[i + 1].max = New[0].Gene[i + 1] + (New[0].Gene[i + 2] - New[0].Gene[i + 1]) / 2.0;

    intervalos[i + 2].min = New[0].Gene[i + 2] - (New[0].Gene[i + 2] - New[0].Gene[i + 1]) / 2.0;
    intervalos[i + 2].max = New[0].Gene[i + 2] + (New[0].Gene[i + 2] - New[0].Gene[i + 1]) / 2.0;
  }

  /* Se inicializa la segunda parte del primer cromosoma con los parametros
     de los consecuentes de las reglas de la BC inicial, junto con los inter-
     valos correspondientes */
  for (i = 0; i < base_reglas.n_reglas; i++) {
    for (j = 0; j < tabla.n_variables; j++) {
      temp = primer_gen_C2 + i * (tabla.n_variables) + j;
      New[0].Gene[temp] = Math.atan(base_reglas.BaseReglas[i].Cons[j]);
      intervalos[temp].min = (-1.0 * PI / 2.0) + 1E-10;
      intervalos[temp].max = (PI / 2.0) - 1E-10;
    }
  }

  /* Se genera la segunda mitad de la poblacion inicial generando aleatoriamen-
     te C1 y manteniendo C2 */
  mitad_Pob = (int) Math.ceil(long_poblacion / 2.0);
  for (i = 1; i < mitad_Pob; i++) {
    for (j = 0; j < primer_gen_C2; j++) {
      New[i].Gene[j] = intervalos[j].min + Randomize.Randdouble(intervalos[j].min, intervalos[j].max);
    }

    for (j = primer_gen_C2; j < n_genes; j++) {
      New[i].Gene[j] = New[0].Gene[j];
    }

    New[i].n_e = 1;
  }

  /* Se genera el resto de la poblacion inicial generando aleatoriamente C1
     a partir de los intervalos anteriores y mutando C2 */
  for (i = mitad_Pob; i < long_poblacion; i++) {
    for (j = 0; j < primer_gen_C2; j++) {
      New[i].Gene[j] = intervalos[j].min + Randomize.Randdouble(intervalos[j].min, intervalos[j].max);
    }

    for (j = primer_gen_C2; j < n_genes; j++) {
      /* Comprobamos que no se salgan del intervalo permitido [-PI/2,PI/2] */
      do {
        New[i].Gene[j] = New[0].Gene[j] + ValorNormal(Valor_Inicial_Sigma);
      }
      while (New[i].Gene[j] <= (-1.0 * PI / 2.0) || New[i].Gene[j] >= (PI / 2.0));
    }

    New[i].n_e = 1;
  }
}
 
Example 7
Source File: AG_Tun.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
/** Mutation Non Uniform */
public void Mutacion_No_Uniforme(long Gen, long n_generaciones) {
  int posiciones, i, j;
  double nval, m;

  posiciones = n_genes * long_poblacion;

  if (prob_mutacion > 0) {
    while (Mu_next < posiciones) {

      /* we determinate the chromosome and the gene */
      i = Mu_next / n_genes;
      j = Mu_next % n_genes;

      /* Se determinan los intervalos de mutacion de ese gen y se calcula el
           valor mutado */
      if (j >= primer_gen_C2) { /* Consecuente: muta en [-PI/2,PI/2] */
        intervalo_mut.min = intervalos[j].min;
        intervalo_mut.max = intervalos[j].max;
      }
      else {
        switch (j % 3) {
          case 0:
              /* Punto izquierdo: muta en [intervalos[j].min,cromosoma[j+1]] */
            intervalo_mut.min = intervalos[j].min;
            intervalo_mut.max = New[i].Gene[j + 1];
            break;

          case 1:
              /* Punto central: muta en [cromosoma[j-1],cromosoma[j+1]] */
            intervalo_mut.min = New[i].Gene[j - 1];
            intervalo_mut.max = New[i].Gene[j + 1];
            break;

          case 2:
              /* Punto derecho: muta en [cromosoma[j-1],intervalos[j].max] */
            intervalo_mut.min = New[i].Gene[j - 1];
            intervalo_mut.max = intervalos[j].max;
            break;
        }
      }

      /* we mutate the gene */
      if (Randomize.Rand() < 0.5) {
        nval = New[i].Gene[j] +
            delta(Gen, intervalo_mut.max - New[i].Gene[j], n_generaciones);
      }
      else {
        nval = New[i].Gene[j] -
            delta(Gen, New[i].Gene[j] - intervalo_mut.min, n_generaciones);
      }

      New[i].Gene[j] = nval;
      New[i].n_e = 1;

      /* we calculate the next position */
      if (prob_mutacion < 1) {
        m = Randomize.Rand();
        Mu_next += (int) Math.ceil(Math.log(m) / Math.log(1.0 - prob_mutacion));
      }
      else {
        Mu_next += 1;
      }
    }

    Mu_next -= posiciones;
  }
}
 
Example 8
Source File: SystemFunctions.java    From incubator-retired-mrql with Apache License 2.0 votes vote down vote up
public static MR_double ceil ( MR_double x ) { return new MR_double(Math.ceil(x.get())); }