def search(points, maxIterations, maxTabu, maxCandidates): # construct a random tour best = {} best["loopIter"] = constructInitialSolution(points) """Call constraint set solver to get distance d between 2 polyhedra""" best["cost"] = tourCost(best["loopIter"]) tabuList = [] while maxIterations > 0: # Generate candidates using stocahstic 2-opt near current best candidate # Use Tabu list to not revisit previous rewired edges candidates = [] for index in range(0, maxCandidates): candidates.append(generateCandidates(best, tabuList, points)) # Locate the best candidate # sort the list of candidates by cost # since it is an involved sort, we write a function for getting the least cost candidate bestCandidate, bestCandidateEdges = locateBestCandidate(candidates) # compare with current best and update if necessary if bestCandidate["cost"] < best["cost"]: # set current to the best, so thatwe can continue iteration best = bestCandidate # update tabu list for edge in bestCandidateEdges: if len(tabuList) < maxTabu: tabuList.append(edge) maxIterations -= 1 return best
def generateCandidates(best, tabuList, points): permutation, edges, result = None, None, {} while permutation == None or isTabu(best["loopIter"], tabuList): permutation, edges = stochasticTwoOptWithEdges(best["loopIter"]) candidate = {} candidate["loopIter"] = permutation """Call constraint set solver to get distance d between 2 polyhedra""" candidate["cost"] = tourCost(candidate["loopIter"]) result["candidate"] = candidate result["edges"] = edges return result