示例#1
0
    def test_vertex_edge_merge(self, round):
        from four_color.GraphMerger import GraphMerger
        temp = self.graph
        content = self.graph.to_json()
        g1 = MultiGraph.from_json(content)
        g2 = MultiGraph.from_json(content)
        while round > 0:
            (g, elist) = GraphMerger.single_vertex_and_edge_merge(g1, g2)

            self.graph = g

            for eid in elist:
                xx, yy = eid
                edge = self.graph.get_edge_by_endpoints(xx, yy)
                self.remove_specified_edge(edge)

                if not self.edge_coloring():
                    raise Exception("Can not 3 coloring the induced graph")
                assert self.graph.num_errors == 0

                self.putback_the_last_deleted_edge(True)

                if not self.bicycle_algorithm():
                    xxx = edge.get_endpoints()
                    print("remove: ", xxx)
                    failed_graph_DB.add_graph(self.graph.name,
                                              self.graph.to_json())
                    raise Exception("bicycle_algorithm not work!")

                assert self.graph.num_errors == 0

            round -= 1
示例#2
0
    def test_merge(self, round):
        from four_color.GraphMerger import GraphMerger
        temp = self.graph
        content = self.graph.to_json()
        g1 = MultiGraph.from_json(content)
        g2 = MultiGraph.from_json(content)

        while round > 0:
            (g, elist) = GraphMerger.single_vertex_merge(g1, g2)
            self.graph = g
            self.remove_edge_on_girth()

            if not self.edge_coloring():
                raise Exception("Can not 3 coloring the induced graph")
            assert self.graph.num_errors == 0

            self.putback_the_last_deleted_edge(True)

            if not self.bicycle_algorithm():
                failed_graph_DB.add_graph(self.graph.name,
                                          self.graph.to_json())
                raise Exception("bicycle_algorithm not work!")

            assert self.graph.num_errors == 0

            round -= 1
    def test_merge(self, round):
        from four_color.GraphMerger import GraphMerger
        temp = self.graph
        content = self.graph.to_json()
        g1 = MultiGraph.from_json(content)
        g2 = MultiGraph.from_json(content)
        
        while round > 0:
            (g, elist) = GraphMerger.single_vertex_merge(g1, g2)
            self.graph = g
            self.remove_edge_on_girth()
            
            if not self.edge_coloring():
                raise Exception("Can not 3 coloring the induced graph")
            assert self.graph.num_errors == 0

            self.putback_the_last_deleted_edge(True)

            if not self.bicycle_algorithm():
                failed_graph_DB.add_graph(self.graph.name,self.graph.to_json())
                raise Exception("bicycle_algorithm not work!")
            
            assert self.graph.num_errors == 0
            
            round -= 1
    def test_vertex_edge_merge(self, round):
        from four_color.GraphMerger import GraphMerger
        temp = self.graph
        content = self.graph.to_json()
        g1 = MultiGraph.from_json(content)
        g2 = MultiGraph.from_json(content)
        while round > 0:
            (g, elist) = GraphMerger.single_vertex_and_edge_merge(g1, g2)
            
            self.graph = g


            for eid in elist:
                xx, yy = eid
                edge = self.graph.get_edge_by_endpoints(xx, yy)
                self.remove_specified_edge(edge)

                if not self.edge_coloring():
                    raise Exception("Can not 3 coloring the induced graph")
                assert self.graph.num_errors == 0

                self.putback_the_last_deleted_edge(True)

                if not self.bicycle_algorithm():
                    xxx = edge.get_endpoints()
                    print "remove: ", xxx
                    failed_graph_DB.add_graph(self.graph.name,self.graph.to_json())
                    raise Exception("bicycle_algorithm not work!")
                
                assert self.graph.num_errors == 0
            
            round -= 1
    def test_main(self, round):
        while round > 0:
            if self.edge_coloring_by_perfect_matching():
                cycs = self.find_locking_cycles()
                if len(cycs) == 2:
                    if not self.bicycle_algorithm():
                        failed_graph_DB.add_graph(self.graph.name,self.graph.to_json())
                        raise Exception("bicycle_algorithm not work!")
                    
                    assert self.graph.num_errors == 0

            round -= 1
示例#6
0
    def test_main(self, round):
        while round > 0:
            if self.edge_coloring_by_perfect_matching():
                cycs = self.find_locking_cycles()
                if len(cycs) == 2:
                    if not self.bicycle_algorithm():
                        failed_graph_DB.add_graph(self.graph.name,
                                                  self.graph.to_json())
                        raise Exception("bicycle_algorithm not work!")

                    assert self.graph.num_errors == 0

            round -= 1
    def case_test(self, round):
        while round > 0:
            
            self.remove_edge_on_girth()
            #temp = self.graph.random_pick_a_edge()
            #self.remove_specified_edge(temp)
            
            if not self.edge_coloring():
                raise Exception("Can not 3 coloring the induced graph")
            assert self.graph.num_errors == 0

            self.putback_the_last_deleted_edge(True)

            if not self.bicycle_algorithm():
                failed_graph_DB.add_graph(self.graph.name,self.graph.to_json())
                raise Exception("bicycle_algorithm not work!")
            
            assert self.graph.num_errors == 0
            
            round -= 1
示例#8
0
    def case_test(self, round):
        while round > 0:

            self.remove_edge_on_girth()
            #temp = self.graph.random_pick_a_edge()
            #self.remove_specified_edge(temp)

            if not self.edge_coloring():
                raise Exception("Can not 3 coloring the induced graph")
            assert self.graph.num_errors == 0

            self.putback_the_last_deleted_edge(True)

            if not self.bicycle_algorithm():
                failed_graph_DB.add_graph(self.graph.name,
                                          self.graph.to_json())
                raise Exception("bicycle_algorithm not work!")

            assert self.graph.num_errors == 0

            round -= 1
    def single_vertex_and_edge_merge(cls, g1, g2):
        vertex_1 = g1.random_pick_a_vertex()
        edge_1 = g2.random_pick_a_edge()

        graph = MultiGraph()
        v_count = 1
        v1_map = {}
        v2_map = {}
        
        for u in g1.vertices:
            if u.id == vertex_1.id:
                continue
            v1_map[u.id] = v_count
            graph.add_vertex(v_count)
            v_count += 1

        for u in g2.vertices:
            v2_map[u.id] = v_count
            graph.add_vertex(v_count)
            v_count += 1

        new_vertices = range(v_count, v_count + 5, 1)

        for i in new_vertices:
            graph.add_vertex(i)

        for i in range(0, 5, 1):
            graph.add_edge(new_vertices[i], new_vertices[(i+1) % 5])

        ret1 = list()
        for edge in g1.edges:
            (a, b) = edge.get_endpoints()
            
            if a == vertex_1.id:
                temp = new_vertices.pop()
                ret1.append(temp)
                graph.add_edge(v1_map[b], temp)
            elif b == vertex_1.id:
                temp = new_vertices.pop()
                ret1.append(temp)
                graph.add_edge(v1_map[a], temp)

            else:
                graph.add_edge(v1_map[a], v1_map[b])
        
        for edge in g2.edges:
            if edge.id == edge_1.id:
                continue
            (a, b) = edge.get_endpoints()
            graph.add_edge(v2_map[a], v2_map[b])

        x, y = edge_1.get_endpoints()
        graph.add_edge(new_vertices[0], v2_map[x])
        graph.add_edge(new_vertices[1], v2_map[y])

        #print "ret1: ", ret1
        #print "new vertex: ", new_vertices
        elist = list()
        elist.append((ret1[0], ret1[1]))
        elist.append((ret1[1], ret1[2]))
        elist.append((new_vertices[0], new_vertices[1]))
        
        try:
            graph.validate()
        except:
            failed_graph_DB.add_graph(graph.name, graph.to_json())
            raise
        return (graph, elist)
示例#10
0
 def add_to_db(self):
     failed_graph_DB.add_graph(self.graph.name, self.graph.to_json())
示例#11
0
    def single_vertex_and_edge_merge(cls, g1, g2):
        vertex_1 = g1.random_pick_a_vertex()
        edge_1 = g2.random_pick_a_edge()

        graph = MultiGraph()
        v_count = 1
        v1_map = {}
        v2_map = {}

        for u in g1.vertices:
            if u.id == vertex_1.id:
                continue
            v1_map[u.id] = v_count
            graph.add_vertex(v_count)
            v_count += 1

        for u in g2.vertices:
            v2_map[u.id] = v_count
            graph.add_vertex(v_count)
            v_count += 1

        new_vertices = range(v_count, v_count + 5, 1)

        for i in new_vertices:
            graph.add_vertex(i)

        for i in range(0, 5, 1):
            graph.add_edge(new_vertices[i], new_vertices[(i + 1) % 5])

        ret1 = list()
        for edge in g1.edges:
            (a, b) = edge.get_endpoints()

            if a == vertex_1.id:
                temp = new_vertices.pop()
                ret1.append(temp)
                graph.add_edge(v1_map[b], temp)
            elif b == vertex_1.id:
                temp = new_vertices.pop()
                ret1.append(temp)
                graph.add_edge(v1_map[a], temp)

            else:
                graph.add_edge(v1_map[a], v1_map[b])

        for edge in g2.edges:
            if edge.id == edge_1.id:
                continue
            (a, b) = edge.get_endpoints()
            graph.add_edge(v2_map[a], v2_map[b])

        x, y = edge_1.get_endpoints()
        graph.add_edge(new_vertices[0], v2_map[x])
        graph.add_edge(new_vertices[1], v2_map[y])

        #print "ret1: ", ret1
        #print "new vertex: ", new_vertices
        elist = list()
        elist.append((ret1[0], ret1[1]))
        elist.append((ret1[1], ret1[2]))
        elist.append((new_vertices[0], new_vertices[1]))

        try:
            graph.validate()
        except:
            failed_graph_DB.add_graph(graph.name, graph.to_json())
            raise
        return (graph, elist)
 def add_to_db(self):
     failed_graph_DB.add_graph(self.graph.name,self.graph.to_json())