Adapt main module to the requirements
This commit is contained in:
parent
6ccc1cb661
commit
89045a04c8
|
@ -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:
|
||||
|
|
30
src/main.py
30
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()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue