Example #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
Example #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
    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
Example #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)
    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)
 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
Example #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
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
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
    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
Example #12
0
    def single_vertex_merge(cls, g1, g2):
        vertices_num1 = g1.num_vertices
        vertices_num2 = g2.num_vertices

        vertex_1 = g1.random_pick_a_vertex()
        vertex_2 = g2.random_pick_a_vertex()

        neighbor_vertices1 = []
        for v in vertex_1.neighbor_vertices:
            neighbor_vertices1.append(v)

        neighbor_vertices2 = []
        for v in vertex_2.neighbor_vertices:
            neighbor_vertices2.append(v)

        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:
            if u.id == vertex_2.id:
                continue
            v2_map[u.id] = v_count
            graph.add_vertex(v_count)
            v_count += 1

        for edge in g1.edges:
            (a, b) = edge.get_endpoints()
            if a == vertex_1.id or b == vertex_1.id:
                continue
            graph.add_edge(v1_map[a], v1_map[b])

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

        x1, y1, z1 = neighbor_vertices1[0], neighbor_vertices1[
            1], neighbor_vertices1[2]
        x2, y2, z2 = neighbor_vertices2[0], neighbor_vertices2[
            1], neighbor_vertices2[2]
        e_id1 = graph.add_edge(v1_map[x1], v2_map[x2])
        e_id2 = graph.add_edge(v1_map[y1], v2_map[y2])
        e_id3 = graph.add_edge(v1_map[z1], v2_map[z2])

        return (graph, [e_id1, e_id2, e_id3])
Example #13
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)
Example #14
0
 def create_graph(self, name, data):
     graph = MultiGraph.from_json(data)
     graph.name = name
     self.store.add_graph(graph)
    def single_vertex_merge(cls, g1, g2):
        vertices_num1 = g1.num_vertices
        vertices_num2 = g2.num_vertices

        vertex_1 = g1.random_pick_a_vertex()
        vertex_2 = g2.random_pick_a_vertex()

        neighbor_vertices1 = []
        for v in vertex_1.neighbor_vertices:
            neighbor_vertices1.append(v)

        neighbor_vertices2 = []
        for v in vertex_2.neighbor_vertices:
            neighbor_vertices2.append(v)

        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:
            if u.id == vertex_2.id:
                continue
            v2_map[u.id] = v_count
            graph.add_vertex(v_count)
            v_count += 1
        
        for edge in g1.edges:
            (a, b) = edge.get_endpoints()
            if a == vertex_1.id or b == vertex_1.id:
                continue
            graph.add_edge(v1_map[a], v1_map[b])
        
        for edge in g2.edges:
            (a, b) = edge.get_endpoints()
            if a == vertex_2.id or b == vertex_2.id:
                continue
            graph.add_edge(v2_map[a], v2_map[b])
        
        x1, y1, z1 = neighbor_vertices1[0], neighbor_vertices1[1], neighbor_vertices1[2]
        x2, y2, z2 = neighbor_vertices2[0], neighbor_vertices2[1], neighbor_vertices2[2]
        e_id1 = graph.add_edge(v1_map[x1], v2_map[x2])
        e_id2 = graph.add_edge(v1_map[y1], v2_map[y2])
        e_id3 = graph.add_edge(v1_map[z1], v2_map[z2])

        return (graph, [e_id1, e_id2, e_id3])
Example #16
0
from common.storage import failed_graph_DB
from common.storage import snark_graph_DB
from settings import count_utility

import logging
import random
import json
import sys

import settings

random.seed(0)

logging.basicConfig(level=logging.DEBUG)

graph1 = MultiGraph()

for i in range(1, 31, 1):
    graph1.add_vertex(i)
    graph1._positions[i] = (0, 0)

##########
for i in range(1, 15, 1):
    e_id = graph1.add_edge(i, i + 1)
    edge = graph1.get_edge(e_id)
    edge.color = i % 2 + 1

e_id = graph1.add_edge(1, 15)
edge = graph1.get_edge(e_id)
graph1.set_color(e_id, 1, 1)
graph1.set_color(e_id, 15, 2)
    def merge(cls, g1, g2):
        inspector1 = InductionEngine(g1)
        inspector2 = InductionEngine(g2)
        (face1, cycle1) = inspector1.find_girth()
        (face2, cycle2) = inspector2.find_girth()
        if len(face1) != len(face2):
            print "two face not of same kind"
            return None
        
        graph = MultiGraph()
        v_count = 1
        v1_map = {}
        v2_map = {}
        for u in g1.vertices:
            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
        
        for edge in g1.edges:
            (a, b) = edge.get_endpoints()
            if a in cycle1 and b in cycle1:
                continue
            graph.add_edge(v1_map[a], v1_map[b])
        
        for edge in g2.edges:
            (a, b) = edge.get_endpoints()
            if a in cycle2 and b in cycle2:
                continue
            graph.add_edge(v2_map[a], v2_map[b])
        
        k = min(len(cycle1), len(cycle2))
        cycle1.append(cycle1[0])
        cycle2.append(cycle2[0])
        for i in xrange(k):
            x, y = tuple(map(v1_map.get, cycle1[i:i + 2]))
            u, v = tuple(map(v2_map.get, cycle2[i:i + 2]))
            p = v_count
            q = v_count + 1
            v_count += 2
            graph.add_vertex(p)
            graph.add_vertex(q)
            graph.add_edge(x, p)
            graph.add_edge(p, y)
            graph.add_edge(p, q)
            graph.add_edge(u, q)
            graph.add_edge(q, v)

        for i in xrange(k, len(cycle1) - 1):
            x, y = tuple(map(v1_map.get, cycle1[i:i + 2]))
            if graph.multiplicity(x, y) == 0:
                graph.add_edge(x, y)

        for i in xrange(k, len(cycle2) - 1):
            x, y = tuple(map(v2_map.get, cycle2[i:i + 2]))
            if graph.multiplicity(x, y) == 0:
                graph.add_edge(x, y)
        return graph
    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)
Example #19
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'}

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()
Example #21
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 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)
Example #23
0
    def merge(cls, g1, g2):
        inspector1 = InductionEngine(g1)
        inspector2 = InductionEngine(g2)
        (face1, cycle1) = inspector1.find_girth()
        (face2, cycle2) = inspector2.find_girth()
        if len(face1) != len(face2):
            print "two face not of same kind"
            return None

        graph = MultiGraph()
        v_count = 1
        v1_map = {}
        v2_map = {}
        for u in g1.vertices:
            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

        for edge in g1.edges:
            (a, b) = edge.get_endpoints()
            if a in cycle1 and b in cycle1:
                continue
            graph.add_edge(v1_map[a], v1_map[b])

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

        k = min(len(cycle1), len(cycle2))
        cycle1.append(cycle1[0])
        cycle2.append(cycle2[0])
        for i in xrange(k):
            x, y = tuple(map(v1_map.get, cycle1[i:i + 2]))
            u, v = tuple(map(v2_map.get, cycle2[i:i + 2]))
            p = v_count
            q = v_count + 1
            v_count += 2
            graph.add_vertex(p)
            graph.add_vertex(q)
            graph.add_edge(x, p)
            graph.add_edge(p, y)
            graph.add_edge(p, q)
            graph.add_edge(u, q)
            graph.add_edge(q, v)

        for i in xrange(k, len(cycle1) - 1):
            x, y = tuple(map(v1_map.get, cycle1[i:i + 2]))
            if graph.multiplicity(x, y) == 0:
                graph.add_edge(x, y)

        for i in xrange(k, len(cycle2) - 1):
            x, y = tuple(map(v2_map.get, cycle2[i:i + 2]))
            if graph.multiplicity(x, y) == 0:
                graph.add_edge(x, y)
        return graph
 def create_graph(self, name, data):
     graph = MultiGraph.from_json(data)
     graph.name = name
     self.store.add_graph(graph)
from common.storage import snark_graph_DB
from settings import count_utility

import logging
import random
import json
import sys

import settings

random.seed(0)

logging.basicConfig(level=logging.DEBUG)


graph1 = MultiGraph()

for i in range(1, 31, 1):
	graph1.add_vertex(i)
	graph1._positions[i] = (0, 0)

##########
for i in range(1, 15, 1):
	e_id = graph1.add_edge(i, i + 1)
	edge = graph1.get_edge(e_id)
	edge.color = i % 2 + 1

e_id = graph1.add_edge(1, 15)
edge = graph1.get_edge(e_id)
graph1.set_color(e_id, 1, 1)
graph1.set_color(e_id, 15, 2)