def neighbours_LNS(data, perm, size = 2): # Returns the Large Neighbourhood Search neighbours candidates = [perm] # Bound the number of neighbourhoods in case there are too many jobs neighbourhoods = list(combinations(range(len(perm)), size)) random.shuffle(neighbourhoods) for subset in neighbourhoods[:flow.MAX_LNS_NEIGHBOURHOODS]: # Keep track of the best candidate for each neighbourhood best_make = flow.makespan(data, perm) best_perm = perm # Enumerate every permutation of the selected neighbourhood for ordering in permutations(subset): candidate = perm[:] for i in range(len(ordering)): candidate[subset[i]] = perm[ordering[i]] res = flow.makespan(data, candidate) if res < best_make: best_make = res best_perm = candidate # Record the best candidate as part of the larger neighbourhood candidates.append(best_perm) return candidates
def neighbours_LNS(data, perm, size=2): # Returns the Large Neighbourhood Search neighbours candidates = [perm] # Bound the number of neighbourhoods in case there are too many jobs neighbourhoods = list(combinations(range(len(perm)), size)) random.shuffle(neighbourhoods) for subset in neighbourhoods[:flow.MAX_LNS_NEIGHBOURHOODS]: # Keep track of the best candidate for each neighbourhood best_make = flow.makespan(data, perm) best_perm = perm # Enumerate every permutation of the selected neighbourhood for ordering in permutations(subset): candidate = perm[:] for i in range(len(ordering)): candidate[subset[i]] = perm[ordering[i]] res = flow.makespan(data, candidate) if res < best_make: best_make = res best_perm = candidate # Record the best candidate as part of the larger neighbourhood candidates.append(best_perm) return candidates
def neighbours_LNS(data, perm, size = 2): # Returns the Large Neighbourhood Search neighbours # 返回最大的相邻搜索点集 candidates = [perm] # 限定最大的搜索数量 neighbourhoods = list(combinations(range(len(perm)), size)) random.shuffle(neighbourhoods) for subset in neighbourhoods[:flow.MAX_LNS_NEIGHBOURHOODS]: # 记录每个候选集中表现最好的候选点 best_make = flow.makespan(data, perm) best_perm = perm # Enumerate every permutation of the selected neighbourhood # 枚举选中邻域的每个排列 for ordering in permutations(subset): candidate = perm[:] for i in range(len(ordering)): candidate[subset[i]] = perm[ordering[i]] res = flow.makespan(data, candidate) if res < best_make: best_make = res best_perm = candidate # 将最好的结果保存到候选集尾部 candidates.append(best_perm) return candidates
def heur_random_hillclimbing(data, candidates): # Returns a candidate with probability proportional to its rank in sorted quality scores = [(flow.makespan(data, perm), perm) for perm in candidates] i = 0 while (random.random() < 0.5) and (i < len(scores) - 1): i += 1 return sorted(scores)[i][1]
def heur_random_hillclimbing(data, candidates): # 考虑每个方案的排名,进行加权随机选取 scores = [(flow.makespan(data, perm), perm) for perm in candidates] i = 0 while (random.random() < 0.5) and (i < len(scores) - 1): i += 1 return sorted(scores)[i][1]
def heur_hillclimbing(data, candidates): # Returns the best candidate in the list scores = [(flow.makespan(data, perm), perm) for perm in candidates] return sorted(scores)[0][1]
def heur_hillclimbing(data, candidates): # 返回候选集中最好的方案 scores = [(flow.makespan(data, perm), perm) for perm in candidates] return sorted(scores)[0][1]