def detecting_nodes(boxes, B): #boxes are list of cer and uncer curve mixes_boxes = [[1, box] for box in boxes[0]] + [ [0, box] for box in boxes[1] ] #putting flaggs for cer and uncer boxes ftboxes = [[ box[0], [d.ftconstructor(boxi[0], boxi[1]) for boxi in box[1]] ] for box in mixes_boxes] nodes_lifting = [] used = [] for i in range(len(ftboxes)): for j in range(i + 1, len(ftboxes)): if d.boxes_intersection(ftboxes[1][i],ftboxes[1][j]) ==[] and \ d.boxes_intersection(ftboxes[1][i][:2],ftboxes[1][j][:2]) : if i not in used: used.append(i) nodes_lifting.append(ftboxes[i]) if j not in used: used.append(j) nodes_lifting.append(ftboxes[j]) components = planner_connected_compnants(nodes_lifting) cer_components = [] uncer_components = [] for component in components: if 0 in [box[0] for box in component]: cer_components.append([box[1] for box in component]) else: uncer_components.append([box[1] for box in component]) return [cer_components, uncer_components]
def planner_connected_compnants(boxes): ftboxes = boxes[:] #ftboxes=[ [d.ftconstructor(boxi[0],boxi[1]) for boxi in box ] for box in boxes ] components = [[ftboxes[0]]] for i in range(1, len(ftboxes)): boxi_isused = 0 for j in range(len(components)): membership = 0 for k in range(len(components[j])): if d.boxes_intersection(ftboxes[i][1][:2],components[j][k][1][:2]) !=[] and \ d.boxes_intersection(ftboxes[i][1],components[j][k][1]) ==[]: components[j].append(ftboxes[i]) membership = 1 boxi_isused = 1 break if membership == 1: break if boxi_isused == 0: components.append([ftboxes[i]]) unused = list(range(len(components))) components1 = components[:] components2 = [] while len(components1) != len(components2): for i in unused: for j in [ j for j in list(range(i + 1, len(components))) if j in unused ]: intersection_exists = False is_looping = True for boxi in components[i]: for boxj in components[j]: if d.boxes_intersection(boxi[1],boxj[1])==[] and \ d.boxes_intersection(boxi[1][:2],boxj[1][:2]) != [] : is_looping = False intersection_exists = True break if is_looping == False: break if intersection_exists == True: components[i] += components[j] unused.remove(j) components2 = components1[:] components1 = [components[k] for k in unused] return components1 return components
def assum_alph3_checker(solutions): comparing_list = [[]] * len(solutions) for i in range(len(solutions) - 1): for j in range(i + 1, len(solutions)): if d.boxes_intersection(solutions[i][:2], solutions[j][:2]) != []: comparing_list[i].append(j) comparing_list[j].append(i) matching = [len(T) for T in comparing_list] if max(matching) <= 2: return 1 else: return 0
def detecting_nodes(boxes, B, f, X): #boxes are list of cer and uncer curve mixes_boxes = [[1, box] for box in boxes[0]] + [ [0, box] for box in boxes[1] ] #putting flaggs for cer and uncer boxes ftboxes = [[ box[0], [d.ftconstructor(boxi[0], boxi[1]) for boxi in box[1]] ] for box in mixes_boxes] nodes_lifting = [] used = [] for i in range(len(ftboxes)): for j in range(i + 1, len(ftboxes)): if d.boxes_intersection(ftboxes[i][1],ftboxes[j][1]) ==[] and \ d.boxes_intersection(ftboxes[i][1][:2],ftboxes[j][1][:2]) : if i not in used: used.append(i) nodes_lifting.append(ftboxes[i]) if j not in used: used.append(j) nodes_lifting.append(ftboxes[j]) components = planner_connected_compnants(nodes_lifting) cer_components = [] uncer_components = [] component_normal = [] for component in components: boxes_component = [box[1] for box in component] component_normal = [[[float(Bi.lower()), float(Bi.upper())] for Bi in box[1]] for box in component] if 0 not in [box[0] for box in component] and eval_file_gen( f, component_normal, X) == "[]\n": cer_components.append(boxes_component) else: uncer_components.append(boxes_component) return [cer_components, uncer_components]
def connected_compnants(boxes): ftboxes = [[d.ftconstructor(boxi[0], boxi[1]) for boxi in box] for box in boxes] components = [[ftboxes[0]]] for i in range(1, len(ftboxes)): boxi_isused = 0 for j in range(len(components)): membership = 0 for k in range(len(components[j])): if d.boxes_intersection(ftboxes[i], components[j][k]) != []: components[j].append(ftboxes[i]) membership = 1 boxi_isused = 1 break if membership == 1: break if boxi_isused == 0: components.append([ftboxes[i]]) return components