<jupyter_start><jupyter_text>JSSP Tabu Search and Genetic Algorithm ExampleThis notebook demonstrates how to use both parallel tabu seach and the genetic algorithm.<jupyter_code>from JSSP import CSVData

# initialize data
data_directory = '../data/given_data'
instance_data = CSVData(data_directory + '/sequenceDependencyMatrix.csv',
                              data_directory + '/machineRunSpeed.csv',
                              data_directory + '/jobTasks.csv')

# uncomment this to print the data that was read in
# print(instance_data)
from JSSP.genetic_algorithm import GASelectionEnum

output_dir = './example_output'
output_results = True
auto_open = True
verbose = True
benchmark = True
progress_bar = True

# TS parameters
ts_runtime = 30 # in seconds
num_processes = 4
num_solutions_per_process = 5
tabu_list_size = 50
neighborhood_size = 200
neighborhood_wait = 0.12
probability_change_machine = 0.8
reset_threshold = 100

# ga parameters
ga_runtime = 30 # in seconds
mutation_probability = 0.2
population_size = 100
selection_method = GASelectionEnum.FITNESS_PROPORTIONATE
selection_size = 5
population = []<jupyter_output><empty_output><jupyter_text>Tabu Search Before Genetic Algorithm<jupyter_code>from JSSP.solver import Solver

# create solver
solver = Solver(instance_data)

# run tabu seach
solver.tabu_search_time(runtime=ts_runtime,
                        num_processes=num_processes,
                        num_solutions_per_process=num_solutions_per_process,
                        tabu_list_size=tabu_list_size,
                        neighborhood_size=neighborhood_size,
                        neighborhood_wait=neighborhood_wait,
                        probability_change_machine=probability_change_machine,
                        reset_threshold=reset_threshold,
                        benchmark=benchmark,
                        verbose=verbose,
                        progress_bar=progress_bar
                        )

# add all tabu search solutions to population
for ts_agent in solver.ts_agent_list:
    population += ts_agent.all_solutions
    
# run genetic algorithm
solution = solver.genetic_algorithm_time(runtime=ga_runtime,
                                         population=population,
                                         population_size=population_size,
                                         selection_method_enum=selection_method,
                                         selection_size=selection_size,
                                         mutation_probability=mutation_probability, 
                                         benchmark=benchmark,
                                         verbose=verbose,
                                         progress_bar=progress_bar
                                        )

print('\nSolution:')
print(solution)

if output_results:
    if benchmark:
        solver.output_benchmark_results(output_dir, name='example_benchmark', auto_open=auto_open)
    else:
        solution.create_schedule_xlsx_file(output_dir)<jupyter_output>Running benchmark of TS
Parameters:
stopping_condition = 30
time_condition = True
num_solutions_per_process = 5
num_processes = 4
tabu_list_size = 50
neighborhood_size = 200
neighborhood_wait = 0.12
probability_change_machine = 0.8
reset_threshold = 100

Initial Solution's makespans:
[8472, 9358, 8268, 7362]

child TS process started. pid = 1535
child TS process started. pid = 1536
child TS process started. pid = 1538
child TS process started. pid = 1539<jupyter_text>Genetic Algorithm Before Tabu Search<jupyter_code>from JSSP.solver import Solver

# create solver
solver = Solver(instance_data)

# run genetic algorithm
solver.genetic_algorithm_time(runtime=ga_runtime, 
                              population_size=population_size, 
                              selection_method_enum=selection_method,
                              selection_size=selection_size,
                              mutation_probability=mutation_probability, 
                              benchmark=benchmark,
                              verbose=verbose,
                              progress_bar=progress_bar
                              )

# pass best solutions found to tabu search
initial_solutions = sorted(solver.ga_agent.result_population)[:num_processes]

# run tabu seach
solution = solver.tabu_search_time(runtime=ts_runtime,
                                   num_processes=num_processes,
                                   num_solutions_per_process=num_solutions_per_process,
                                   tabu_list_size=tabu_list_size,
                                   neighborhood_size=neighborhood_size,
                                   neighborhood_wait=neighborhood_wait,
                                   probability_change_machine=probability_change_machine,
                                   reset_threshold=reset_threshold,
                                   initial_solutions=initial_solutions,
                                   benchmark=benchmark,
                                   verbose=verbose,
                                   progress_bar=progress_bar
                                  )
    
print('\nSolution:')
print(solution)

if output_results:
    if benchmark:
        solver.output_benchmark_results(output_dir, name='example_benchmark', auto_open=auto_open)
    else:
        solution.create_schedule_xlsx_file(output_dir)<jupyter_output>Running benchmark of GA
Parameters:
stopping_condition = 30
time_condition = True
population_size = 100
selection_method = _fitness_proportionate_selection
mutation_probability = 0.2
{'fraction_non_alphanumeric': 0.051561106155218556, 'fraction_numerical': 0.014451382694023194, 'mean_word_length': 2.0684181718664476, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '375625', 'license': '0BSD', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1391, 'n_words': 284, 'path': 'examples/TS_and_GA_Example.ipynb', 'repo_name': 'mcfadd/Job_Shop_Schedule_Problem', 'size': '5605'}