def bicycle_algorithm(self): errors = [] for e in self.graph.errors: errors.append(e) if len(errors) != 2: print "errors not equal 2, return false" return False left = errors[0] right = errors[1] (v1, v2) = left.get_endpoints() (v3, v4) = right.get_endpoints() la = left.link_color(v1) lb = left.link_color(v2) ra = right.link_color(v3) rb = right.link_color(v4) a, b = la, lb if (la, lb) == (ra, rb): pass elif (la, lb) == (rb, ra): v3, v4 = v4, v3 else: print "Two variable not same, return false" return False left_p = create_path(self.graph, v1, b, a) if left_p.is_closed() != True: count_utility.count(-1) left_p.swap_colors(b, a) return True right_p = create_path(self.graph, v3, b, a) len_left = len(left_p) len_right = len(right_p) steps = 0 for i in range(0, 2 * len_left): for j in range(0, 2 * len_right): if self.sub_routine_for_bicycle_algorithm(left_p, right_p): count_utility.count(steps) return True right_p.move_one_step() steps = steps + 1 left_p.move_one_step() return False
def bicycle_algorithm(self): errors = [] for e in self.graph.errors: errors.append(e) if len(errors) != 2: print ("errors not equal 2, return false") return False left = errors[0] right = errors[1] (v1, v2) = left.get_endpoints() (v3, v4) = right.get_endpoints() la = left.link_color(v1) lb = left.link_color(v2) ra = right.link_color(v3) rb = right.link_color(v4) a, b = la, lb if (la, lb) == (ra, rb): pass elif (la, lb) == (rb, ra): v3, v4 = v4, v3 else: print ("Two variable not same, return false") return False left_p = create_path(self.graph, v1, b, a) if left_p.is_closed() != True: count_utility.count(-1) left_p.swap_colors(b, a) return True right_p = create_path(self.graph, v3, b, a) len_left = len(left_p) len_right = len(right_p) steps = 0 for i in range(0, 2 * len_left): for j in range(0, 2 * len_right): if self.sub_routine_for_bicycle_algorithm(left_p, right_p): count_utility.count(steps) return True right_p.move_one_step() steps = steps + 1 left_p.move_one_step() return False
def false_algorithm_1(self): errors = [] for e in self.graph.errors: errors.append(e) if len(errors) != 2: print "errors not equal 2, return false" return False left = errors[0] right = errors[1] (v1, v2) = left.get_endpoints() (v3, v4) = right.get_endpoints() la = left.link_color(v1) lb = left.link_color(v2) ra = right.link_color(v3) rb = right.link_color(v4) a, b = la, lb if (la, lb) == (ra, rb): pass elif (la, lb) == (rb, ra): v3, v4 = v4, v3 else: print "Two variable not same, return false" return False left_p = create_path(self.graph, v1, b, a) if left_p.is_closed() != True: left_p.swap_colors(b, a) return True if self.graph.multiplicity(v1, v3) == 1: x, y = v1, v3 elif self.graph.multiplicity(v1, v4) == 1: x, y = v1, v4 elif self.graph.multiplicity(v2, v3) == 1: x, y = v2, v3 elif self.graph.multiplicity(v2, v4) == 1: x, y = v2, v4 else: raise Exception("weriuhgas") xx = v1 + v2 - x yy = v3 + v4 - y vid_x = self.graph.neighbor_vid_list(x) vid_y = self.graph.neighbor_vid_list(y) vid_x.remove(y) vid_y.remove(x) x1, x2 = vid_x y1, y2 = vid_y def list_to_set(li): ss = set() for x in li: ss.add(x) return ss temp1 = self.graph.neighbor_vid_list(x1) ################### right_p = create_path(self.graph, v3, b, a) len_left = len(left_p) len_right = len(right_p) steps = 0 for i in range(0, 2 * len_left): for j in range(0, 2 * len_right): if self.sub_routine_for_bicycle_algorithm(left_p, right_p): count_utility.count(steps) return True right_p.move_one_step() steps = steps + 1 left_p.move_one_step() return False
def false_algorithm_1(self): errors = [] for e in self.graph.errors: errors.append(e) if len(errors) != 2: print ("errors not equal 2, return false") return False left = errors[0] right = errors[1] (v1, v2) = left.get_endpoints() (v3, v4) = right.get_endpoints() la = left.link_color(v1) lb = left.link_color(v2) ra = right.link_color(v3) rb = right.link_color(v4) a, b = la, lb if (la, lb) == (ra, rb): pass elif (la, lb) == (rb, ra): v3, v4 = v4, v3 else: print ("Two variable not same, return false") return False left_p = create_path(self.graph, v1, b, a) if left_p.is_closed() != True: left_p.swap_colors(b, a) return True if self.graph.multiplicity(v1, v3) == 1: x, y = v1, v3 elif self.graph.multiplicity(v1, v4) == 1: x, y = v1, v4 elif self.graph.multiplicity(v2, v3) == 1: x, y = v2, v3 elif self.graph.multiplicity(v2, v4) == 1: x, y = v2, v4 else: raise Exception("weriuhgas") xx = v1 + v2 - x yy = v3 + v4 - y vid_x = self.graph.neighbor_vid_list(x) vid_y = self.graph.neighbor_vid_list(y) vid_x.remove(y) vid_y.remove(x) x1, x2 = vid_x y1, y2 = vid_y def list_to_set(li): ss = set() for x in li: ss.add(x) return ss temp1 = self.graph.neighbor_vid_list(x1) ################### right_p = create_path(self.graph, v3, b, a) len_left = len(left_p) len_right = len(right_p) steps = 0 for i in range(0, 2 * len_left): for j in range(0, 2 * len_right): if self.sub_routine_for_bicycle_algorithm(left_p, right_p): count_utility.count(steps) return True right_p.move_one_step() steps = steps + 1 left_p.move_one_step() return False