def test_preffered(self): swaps = list(sgp.swaps(self.solution)) #print(swaps) violats = list(map(lambda t: (sgp.evaluate_swap(self.solution, t), t), swaps)) print(min(violats), max(violats)) """self.assertEqual(
def learning(self, solution): tabu = [ {} for week in solution ] best_solution = copy.deepcopy(solution) best_violations = sgp.violations(solution)[0] # wie lange wird weiter gesucht, obwohl keine verbesserung eintritt #learning_semaphore = self.max_learning for iteration in range(self.groups * self.weeks): if best_violations == 0 or self.timeout: # were done break try: # von allen Täuschen, den besten finden nex_viol, w, a, b = min( filter( # entweder verbessert dieser Tausch diese Lösung zur Besten # oder er ist nicht tabu lambda t: t[0] < best_violations or not tuple(sorted((t[2], t[3]))) in tabu[t[1]] or tabu[t[1]][tuple(sorted((t[2], t[3])))] < iteration, map( lambda t: (sgp.evaluate_swap(solution, t), t[0], t[1], t[2]), sgp.swaps(solution) ) ) ) sgp.swap(solution, w, a, b) tabu[w][tuple(sorted((a, b)))] = iteration + random.randint(4, 100) if nex_viol < best_violations: best_solution = solution best_violations = nex_viol print(best_violations, end=' ') sys.stdout.flush() except ValueError as e: break return best_solution