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
|
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)
|
initial_solutions = generate_initial_solutions(n, m, data, number_solutions)
|
||||||
solutions = []
|
solutions = []
|
||||||
for solution in initial_solutions:
|
for solution in initial_solutions:
|
||||||
|
|
30
src/main.py
30
src/main.py
|
@ -1,27 +1,14 @@
|
||||||
from preprocessing import parse_file
|
from preprocessing import parse_file
|
||||||
from genetic_algorithm import genetic_algorithm
|
from local_search import multistart_local_search
|
||||||
from memetic_algorithm import memetic_algorithm
|
from simulated_annealing import simulated_annealing
|
||||||
from time import time
|
from time import time
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
|
||||||
def execute_algorithm(args, n, m, data):
|
def execute_algorithm(args, n, m, data):
|
||||||
if args.algorithm == "genetic":
|
if args.algorithm == "annealing":
|
||||||
return genetic_algorithm(
|
return simulated_annealing(n, m, data, max_iterations=100)
|
||||||
n,
|
return multistart_local_search(n, m, data)
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def show_results(solution, time_delta):
|
def show_results(solution, time_delta):
|
||||||
|
@ -36,12 +23,7 @@ def show_results(solution, time_delta):
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
parser.add_argument("file", help="dataset of choice")
|
parser.add_argument("file", help="dataset of choice")
|
||||||
subparsers = parser.add_subparsers(dest="algorithm")
|
parser.add_argument("algorithm", choices=["annealing", "multisearch"])
|
||||||
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"])
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue