private void addMutantToDB(
      Individual original, Individual mutant, int generationNumber, Location location) {
    final GraphDatabaseService graphDB = GraphDB.graphDB();
    IndexManager index = graphDB.index();
    Index<Node> individualNodes = index.forNodes("individuals");
    Index<Node> locationNodes = index.forNodes("locations");

    Transaction tx = graphDB.beginTx();

    Relationship mutantRelationship;
    Relationship node;
    Node individualNode;
    try {
      individualNode = graphDB.createNode();
      individualNode.setProperty("fitness", mutant.getGlobalFitness());
      individualNode.setProperty("id", mutant.uid.toString());
      Node locationNode = locationNodes.get("locationID", location.getPosition()).next();
      node = individualNode.createRelationshipTo(locationNode, RelTypes.LOCATEDIN);
      node.setProperty("generation", generationNumber);

      Node originalNode = individualNodes.get("id", original.uid.toString()).next();
      mutantRelationship = individualNode.createRelationshipTo(originalNode, RelTypes.MUTANTOF);
      mutantRelationship.setProperty("generation", generationNumber);

      individualNodes.add(individualNode, "id", mutant.uid.toString());

      tx.success();
    } finally {
      tx.finish();
    }
  }
  @Override
  protected double doEvaluation(Problem problem, Individual individual) {
    OnesMaxProblem onesMaxProblem = (OnesMaxProblem) problem;
    int numBits = onesMaxProblem.getBitStringSize();

    if (numBits == 0) {
      return 1.0;
    }

    int onesCount = 0;
    int[] bits = individual.getBits();
    for (int i = 0; i < numBits; i++) {
      if (bits[i] == 1) {
        onesCount++;
      }
    }

    return onesCount / (double) numBits;
  }
  @Override
  public Individual mutate(Individual ind, Object... parameters) {
    int generationNumber = (Integer) parameters[1];
    Location location = (Location) parameters[0];

    int[] bits = ind.getBits();

    double mutationRate = DoubleParameter.AVERAGE_MUTATIONS.getValue() / bits.length;

    for (int i = 0; i < bits.length; i++) {
      if (prngInstance.nextDouble() < mutationRate) {
        bits[i] = flipBit(bits[i]);
      }
    }

    Individual mutant = new Individual(bits);

    addMutantToDB(ind, mutant, generationNumber, location);

    return mutant;
  }