def search(experience_number):
    fragments = base.read_data_from_file(experience_number, 'fragment')
    increase_fragments_count(fragments)
    best_reference_seq = {
        'first': None,
        'second': None,
        'score': 0
    }
    for i in range(MAX_HILL_CLIMBS_COUNT):
        print('hill climb number ' + str(i) + '...')
        local_best_reference_seqs = climb_hill(fragments)
        if local_best_reference_seqs['score'] > best_reference_seq['score']:
            best_reference_seq = local_best_reference_seqs
    haplotypes = base.read_data_from_file(experience_number, 'haplotype')
    print('Accuracy 1: ' + str((base.HAPLOTYPE_LENGTH - base.calculate_hamming_distance(
        best_reference_seq['first'], haplotypes[0])) / base.HAPLOTYPE_LENGTH))
    print('Accuracy 2: ' + str((base.HAPLOTYPE_LENGTH - base.calculate_hamming_distance(
        best_reference_seq['second'], haplotypes[1])) / base.HAPLOTYPE_LENGTH))
示例#2
0
def search(experience_number):
    global FRAGMENTS_COUNT
    fragments = base.read_data_from_file(experience_number, 'fragment')
    FRAGMENTS_COUNT += len(fragments)
    first_reference_sequence = generate_base_reference_sequence()
    second_reference_sequence = generate_base_reference_sequence()
    for fragment in fragments:
        if are_compatible(first_reference_sequence, fragment):
            first_reference_sequence = combine(first_reference_sequence,
                                               fragment)
        elif are_compatible(second_reference_sequence, fragment):
            second_reference_sequence = combine(second_reference_sequence,
                                                fragment)
        else:
            print('Conflict.')
    haplotypes = base.read_data_from_file(experience_number, 'haplotype')
    if (are_compatible(haplotypes[0], first_reference_sequence)
            and are_compatible(haplotypes[1], second_reference_sequence)):
        print('100% match!')
def search(experience_number):
    fragments = base.read_data_from_file(experience_number, 'fragment')
    increase_fragments_count(fragments)
    init_edges_pheromones(fragments)
    best_sequences = {'score': 0}
    for i in range(ANTS_COUNT):
        print('Deploying ant number ' + str(i) + '...')
        sequences = deploy_ant(fragments)
        if sequences['score'] > best_sequences['score']:
            best_sequences['first'] = sequences['first']
            best_sequences['second'] = sequences['second']
            best_sequences['score'] = sequences['score']
    haplotypes = base.read_data_from_file(experience_number, 'haplotype')
    print('Accuracy 1: ' +
          str((base.HAPLOTYPE_LENGTH - base.calculate_hamming_distance(
              best_sequences['first'], haplotypes[0])) /
              base.HAPLOTYPE_LENGTH))
    print('Accuracy 2: ' +
          str((base.HAPLOTYPE_LENGTH - base.calculate_hamming_distance(
              best_sequences['second'], haplotypes[1])) /
              base.HAPLOTYPE_LENGTH))
def search(experience_number):
    fragments = base.read_data_from_file(experience_number, 'fragment')
    increase_fragments_count(fragments)
    best_sequence_pair = {'score': 0}
    population = generate_random_population()
    for i in range(10):
        print('Generation number ' + str(i) + '...')
        population = reproduce_new_population(population, fragments)
        best, score = get_fittest_in_population(population, fragments)
        if score > best_sequence_pair['score']:
            best_sequence_pair['first'] = best[0]
            best_sequence_pair['second'] = best[1]
            best_sequence_pair['score'] = score
    haplotypes = base.read_data_from_file(experience_number, 'haplotype')
    print('Accuracy 1: ' +
          str((base.HAPLOTYPE_LENGTH - base.calculate_hamming_distance(
              best_sequence_pair['first'], haplotypes[0])) /
              base.HAPLOTYPE_LENGTH))
    print('Accuracy 2: ' +
          str((base.HAPLOTYPE_LENGTH - base.calculate_hamming_distance(
              best_sequence_pair['second'], haplotypes[1])) /
              base.HAPLOTYPE_LENGTH))