From 89045a04c8c42504f765af10c7f069c683ef7c71 Mon Sep 17 00:00:00 2001 From: coolneng Date: Tue, 22 Jun 2021 09:14:50 +0200 Subject: [PATCH] Adapt main module to the requirements --- src/local_search.py | 2 +- src/main.py | 30 ++++++------------------------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/local_search.py b/src/local_search.py index 7ead8ad..ca65f9e 100644 --- a/src/local_search.py +++ b/src/local_search.py @@ -97,7 +97,7 @@ def evaluate_all_solutions(solutions, data, cores=4): return fitness -def local_search(n, m, data, number_solutions=10): +def multistart_local_search(n, m, data, number_solutions=10): initial_solutions = generate_initial_solutions(n, m, data, number_solutions) solutions = [] for solution in initial_solutions: diff --git a/src/main.py b/src/main.py index 887484b..f4a64df 100755 --- a/src/main.py +++ b/src/main.py @@ -1,27 +1,14 @@ from preprocessing import parse_file -from genetic_algorithm import genetic_algorithm -from memetic_algorithm import memetic_algorithm +from local_search import multistart_local_search +from simulated_annealing import simulated_annealing from time import time from argparse import ArgumentParser def execute_algorithm(args, n, m, data): - if args.algorithm == "genetic": - return genetic_algorithm( - n, - m, - data, - select_mode=args.selection, - crossover_mode=args.crossover, - max_iterations=100, - ) - return memetic_algorithm( - n, - m, - data, - hybridation=args.hybridation, - max_iterations=100, - ) + if args.algorithm == "annealing": + return simulated_annealing(n, m, data, max_iterations=100) + return multistart_local_search(n, m, data) def show_results(solution, time_delta): @@ -36,12 +23,7 @@ def show_results(solution, time_delta): def parse_arguments(): parser = ArgumentParser() parser.add_argument("file", help="dataset of choice") - subparsers = parser.add_subparsers(dest="algorithm") - parser_genetic = subparsers.add_parser("genetic") - parser_memetic = subparsers.add_parser("memetic") - parser_genetic.add_argument("crossover", choices=["uniform", "position"]) - parser_genetic.add_argument("selection", choices=["generational", "stationary"]) - parser_memetic.add_argument("hybridation", choices=["all", "random", "best"]) + parser.add_argument("algorithm", choices=["annealing", "multisearch"]) return parser.parse_args()