Пример #1
0
class OJSAPI(QtCore.QObject):
    '''
        this class is the "oegarn" in the show.html
    '''
    def __init__(self):
        QtCore.QObject.__init__(self)
        self.store = SQLiteGraphStore(settings.VIEW_THIS_DB)
        #self.store = SQLiteGraphStore(settings.DB_FILE)

    def attach(self, parent):
        self.setParent(parent)
        self.app = parent
        self.app.page.mainFrame().javaScriptWindowObjectCleared.connect(
            self.add_to_window)

    @QtCore.Slot()
    def add_to_window(self):
        # add OJSAPI to the GUI
        self.app.page.mainFrame().addToJavaScriptWindowObject('oegarn', self)

    @QtCore.Slot()
    def quit(self):
        #self.app.qt_gui.quit()
        #QtCore.QCoreApplication.instance().quit()
        pass

    update_graph_list = QtCore.Signal(str)  # Signal for update the graph list

    @QtCore.Slot()
    def list_graphs(self):
        graphs = self.store.list_graphs()
        self.update_graph_list.emit(json.dumps(graphs))

    @QtCore.Slot(str)
    def load_graph(self, id):
        graph = self.store.get_graph(id)
        self._graph = graph
        self._graph.g_id = id
        self._induction = InductionEngine(self._graph)
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot(str, str)
    def create_graph(self, name, data):
        graph = MultiGraph.from_json(data)
        graph.name = name
        self.store.add_graph(graph)

    update_current_graph = QtCore.Signal(
        str)  # Signal for update the current graph
    highlight = QtCore.Signal(str)

    @QtCore.Slot()
    def layout(self):
        self._induction.layout()
        #logger.info('layout engine !!!')
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def random_color(self):
        self._graph.random_color()
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def color(self):
        if not self._induction.edge_coloring():
            print("no success")
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def edge_coloring_by_perfect_matching(self):
        self._induction.edge_coloring_by_perfect_matching()
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def cut_edges(self):
        re = self._induction.cut_edges()
        print("cut edges:", re)

    @QtCore.Slot()
    def perfect_matching(self):
        if self._induction.perfect_matching():
            print("yes")
        else:
            print("no")
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def exhaustive_matching(self):
        self._induction.try_to_find()

    @QtCore.Slot()
    def find_pentagon(self):
        data = self._induction.highlight_pentagon()
        self.highlight.emit(json.dumps(data))

    @QtCore.Slot()
    def highlight_blocking(self):
        data = self._induction.highlight_two_locking_cycles()
        self.highlight.emit(json.dumps(data))

    @QtCore.Slot()
    def highlight_ac_exclusive_chain(self):
        data = self._induction.highlight_ac_exclusive_chain()
        self.highlight.emit(json.dumps(data))

    @QtCore.Slot()
    def highlight_bc_exclusive_chain(self):
        data = self._induction.highlight_bc_exclusive_chain()
        self.highlight.emit(json.dumps(data))

    @QtCore.Slot()
    def highlight_ab_cycles(self):
        data = self._induction.highlight_ab_cycles()
        self.highlight.emit(json.dumps(data))

    @QtCore.Slot()
    def highlight_ac_cycles(self):
        data = self._induction.highlight_ac_cycles()
        self.highlight.emit(json.dumps(data))

    @QtCore.Slot()
    def highlight_bc_cycles(self):
        data = self._induction.highlight_bc_cycles()
        self.highlight.emit(json.dumps(data))

    @QtCore.Slot()
    def highlight_petersen_subdivision(self):
        data = self._induction.find_petersen_subdivision()
        if data != False:
            self.highlight.emit(json.dumps(data))

    @QtCore.Slot()
    def invert_highlighted(self):
        data = self._induction.invert_highlighted()
        if data['edges'] == [] and data['vertices'] == []:
            return
        self.update_current_graph.emit(self._graph.to_json())
        self.highlight.emit(json.dumps(data))

    @QtCore.Slot()
    def move_left(self):
        self._induction.move_left()
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def move_right(self):
        self._induction.move_right()
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def count_resolve(self):
        self._induction.count_resolve_with_even_ab()

    @QtCore.Slot()
    def check_resolvable(self):
        if self._induction.check_resolvable():
            print("yes")
        else:
            print("no")

    @QtCore.Slot()
    def smooth(self):
        self._induction.smooth()
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot(str)
    def remove_one_edge(self, info):
        data = ast.literal_eval(info)
        if type(data) != tuple and len(data) != 2:
            print("error input")
            return
        a, b = data
        edge = self._induction.graph.get_edge_by_endpoints(a, b)
        if edge is None:
            print("not such edge")
            return
        self._induction.remove_specified_edge(edge)
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def delete_even_ab_cycles(self):
        self._induction.delete_even_ab_cycles()
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def put_back(self):
        self._induction.putback_the_last_deleted_edge(True)
        print("put back edge")
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def clear_colors(self):
        self._induction.clear_colors()
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot()
    def bicycle_format(self):
        self._induction.bicycle_layout()
        self.update_current_graph.emit(self._graph.to_json())

    @QtCore.Slot(str)
    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)

    @QtCore.Slot(str)
    def print_svg(self, svg_source):
        #logger.info(svg_source)
        svg_renderer = QtSvg.QSvgRenderer()
        svg_renderer.load(QtCore.QByteArray(svg_source))
        logger.info('svg renderer')
        printer = QtGui.QPrinter()
        printer.setPageMargins(50, 250, 50, 250, QtGui.QPrinter.DevicePixel)
        print_dialog = QtGui.QPrintDialog(printer, self.app.view)
        print_dialog.setOption(QtGui.QAbstractPrintDialog.PrintToFile, True)
        print_dialog.setOption(QtGui.QAbstractPrintDialog.PrintPageRange, True)
        if print_dialog.exec_() == QtGui.QDialog.Accepted:
            painter = QtGui.QPainter()
            painter.begin(printer)
            svg_renderer.render(painter)
            painter.end()
Пример #2
0
 def load_graph(self, id):
     graph = self.store.get_graph(id)
     self._graph = graph
     self._graph.g_id = id
     self._induction = InductionEngine(self._graph)
     self.update_current_graph.emit(self._graph.to_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()
Пример #4
0
graph1.set_color(e_id, 30, 1)

##############################
elist = []

elist.append(graph1.add_edge(2, 17))
elist.append(graph1.add_edge(5, 20))
elist.append(graph1.add_edge(8, 23))
elist.append(graph1.add_edge(1, 15))
elist.append(graph1.add_edge(3, 14))
elist.append(graph1.add_edge(4, 13))
elist.append(graph1.add_edge(6, 12))
elist.append(graph1.add_edge(7, 11))
elist.append(graph1.add_edge(9, 10))
elist.append(graph1.add_edge(16, 30))
elist.append(graph1.add_edge(18, 29))
elist.append(graph1.add_edge(19, 28))
elist.append(graph1.add_edge(21, 27))
elist.append(graph1.add_edge(22, 26))
elist.append(graph1.add_edge(24, 25))

for x in elist:
    graph1.get_edge(x).color = 3

#failed_graph_DB.add_graph("graph1",graph1.to_json())
engine = InductionEngine(graph1)
if engine.bicycle_algorithm() == False:
    print("haha not resolved")
else:
    print("resolved")
Пример #5
0
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
            if edge == None:
                break
Пример #6
0
        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


gl = [24, 26, 28]

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)
        found = False
        for i in range(0, 40, 1):
            engine.edge_coloring()
            if engine.graph.num_errors == 2:
                found = True
                break
        if found == False:
            snark_graph_DB_2.add_graph(graph_name, g.to_json())
        stri = fin.readline()
Пример #7
0
    #if num < last + tt:
    #        continue
    #last = num
    #tt = random.randint(20, 100)
    print("New Graph: ", num)
    vertices, edges = readGraph(list(stri))
    content = {"vertices": vertices, "edges": edges}
    #print json.dumps(content,indent=4)
    #g = MultiGraph.from_json(json.dumps(content))
    g1 = MultiGraph.from_json(json.dumps(content))
    #g2 = MultiGraph.from_json(json.dumps(content))
    #g3 = MultiGraph.from_json(json.dumps(content))
    #(g12, temp) = GraphMerger.single_vertex_merge(g1, g2)
    #(g123, temp) = GraphMerger.single_vertex_merge(g12, g3)
    #graph_name = "snark{}_cyc4_{}".format(n, num)
    engine = InductionEngine(g1)
    engine.add_to_DB()
    #engine.check_critical()
    #stats[num] = engine.stat_test(rnd)
    #engine.test_vertex_edge_merge(5000)
    stri = fin.readline()
'''a, b, c = 0, 0, 0
for temp in stats:
        
        rate, tt = stats[temp]
        if tt != "NA":
                c += 1
                a += rate
                b += tt
print float(a/c), float(b / c)
results.write(repr(stats))
Пример #8
0
        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


gl = [10]

for n in gl:
    fin = open(
        'D:/Google Drive/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_by_perfect_matching()

        x = engine.exhaustive_matching()
        print x
        #failed_graph_DB.add_graph(graph_name, g.to_json())
Пример #9
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