コード例 #1
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
コード例 #2
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
コード例 #3
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
コード例 #4
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
コード例 #5
0
    def setUp(self):
        from common.multigraph import MultiGraph
        import json

        data = {
            'edges': [
                {'v1': 1, 'v2': 2, 'c1': 1, 'c2': 1},
                {'v1': 1, 'v2': 3, 'c1': 1, 'c2': 1},
                {'v1': 1, 'v2': 6, 'c1': 1, 'c2': 1},
                {'v1': 2, 'v2': 3, 'c1': 1, 'c2': 1},
                {'v1': 2, 'v2': 6, 'c1': 1, 'c2': 1},
                {'v1': 3, 'v2': 4, 'c1': 1, 'c2': 1},
                {'v1': 4, 'v2': 5, 'c1': 1, 'c2': 1},
                {'v1': 5, 'v2': 1, 'c1': 1, 'c2': 1},
                {'v1': 5, 'v2': 2, 'c1': 1, 'c2': 1},
            ],
            'vertices': [
                {'x': 0, 'y': 0, 'name': 1},
                {'x': 0, 'y': 0, 'name': 2},
                {'x': 0, 'y': 0, 'name': 3},
                {'x': 0, 'y': 0, 'name': 4},
                {'x': 0, 'y': 0, 'name': 5},
                {'x': 0, 'y': 0, 'name': 6},
            ],
        }
        graph = MultiGraph.from_json(json.dumps(data))
        self.inspector = InspectorEngine(graph)
コード例 #6
0
    def setUp(self):
        from common.multigraph import MultiGraph
        import json

        data = {
            'edges': [
                {'v1': 1, 'v2': 2, 'c1': 1, 'c2': 1},
                {'v1': 1, 'v2': 3, 'c1': 1, 'c2': 1},
                {'v1': 1, 'v2': 6, 'c1': 1, 'c2': 1},
                {'v1': 2, 'v2': 3, 'c1': 1, 'c2': 1},
                {'v1': 2, 'v2': 6, 'c1': 1, 'c2': 1},
                {'v1': 3, 'v2': 4, 'c1': 1, 'c2': 1},
                {'v1': 4, 'v2': 5, 'c1': 1, 'c2': 1},
                {'v1': 5, 'v2': 1, 'c1': 1, 'c2': 1},
                {'v1': 5, 'v2': 2, 'c1': 1, 'c2': 1},
            ],
            'vertices': [
                {'x': 0, 'y': 0, 'name': 1},
                {'x': 0, 'y': 0, 'name': 2},
                {'x': 0, 'y': 0, 'name': 3},
                {'x': 0, 'y': 0, 'name': 4},
                {'x': 0, 'y': 0, 'name': 5},
                {'x': 0, 'y': 0, 'name': 6},
            ],
        }
        graph = MultiGraph.from_json(json.dumps(data))
        self.inspector = InspectorEngine(graph)
コード例 #7
0
 def get_graph(self, g_id):
     with closing(self.db.cursor()) as c:
         c.execute('''SELECT * FROM graphs WHERE `id`=?''', (g_id, ))
         row = c.fetchone()
         json_data = row[2]
         g = MultiGraph.from_json(json_data)
         g.name = row[1]
         return g
コード例 #8
0
 def get_graph(self, g_id):
     with closing(self.db.cursor()) as c:
         c.execute('''SELECT * FROM graphs WHERE `id`=?''', (g_id, ))
         row = c.fetchone()
         json_data = row[2]
         g = MultiGraph.from_json(json_data)
         g.name = row[1]
         return g
コード例 #9
0
def read_graph_from_txt(path, graph_name):
    # read a graph from a txt file. The 1st line is vertex #, the 2rd is the list of edges
    fin = open(path, 'r')
    import ast
    a = fin.readlines()
    number_of_vertices = int(a[0])
    raw_edges = ast.literal_eval(a[1])
    vertices = []
    edges = []
    for index in range(1, number_of_vertices + 1):
        vertices.append({"x": 0, "y": 0, "name": index})
    for each in raw_edges:
        edges.append({"v1": each[0], "v2": each[1], "c1": -1, "c2": -1})
    content = {"vertices": vertices, "edges": edges}
    g = MultiGraph.from_json(json.dumps(content))
    g.name = graph_name
    return g
コード例 #10
0
def read_graph_from_txt(path, graph_name):
# read a graph from a txt file. The 1st line is vertex #, the 2rd is the list of edges
    fin = open(path,'r')
    import ast
    a = fin.readlines()
    number_of_vertices = int(a[0])
    raw_edges = ast.literal_eval(a[1])
    vertices = []
    edges = []
    for index in range(1,number_of_vertices+1):
        vertices.append({"x":0,"y":0,"name":index})
    for each in raw_edges:
        edges.append({"v1":each[0],"v2":each[1],"c1":-1,"c2":-1})
    content = {"vertices":vertices,"edges":edges}
    g = MultiGraph.from_json(json.dumps(content))
    g.name = graph_name
    return g
コード例 #11
0
 def create_graph(self, name, data):
     graph = MultiGraph.from_json(data)
     graph.name = name
     self.store.add_graph(graph)
コード例 #12
0
 def save(self, string):
     if hasattr(self._graph, 'g_id'):
         graph = MultiGraph.from_json(string)
         graph.name = self._graph.name
         self.store.save_graph(self._graph.g_id, graph)
コード例 #13
0
    g.name = graph_name
    return g


gl = [24]

for n in gl:
    fin = open("C:/Users/temp-admin/Desktop/ove/data/snarks_graph6/snark{}_cyc4.g6".format(n), "r")
    stri = fin.readline()
    num = 0
    while stri != "":
        num = num + 1
        print "New Graph: ", num
        vertices, edges = readGraph(list(stri))
        content = {"vertices": vertices, "edges": edges}
        g = MultiGraph.from_json(json.dumps(content))
        graph_name = "snark{}_cyc4_{}".format(n, num)
        engine = InductionEngine(g)
        engine.edge_coloring()
        engine.layout()
        engine.bicycle_layout()
        snark_graph_DB.add_graph(graph_name, g.to_json())

        checked = []
        while True:
            edge = None
            for e in engine.graph.edges:
                (a, b) = e.get_endpoints()
                if ((a, b) not in checked) and ((b, a) not in checked):
                    edge = e
                    break
コード例 #14
0
 def create_graph(self, name, data):
     graph = MultiGraph.from_json(data)
     graph.name = name
     self.store.add_graph(graph)
コード例 #15
0
 def save(self, string):
     if hasattr(self._graph, 'g_id'):
         graph = MultiGraph.from_json(string)
         graph.name = self._graph.name
         self.store.save_graph(self._graph.g_id, graph)
コード例 #16
0

gl = [18]

for n in gl:
    fin = open(
        'C:/Users/temp-admin/Desktop/ove/data/snarks_graph6/snark{}_cyc4.g6'.
        format(n), 'r')
    stri = fin.readline()
    num = 0
    while stri != "":
        num = num + 1
        print "New Graph: ", num
        vertices, edges = readGraph(list(stri))
        content = {"vertices": vertices, "edges": edges}
        g = MultiGraph.from_json(json.dumps(content))
        graph_name = "snark{}_cyc4_{}".format(n, num)
        engine = InductionEngine(g)
        engine.edge_coloring()

        i = 0
        found = False
        for i in range(0, 10, 1):
            if engine.bicycle_layout():
                found = True
                break
            engine.edge_coloring()
        print "found bicycle"
        engine.find_petersen_subdivision()

        stri = fin.readline()
コード例 #17
0
def current_graph():
    #content = '{"edges": [{"v1": 2, "v2": 3, "c1": 2, "c2": 2}, {"v1": 3, "v2": 4, "c1": 1, "c2": 1}, {"v1": 4, "v2": 5, "c1": 0, "c2": 0}, {"v1": 5, "v2": 6, "c1": 2, "c2": 2}, {"v1": 6, "v2": 7, "c1": 1, "c2": 1}, {"v1": 2, "v2": 8, "c1": 0, "c2": 0}, {"v1": 8, "v2": 9, "c1": 2, "c2": 2}, {"v1": 10, "v2": 7, "c1": 2, "c2": 2}, {"v1": 10, "v2": 9, "c1": 1, "c2": 1}, {"v1": 1, "v2": 11, "c1": 2, "c2": 2}, {"v1": 1, "v2": 12, "c1": 0, "c2": 0}, {"v1": 1, "v2": 13, "c1": 1, "c2": 1}, {"v1": 11, "v2": 14, "c1": 0, "c2": 0}, {"v1": 11, "v2": 15, "c1": 1, "c2": 1}, {"v1": 14, "v2": 16, "c1": 1, "c2": 1}, {"v1": 15, "v2": 16, "c1": 2, "c2": 2}, {"v1": 16, "v2": 17, "c1": 0, "c2": 0}, {"v1": 17, "v2": 18, "c1": 2, "c2": 2}, {"v1": 15, "v2": 19, "c1": 0, "c2": 0}, {"v1": 18, "v2": 19, "c1": 1, "c2": 1}, {"v1": 2, "v2": 20, "c1": 1, "c2": 1}, {"v1": 17, "v2": 21, "c1": 1, "c2": 1}, {"v1": 22, "v2": 8, "c1": 1, "c2": 1}, {"v1": 14, "v2": 22, "c1": 2, "c2": 2}, {"v1": 21, "v2": 22, "c1": 0, "c2": 0}, {"v1": 23, "v2": 9, "c1": 0, "c2": 0}, {"v1": 21, "v2": 23, "c1": 2, "c2": 2}, {"v1": 18, "v2": 24, "c1": 0, "c2": 0}, {"v1": 23, "v2": 24, "c1": 1, "c2": 1}, {"v1": 10, "v2": 25, "c1": 0, "c2": 0}, {"v1": 19, "v2": 25, "c1": 2, "c2": 2}, {"v1": 24, "v2": 25, "c1": 2, "c2": 1}, {"v1": 20, "v2": 26, "c1": 2, "c2": 2}, {"v1": 12, "v2": 27, "c1": 2, "c2": 2}, {"v1": 26, "v2": 27, "c1": 1, "c2": 1}, {"v1": 28, "v2": 4, "c1": 2, "c2": 2}, {"v1": 12, "v2": 29, "c1": 1, "c2": 1}, {"v1": 28, "v2": 29, "c1": 0, "c2": 0}, {"v1": 30, "v2": 7, "c1": 0, "c2": 0}, {"v1": 13, "v2": 31, "c1": 0, "c2": 0}, {"v1": 30, "v2": 31, "c1": 2, "c2": 2}, {"v1": 13, "v2": 32, "c1": 2, "c2": 2}, {"v1": 32, "v2": 33, "c1": 1, "c2": 1}, {"v1": 34, "v2": 5, "c1": 1, "c2": 1}, {"v1": 33, "v2": 34, "c1": 2, "c2": 2}, {"v1": 27, "v2": 35, "c1": 0, "c2": 0}, {"v1": 29, "v2": 35, "c1": 2, "c2": 2}, {"v1": 31, "v2": 36, "c1": 1, "c2": 1}, {"v1": 32, "v2": 36, "c1": 0, "c2": 0}, {"v1": 35, "v2": 37, "c1": 1, "c2": 1}, {"v1": 36, "v2": 38, "c1": 2, "c2": 2}, {"v1": 26, "v2": 39, "c1": 0, "c2": 0}, {"v1": 37, "v2": 39, "c1": 2, "c2": 1}, {"v1": 28, "v2": 40, "c1": 1, "c2": 1}, {"v1": 37, "v2": 40, "c1": 0, "c2": 0}, {"v1": 20, "v2": 41, "c1": 0, "c2": 0}, {"v1": 39, "v2": 41, "c1": 2, "c2": 2}, {"v1": 3, "v2": 42, "c1": 0, "c2": 0}, {"v1": 40, "v2": 42, "c1": 2, "c2": 2}, {"v1": 41, "v2": 42, "c1": 1, "c2": 1}, {"v1": 33, "v2": 43, "c1": 0, "c2": 0}, {"v1": 38, "v2": 43, "c1": 1, "c2": 1}, {"v1": 34, "v2": 44, "c1": 0, "c2": 0}, {"v1": 43, "v2": 44, "c1": 2, "c2": 2}, {"v1": 30, "v2": 45, "c1": 1, "c2": 1}, {"v1": 38, "v2": 45, "c1": 0, "c2": 0}, {"v1": 46, "v2": 6, "c1": 0, "c2": 0}, {"v1": 44, "v2": 46, "c1": 1, "c2": 1}, {"v1": 45, "v2": 46, "c1": 2, "c2": 2}], "vertices": [{"y": 359, "x": 118, "name": "42"}, {"y": 586, "x": 484, "name": "43"}, {"y": 123, "x": 530, "name": "24"}, {"y": 198, "x": 524, "name": "25"}, {"y": 230, "x": 77, "name": "26"}, {"y": 287, "x": 143, "name": "27"}, {"y": 209, "x": 133, "name": "20"}, {"y": 65, "x": 373, "name": "21"}, {"y": 102, "x": 285, "name": "22"}, {"y": 130, "x": 437, "name": "23"}, {"y": 507, "x": 444, "name": "46"}, {"y": 587, "x": 411, "name": "44"}, {"y": 485, "x": 522, "name": "45"}, {"y": 455, "x": 166, "name": "28"}, {"y": 384, "x": 174, "name": "29"}, {"y": 433, "x": 88, "name": "40"}, {"y": 279, "x": 72, "name": "41"}, {"y": 295, "x": 333, "name": "1"}, {"y": 341, "x": 206, "name": "3"}, {"y": 238, "x": 214, "name": "2"}, {"y": 473, "x": 311, "name": "5"}, {"y": 435, "x": 238, "name": "4"}, {"y": 350, "x": 457, "name": "7"}, {"y": 432, "x": 392, "name": "6"}, {"y": 207, "x": 388, "name": "9"}, {"y": 187, "x": 285, "name": "8"}, {"y": 292, "x": 12, "name": "39"}, {"y": 534, "x": 554, "name": "38"}, {"y": 197, "x": 353, "name": "11"}, {"y": 259, "x": 463, "name": "10"}, {"y": 362, "x": 406, "name": "13"}, {"y": 313, "x": 237, "name": "12"}, {"y": 123, "x": 409, "name": "15"}, {"y": 109, "x": 328, "name": "14"}, {"y": 12, "x": 434, "name": "17"}, {"y": 34, "x": 374, "name": "16"}, {"y": 126, "x": 495, "name": "19"}, {"y": 50, "x": 510, "name": "18"}, {"y": 367, "x": 510, "name": "31"}, {"y": 401, "x": 524, "name": "30"}, {"y": 381, "x": 25, "name": "37"}, {"y": 453, "x": 548, "name": "36"}, {"y": 1, "x": 1, "name": "35"}, {"y": 1, "x": 1, "name": "34"}, {"y": 1, "x": 1, "name": "33"}, {"y": 448, "x": 447, "name": "32"}]}'
    content = '{"edges": [{"v1": 1, "v2": 3, "c1": 2, "c2": 2}, {"v1": 3, "v2": 5, "c1": 1, "c2": 1}, {"v1": 2, "v2": 5, "c1": 2, "c2": 2}, {"v1": 2, "v2": 4, "c1": 3, "c2": 3}, {"v1": 1, "v2": 4, "c1": 1, "c2": 1}, {"v1": 1, "v2": 6, "c1": 3, "c2": 1}, {"v1": 2, "v2": 7, "c1": 1, "c2": 1}, {"v1": 3, "v2": 8, "c1": 3, "c2": 3}, {"v1": 4, "v2": 9, "c1": 2, "c2": 2}, {"v1": 5, "v2": 10, "c1": 3, "c2": 1}, {"v1": 6, "v2": 7, "c1": 3, "c2": 3}, {"v1": 7, "v2": 8, "c1": 2, "c2": 2}, {"v1": 8, "v2": 9, "c1": 1, "c2": 1}, {"v1": 9, "v2": 10, "c1": 3, "c2": 3}, {"v1": 6, "v2": 10, "c1": 2, "c2": 2}], "vertices": [{"y": 440, "x": 24, "name": 1}, {"y": 506, "x": 496, "name": 2}, {"y": 201, "x": 201, "name": 3}, {"y": 554, "x": 194, "name": 4}, {"y": 173, "x": 478, "name": 5}, {"y": 298, "x": 575, "name": 7}, {"y": 34, "x": 371, "name": 8}, {"y": 193, "x": 47, "name": 9}, {"y": 358, "x": 285, "name": 6}, {"y": 26, "x": 207, "name": 10}]}'
    g = MultiGraph.from_json(content)
    #g.layout()
    return g.to_json(), 200, {'Content-Type': 'application/json'}