class_docstr: The :class:`History` class helps to build a genealogy of all the
  individuals produced in the evolution. It contains two attributes,
  the :attr:`genealogy_tree` that is a dictionary of lists indexed by
  individual, the list contain the indices of the parents. The second
  attribute :attr:`genealogy_history` contains every individual indexed
  by their individual number as in the genealogy tree.
  
  The produced genealogy tree is compatible with `NetworkX
  <http://networkx.lanl.gov/index.html>`_, here is how to plot the genealogy
  tree ::
  
      history = History()
  
      # Decorate the variation operators
      toolbox.decorate("mate", history.decorator)
      toolbox.decorate("mutate", history.decorator)
  
      # Create the population and populate the history
      population = toolbox.population(n=POPSIZE)
      history.update(population)
  
      # Do the evolution, the decorators will take care of updating the
      # history
      # [...]
  
      import matplotlib.pyplot as plt
      import networkx
  
      graph = networkx.DiGraph(history.genealogy_tree)
      graph = graph.reverse()     # Make the graph top-down
      colors = [toolbox.evaluate(history.genealogy_history[i])[0] for i in graph]
      networkx.draw(graph, node_color=colors)
      plt.show()
  
  Using NetworkX in combination with `pygraphviz
  <http://networkx.lanl.gov/pygraphviz/>`_ (dot layout) this amazing
  genealogy tree can be obtained from the OneMax example with a population
  size of 20 and 5 generations, where the color of the nodes indicate their
  fitness, blue is low and red is high.
  
  .. image:: /_images/genealogy.png
     :width: 67%
  
  .. note::
     The genealogy tree might get very big if your population and/or the
     number of generation is large.
class_docstr_tok: ["The",":","class",":","`","History","`","class","helps","to","build","a","genealogy","of","all","the","individuals","produced","in","the","evolution",".","It","contains","two","attributes",",","the",":","attr",":","`","genealogy_tree","`","that","is","a","dictionary","of","lists","indexed","by","individual",",","the","list","contain","the","indices","of","the","parents",".","The","second","attribute",":","attr",":","`","genealogy_history","`","contains","every","individual","indexed","by","their","individual","number","as","in","the","genealogy","tree",".","The","produced","genealogy","tree","is","compatible","with","`","NetworkX","<","http",":","\/\/networkx.lanl.gov\/index.html",">","`","_",",","here","is","how","to","plot","the","genealogy","tree",":",":","history","=","History","(",")","#","Decorate","the","variation","operators","toolbox.decorate","(","``","mate","''",",","history.decorator",")","toolbox.decorate","(","``","mutate","''",",","history.decorator",")","#","Create","the","population","and","populate","the","history","population","=","toolbox.population","(","n=POPSIZE",")","history.update","(","population",")","#","Do","the","evolution",",","the","decorators","will","take","care","of","updating","the","#","history","#","[","...","]","import","matplotlib.pyplot","as","plt","import","networkx","graph","=","networkx.DiGraph","(","history.genealogy_tree",")","graph","=","graph.reverse","(",")","#","Make","the","graph","top-down","colors","=","[","toolbox.evaluate","(","history.genealogy_history","[","i","]",")","[","0","]","for","i","in","graph","]","networkx.draw","(","graph",",","node_color=colors",")","plt.show","(",")","Using","NetworkX","in","combination","with","`","pygraphviz","<","http",":","\/\/networkx.lanl.gov\/pygraphviz\/",">","`","_","(","dot","layout",")","this","amazing","genealogy","tree","can","be","obtained","from","the","OneMax","example","with","a","population","size","of","20","and","5","generations",",","where","the","color","of","the","nodes","indicate","their","fitness",",","blue","is","low","and","red","is","high",".","..","image",":",":","\/_images\/genealogy.png",":","width",":","67","%","..","note",":",":","The","genealogy","tree","might","get","very","big","if","your","population","and\/or","the","number","of","generation","is","large","."]
docstr: Update the history with the new *individuals*. The index present in
  their :attr:`history_index` attribute will be used to locate their
  parents, it is then modified to a unique one to keep track of those
  new individuals. This method should be called on the individuals after
  each variation.
  
  :param individuals: The list of modified individuals that shall be
                      inserted in the history.
  
  If the *individuals* do not have a :attr:`history_index` attribute,
  the attribute is added and this individual is considered as having no
  parent. This method should be called with the initial population to
  initialize the history.
  
  Modifying the internal :attr:`genealogy_index` of the history or the
  :attr:`history_index` of an individual may lead to unpredictable
  results and corruption of the history.
docstr_tok: ["Update","the","history","with","the","new","*","individuals","*",".","The","index","present","in","their",":","attr",":","`","history_index","`","attribute","will","be","used","to","locate","their","parents",",","it","is","then","modified","to","a","unique","one","to","keep","track","of","those","new","individuals",".","This","method","should","be","called","on","the","individuals","after","each","variation",".",":","param","individuals",":","The","list","of","modified","individuals","that","shall","be","inserted","in","the","history",".","If","the","*","individuals","*","do","not","have","a",":","attr",":","`","history_index","`","attribute",",","the","attribute","is","added","and","this","individual","is","considered","as","having","no","parent",".","This","method","should","be","called","with","the","initial","population","to","initialize","the","history",".","Modifying","the","internal",":","attr",":","`","genealogy_index","`","of","the","history","or","the",":","attr",":","`","history_index","`","of","an","individual","may","lead","to","unpredictable","results","and","corruption","of","the","history","."]
code: def update(self, individuals):
      """Update the history with the new *individuals*. The index present in
      their :attr:`history_index` attribute will be used to locate their
      parents, it is then modified to a unique one to keep track of those
      new individuals. This method should be called on the individuals after
      each variation.
  
      :param individuals: The list of modified individuals that shall be
                          inserted in the history.
  
      If the *individuals* do not have a :attr:`history_index` attribute,
      the attribute is added and this individual is considered as having no
      parent. This method should be called with the initial population to
      initialize the history.
  
      Modifying the internal :attr:`genealogy_index` of the history or the
      :attr:`history_index` of an individual may lead to unpredictable
      results and corruption of the history.
      """
      try:
          parent_indices = tuple(
              ind.history_index for ind in individuals
          )
      except AttributeError:
          parent_indices = tuple()
  
      for ind in individuals:
          self.genealogy_index += 1
          ind.history_index = self.genealogy_index
          self.genealogy_history[self.genealogy_index] = deepcopy(ind)
          self.genealogy_tree[self.genealogy_index] = parent_indices
  
imports: from bisect import bisect_right
  from collections import defaultdict
  from copy import deepcopy
  from functools import partial
  from itertools import chain
  from operator import eq
label_desc: Use image node_id 2 for calling the History obj's underlying member method code with example usage: obj.update(individuals) without return types