示例#1
0
  // MÉTODOS DE PROCRIAÇÃO
  // TODO: métodos de geração (por gestação, ovos etc)
  public Creature copulate(ArrayList<Creature> creatures) {
    Creature c = null;
    for (Creature other : creatures) {
      DNA partner = other.dna;

      if (relativeness(creatures, 3, 297, 391) == true) {
        DNA childDNA = dna.mate(partner);
        childDNA.mutate(0.01f); // mudar (isPredator)
        c =
            new Creature(
                childDNA,
                p.round(p.random(9999999)),
                loc,
                true,
                true,
                true,
                true,
                true,
                true,
                true,
                false);
      }
    }
    return c;
  }
示例#2
0
  private boolean relativeness(ArrayList<Creature> creatures, int number, int from, int to) {
    // analiza um conjunto de genes e retorna verdadeiro se dada porcentagem
    // for positiva.

    int count = 0;
    for (Creature other : creatures) {
      DNA mate = other.dna;
      if (other.id != id) {
        count = 0;
        for (int i = from; i < to; i++) {

          if ((mate.getGene(i) == dna.getGene(i))) {
            // println("the genes: " + i + ", of creatures " +
            // other.id + " and " + id + " are equal");
            count++;
          }
        }
      }
    }
    // println("count: " + count);
    if (count >= number) {
      return true;
    } else {
      return false;
    }
  }
示例#3
0
  // ////////////
  // ///////////
  // //////////
  // COM DNA VVVVVVVV//
  public Creature(
      PApplet _p,
      DNA _dna,
      int _id,
      PVector _loc,
      boolean _mouth,
      boolean _eye,
      boolean _ear,
      boolean _nose,
      boolean _hand,
      boolean _leg,
      boolean _reproductive,
      boolean _isPredator) {

    myHash = this.hashCode();
    p = _p;

    id = _id;
    isPredator = _isPredator;

    loc = _loc;
    acc = new PVector(0, 0);
    vel = new PVector(p.random(-1, 1), p.random(-1, 1));
    dna = _dna;
    // numero fixos de neurons
    dna.setGene(0, .02f); // in
    dna.setGene(1, .03f); // hidden
    dna.setGene(2, .01f); // out
    dna.setGene(3, .25f); // learn

    brainInput = (int) dna.getGene(0) * 100;
    brainHidden = (int) dna.getGene(1) * 100;
    brainOutput = (int) dna.getGene(2) * 100;
    // println("input: " + brainHidden);

    // muitas das capacidades do cérebro são herdadas pelo dna
    // UTILIZAR MAIS DE UM "BRAIN" PARA SEPARAR FUNCIONALIDADES
    brain = new Brain(dna);
    // movementCortex = new Brain(dna);
    // socialCortex = new Brain(dna);
    // enviromentCortex = new Brain(dna);

    haveMouth = _mouth;
    haveEye = _eye;
    haveEar = _ear;
    haveNose = _nose;
    haveHand = _hand;
    haveLeg = _leg;
    haveReproductive = _reproductive;

    // haveShape = false;

    decision = new Decision();

    // //toda criatura tem um corpo físico
    bodyCopy = new Body(p, dna, loc, vel, acc, myHash);
    creatureDrawer = new CreatureDrawer(p, dna, loc, vel);
  }
 /** Test method for {@link com.rtg.mode.TranslatedFrame}. */
 public final void test1() {
   final int l = DNA.values().length;
   final int v = 1 << TranslatedFrame.DNA_UNKNOWN_BITS;
   assertTrue(v >= l);
   final int vm = 1 << TranslatedFrame.DNA_UNKNOWN_BITS - 1;
   assertTrue(vm < l);
 }
 /** Compare the DNA and byte versions */
 public final void testCodonToAmino1() {
   assertEquals(512, TranslatedFrame.CODON_TO_AMINO.length);
   for (final DNA c1 : DNA.values()) {
     for (final DNA c2 : DNA.values()) {
       for (final DNA c3 : DNA.values()) {
         final Protein pr = TranslatedFrame.codonToAmino(c1, c2, c3);
         final byte prb =
             TranslatedFrame.codonToAmino(
                 (byte) c1.ordinal(), (byte) c2.ordinal(), (byte) c3.ordinal());
         assertEquals(pr.ordinal(), prb);
       }
     }
   }
 }
示例#6
0
文件: Brain.java 项目: pradn/Aegis
  /**
   * Ends the life of this Brain upon the termination of evaluation. Should only be called during an
   * evolution run.
   *
   * @param fitvalue the evaluated fitness value for this Brain
   */
  protected void reportFitness(double fitvalue) {
    if (alive && dna != null) {
      // Clear all activation information
      for (NNode n : nodemap.values()) {
        n.activity = 0.0;
        n.output = 0.0;
      }

      // Report fitnesses
      dna.fitness = fitvalue;

      // Kill cleanly
      alive = false;
    }
  }
  public final void testCodonToAmino() {
    final Map<Protein, SortedSet<String>> map = new TreeMap<>();
    for (final DNA c1 : DNA.values()) {
      for (final DNA c2 : DNA.values()) {
        for (final DNA c3 : DNA.values()) {
          final String s = "" + c1 + c2 + c3;
          final Protein pr = TranslatedFrame.codonToAmino(c1, c2, c3);
          if (c1.ignore() || c2.ignore()) {
            assertTrue(s + ":" + pr, pr.ignore());
          } else {
            final SortedSet<String> set = map.get(pr);
            final SortedSet<String> ns;
            if (set == null) {
              ns = new TreeSet<>();
              map.put(pr, ns);
            } else {
              ns = set;
            }
            ns.add(s);
          }
        }
      }
    }

    final StringBuilder sb = new StringBuilder();
    for (final Map.Entry<Protein, SortedSet<String>> e : map.entrySet()) {
      final Protein pr = e.getKey();
      final SortedSet<String> set = e.getValue();
      sb.append(pr.threeLetter()).append("/").append(pr.toString()).append(" ");
      int i = 0;
      for (final String s : set) {
        if (i > 0) {
          sb.append(", ");
        }
        sb.append(s);
        i++;
      }
      sb.append(LS);
    }
    assertEquals(CODON_TABLE, sb.toString());
  }
示例#8
0
 @Override
 public void save(DNA dna) {
   idToDna.put(dna.getId(), dna);
   liveDna.add(dna);
 }