def choose_sequence(self): selected_sequence = TabuSequence() sequence_decision = [] for i, generated_sequence in enumerate(self.generated_neighbour_list): if not generated_sequence.values['decision'] == 'tabu': print('neighbour error', generated_sequence.error) if generated_sequence.error <= self.best_sequence.error: self.best_sequence = copy.deepcopy(generated_sequence) selected_sequence = copy.deepcopy(self.best_sequence) sequence_decision.append('best sequence') elif generated_sequence.error < selected_sequence.error: selected_sequence = copy.deepcopy(generated_sequence) selected_sequence.values['decision'] = 'selected sequence' sequence_decision.append('selected sequence') else: sequence_decision.append('not_chosen') else: sequence_decision.append('tabu') self.prev_sequence_list.append(selected_sequence) self.prev_sequence = selected_sequence self.generated_neighbour_list = [] print('decision', sequence_decision) return sequence_decision
def next_iteration(self, iteration_number): print('next iteration') new_sequence = TabuSequence() new_sequence.values['iteration number'] = iteration_number new_sequence.coming_sequence = self.generate_random(self.prev_sequence.coming_sequence) new_sequence.going_sequence = self.generate_random(self.prev_sequence.going_sequence) if self.same_generated(new_sequence): print('same') self.next_iteration(iteration_number) else: print('diff') self.generated_neighbour_list.append(new_sequence) return new_sequence