def findChains(inputObjectSet, params,objectDict): '''finds all the chains, then returns the ones that satisfy constraints, sorted from best to worst.''' bestlines = [] explored = set() pairwise = cluster_util.find_pairs(inputObjectSet) pairwise.sort(key=lambda p: p[0].distance_to(p[1].representation),reverse=False) for pair in pairwise: start,finish = pair[0],pair[1] if frozenset([start.uuid,finish.uuid]) not in explored: result = chainSearch(start, finish, inputObjectSet,params) if result != None: bestlines.append(result) s = map(frozenset,cluster_util.find_pairs(result[0:len(result)-1])) map(explored.add,s) verybest = [] costSum = 0 for line in bestlines: if len(line)>params.min_line_length: verybest.append(line) verybest.sort(key=lambda l: len(l),reverse=True) costs = map(lambda l: l.pop()+1.5,verybest) data = np.array(map(lambda x: (x.representation.middle,x.uuid),inputObjectSet)) output = [] for i in zip(costs,verybest): output.append(landmark.GroupLineRepresentation([objectDict.get(j) for j in i[1]],i[0])) return output
def findChains(inputObjectSet, params ): '''finds all the chains, then returns the ones that satisfy constraints, sorted from best to worst.''' bestlines = [] explored = set() pairwise = cluster_util.find_pairs(inputObjectSet) pairwise.sort(key=lambda p: cluster_util.findDistance(p[0].position, p[1].position),reverse=False) for pair in pairwise: start,finish = pair[0],pair[1] if frozenset([start.id,finish.id]) not in explored: result = chainSearch(start, finish, inputObjectSet,params) if result != None: bestlines.append(result) s = map(frozenset,cluster_util.find_pairs(result[0:len(result)-1])) map(explored.add,s) verybest = [] costSum = 0 for line in bestlines: if len(line)>params.min_line_length: verybest.append(line) verybest.sort(key=lambda l: len(l),reverse=True) costs = map(lambda l: l.pop()+2,verybest) listOfTheWordLine = ["line"]*len(costs) data = np.array(map(lambda x: (x.position,x.id),inputObjectSet)) return zip(costs,verybest,listOfTheWordLine)
def findChains(inputObjectSet, params, distanceMatrix=-1): '''finds all the chains, then returns the ones that satisfy constraints, sorted from best to worst.''' if distanceMatrix == -1: distanceMatrix = cluster_util.create_distance_matrix(inputObjectSet) bestlines = [] explored = set() pairwise = cluster_util.find_pairs(inputObjectSet) pairwise.sort( key=lambda p: cluster_util.findDistance(p[0].position, p[1].position), reverse=False) for pair in pairwise: start, finish = pair[0], pair[1] if frozenset([start.id, finish.id]) not in explored: result = chainSearch(start, finish, inputObjectSet, params, distanceMatrix) if result != None: bestlines.append(result) s = map(frozenset, cluster_util.find_pairs(result[0:len(result) - 1])) map(explored.add, s) verybest = [] costSum = 0 for line in bestlines: if len(line) > params.min_line_length: verybest.append(line) verybest.sort(key=lambda l: len(l), reverse=True) costs = map(lambda l: l.pop() + 2, verybest) data = np.array(map(lambda x: (x.position, x.id), inputObjectSet)) output = [] for i in zip(costs, verybest): output.append(cluster_util.LineBundle(i[1], i[0])) return output