示例#1
0
def determineTasks(genotypes):

  global TASKS

  # Initialize task list
  if TASKS == []:
    TASKS = avida.get_tasks()

  # If genotypes is a single genotype, convert to a list
  try:
    iter(genotypes)
  except:
    genotypes = [genotypes]

  # Copy the sequences of each genotype into a new sequence string list
  # because avida.calc_info takes in a list of sequence strings
  seqs = [genotype.sequence for genotype in genotypes]

  # Get task list
  seqs_info = avida.get_info(seqs, ['task_list'])
  task_list = seqs_info['task_list']

  # Update each genotype with its tasks
  for genotype, tasks in zip(genotypes, task_list):
    genotype.setTasks(tasks)
示例#2
0
def measureFitness(genotypes, environmentFileName = None):

  # If genotypes is a single genotype, convert to a list
  if not isinstance(genotypes, list):
    genotypes = [genotypes]

  # Copy the sequences of each genotype into a new sequence string list
  # because avida.calc_info takes in a list of sequence strings
  seqs = [genotype.sequence for genotype in genotypes]

  # Get fitnesses and viability
  avida.set_environment(environmentFileName)
  seqs_info = avida.get_info(seqs, ['fitness', 'viable'])
  fitnesses = seqs_info['fitness']
  viability = seqs_info['viable']
  avida.reset_environment()

  # Update each genotype, ensuring unviable sequences have 0 fitness
  for genotype, fitness, viable in zip(genotypes, fitnesses, viability):
    genotype.fitness = fitness * viable