Пример #1
0
  /**
   * It converts double to char by the gray's code
   *
   * @param ds the vector which is goint to change
   * @param length the size of the vector
   * @return the changed vector
   */
  private char[] StringRep(double[] ds, int length) {

    int i;
    double n;
    int pos;
    double INCREMENTO;
    char[] Cad_sal;
    Cad_sal = new char[Genes * BITS_GEN + 1];
    if (flag == 1) {
      tmpstring = new char[Genes * BITS_GEN];
      flag = 0;
    }

    pos = 0;
    for (i = 0; i < length; i++) {
      INCREMENTO = (Gene[i].max() - Gene[i].min()) / (Math.pow(2.0, (double) BITS_GEN) - 1.0);

      n = (((ds[i] - Gene[i].min()) / INCREMENTO) + 0.5);
      tmpstring = F.Itoc((int) n, BITS_GEN);

      F.Gray(tmpstring, Cad_sal, BITS_GEN, pos);
      pos += BITS_GEN;
    }
    return Cad_sal;
  }