def get_fitnessSoCPriority(guess_instance, apadCoordinates):
    """
    Calculating fitness function for set of genes given with guess_instance.
    Fitness function for now is just total distance between
    :param guess_instance: instance of Guess class
    :return: float (fitness)
    """
    return 1 / (
        1 + salesman.total_distance(guess_instance.points, apadCoordinates))
Example #2
0
def scenarioGoToNearest():
    system = parser(filename="evolutionary_init.txt")
    mussel_coordinates = [list(item.coordinates) for item in system.mussels]
    start = min(mussel_coordinates,
                key=lambda x: distance(list(system.pads[0].coordinates), x))
    points = go_to_nearest(system, start)
    totalDistance = total_distance(points)
    system.plot_topology(
        annotate_energy=False,
        order_of_passing=True,
        title=
        "Way of prioritizing: Go to nearest point with nearest first point; Total Distance: {}"
        .format(totalDistance))
def main(points, apadCoordinates):
    n = 25  # POPULATION SIZE
    mut_prob = 0.08  # MUTATION PROBABILITY
    number_of_iterations = 12500  # NUMBER OF ITERATION7
    global points_dict
    for i in range(0, len(points)):
        points_dict[i + 1] = points[i]

    best = k_gen_algorithm(points, n, number_of_iterations, mut_prob,
                           apadCoordinates)
    print("Best guess is: {}".format([points_dict[item]
                                      for item in best.gene]))
    print("Best guess is: {}".format(best.gene))
    print("Best length is: {}".format(
        salesman.total_distance(best.points, apadCoordinates)))
    print("Best fitness is: {}".format(get_fitness(best, apadCoordinates)))
    return (best, points_dict)
Example #4
0
def scenarioEvolutionary():
    system = parser(filename="evolutionary_init.txt")
    mussel_coordinates = [list(item.coordinates) for item in system.mussels]
    bestGene, points_dict = evolutionary.main(mussel_coordinates,
                                              system.pads[0].coordinates)
    switchDict = dict()
    for key, item in points_dict.items():
        switchDict[tuple(item)] = key
    # for i, mussel in enumerate(system.mussels):
    points = bestGene.points
    for i, mussel in enumerate(system.mussels):
        system.mussels[i].order_of_passing = points.index(
            list(mussel.coordinates))
    totalDistance = total_distance(points, system.pads[0].coordinates)
    system.plot_topology(
        annotate_energy=False,
        order_of_passing=True,
        title="Way of prioritizing: Evolutionary algorithm; Total Distance: {}"
        .format(totalDistance))