Example #1
0
  /*
   * aka. addNeuron ()
   */
  public int addNode(int historicalID) {
    Gene randLink;

    do {
      randLink = links.get(rand.nextInt(links.size()));
    } while (randLink.isDisabled());
    double[] from = getNeuronPos(randLink.getFrom());
    double[] to = getNeuronPos(randLink.getTo());

    int minx = sm.getCornerOffset() + sm.getWidth() * (sm.getSmallTileSize() + 2) + 2;
    if (from[0] < minx) {
      from[0] = minx;
    }

    randLink.setDisabled(true);

    int neuralID = neurons.size() + numInputs;
    neurons.add(new Neuron((from[0] + to[0]) / 2, (int) (from[1] + to[1]) / 2));

    // (int from_, int to_, double weight_, int histID_, boolean negative_, boolean disabled_
    addLink(randLink.getFrom(), neuralID, 1.0, historicalID, false);
    addLink(neuralID, randLink.getTo(), randLink.getWeight(), historicalID + 1, false);

    bubbleSortNeurons();

    return historicalID + 2;
  }