示例#1
0
def generate_random():
    '''
    generates a randomgraph
    '''
    w = sg.Window('Enter Erdos-Reyni values:').Layout([[
        sg.Text('number of vertices (V) '
                'and probability of spawning edges (p)')
    ], [sg.Text('V'), sg.Input()], [sg.Text('p'), sg.Input()],
                                                       [sg.OK(),
                                                        sg.Cancel()]])

    event, values = w.Read()
    w.Close()
    if event == 'OK':
        print(values)
        v, p = int(values[0]), float(values[1])
        if (v, p):
            bg = lcg.BaseGraph()
            bg.generate_random(v, p)
            app.bg = bg
            update_bg_data(app.bg)
        else:
            raise ValueError

    retdict = {
        'bgcontainer':
        render_template('graphcontainer.html', container_type='bg', **data),
    }
    response = app.response_class(status=200,
                                  response=json.dumps(retdict),
                                  mimetype='application/json')
    return response
示例#2
0
def load_graph_from_file():
    '''
    loads an input graph from a file
    '''
    w = sg.Window('Get filename').Layout([[sg.Text('Filename')],
                                          [sg.Input(),
                                           sg.FileBrowse()],
                                          [sg.OK(), sg.Cancel()]])

    event, values = w.Read()
    w.Close()
    if event == 'OK':
        resp = values[0]
        if resp and Path(resp).exists():
            args.input_file = resp
            bg = lcg.BaseGraph()
            bg.load_txt(args.input_file)
            app.bg = bg
            update_bg_data(app.bg)
        else:
            raise ValueError

    retdict = {
        'bgcontainer':
        render_template('graphcontainer.html', container_type='bg', **data),
    }
    response = app.response_class(status=200,
                                  response=json.dumps(retdict),
                                  mimetype='application/json')
    return response
示例#3
0
 def test_bipartite_polyp(self, g):
     # this test tests whether
     cg = g.build_coloring_graph(self.k)
     rcg_ = make_nx(cg)
     bg = lcg.BaseGraph()
     bg.load_from_nx(rcg_)
     cg_ = bg.build_coloring_graph(2)
     return len(cg) > 0
示例#4
0
    def test_bipartite_polyp(self, g):
        # this test tests whether
        cg = g.build_coloring_graph(self.k)
        mcg = cg.tarjans()

        mship = mcg.identify_mothership()
        for mv in mcg.get_vertices():
            if mv.get_name() != mship and len(mv)/len(cg) >=.85: return None
        rcg = mcg.rebuild_partial_graph()
        rcg_ = make_nx(rcg)
        bg = lcg.BaseGraph()
        bg.load_from_nx(rcg_)
        cg_ = bg.build_coloring_graph(2)
        return len(cg) > 0
示例#5
0
def runflaskgui(url='http://localhost', port='5000', env='development',
                                                     debug=args.debug,
                                                     testing=True):
    '''
    '''
    app.config['ENV'] = env
    app.config['DEBUG'] = debug
    app.config['TESTING'] = testing

    bg = lcg.BaseGraph()
    app.cg = cg = bg.build_coloring_graph(0)
    app.mcg = mcg = cg.tarjans()
    app.cut_verts = cut_verts = [*mcg.get_cut_vertices()]
    app.pcg = pcg = mcg.rebuild_partial_graph()
    app.mother_verts = mother_verts = [*mcg.get_mothership_cut_vertices()]
    
    if args.input_file:
        bg.load_txt(args.input_file)
    app.bg = bg

    if args.render_on_launch:
        app.cg = cg = bg.build_coloring_graph(args.colors)
        app.mcg = mcg = cg.tarjans()
        app.cut_verts = cut_verts = [*mcg.get_cut_vertices()]
        app.pcg = pcg = mcg.rebuild_partial_graph()
        app.mother_verts = mother_verts = [*mcg.get_mothership_cut_vertices()]

    update_bg_data(bg)
    update_mcg_data(mcg)
    update_cg_data(cg)
    update_pcg_data(pcg)

    app.statsdict = statsdict = dict(
        cgsize=len(cg),
        is_connected=cg.is_connected(),
        is_biconnected=cg.is_biconnected(),
    )
    data.update({'stats': ' '.join(['{}: {},'.format(k, v)
                 for k, v in app.statsdict.items()])})

    
    app.run(port=port, threaded=args.threaded)
示例#6
0
def index(request):
    template = loader.get_template('viewtemplate.html')
    
    bg = lcg.BaseGraph()
    path = '/home/aalok/code/coloring-graphs/in/hexmod.in'
    # path = '/home/aalok/code/coloring-graphs/in/bipartite_test_graph0.in'
    bg.load_txt(path)
    #mbg = bg.tarjans()
    
    cg = bg.build_coloring_graph(4)  
    print(type(cg))
    mcg = cg.tarjans()
    
    data = dict()
    data.update(lcg.viz.to_visjs(bg))
    data.update(lcg.viz.to_visjs(cg))
    data.update(lcg.viz.to_visjs(mcg))
    
    if request.method == 'GET':
        response = HttpResponse(template.render(context=data))
        # print(response.content)
        return response
        
    return HttpResponse("ERROR")
示例#7
0
def flaskgui(url='http://localhost', port='5000'):
    '''
    '''
    app.config['ENV'] = 'development'
    app.config['DEBUG'] = True
    app.config['TESTING'] = True

    bg = lcg.BaseGraph()
    if not args.new:
        bg.load_txt(args.input_file)
        #mbg = bg.tarjans()

    cg = bg.build_coloring_graph(args.colors)
    mcg = cg.tarjans()

    pcg = bg

    global data
    data.update(lcg.viz.to_visjs(bg))
    data.update(lcg.viz.to_visjs(cg))
    data.update(lcg.viz.to_visjs(mcg))
    data.update(lcg.viz.to_visjs(pcg))

    app.run(port=port)
示例#8
0
                thiscolors = cg.get_possible_colors([v])
                diff = difference(alpha, thiscolors)
                #print ('this_colors:', thiscolors,
                #        '\ndiff: ', diff)
                if diff in reprs:
                    reprs[diff].update({thiscolors})
                    print(cg.get_possible_colors([v]), diff, sep='\n')
                    flag = False
                reprs[diff].update({thiscolors})
            if not flag:
                for k in reprs:
                    print(k)
                    for val in reprs[k]:
                        print('\t', val)
                return False
        return True


if __name__ == '__main__':
    hyp = HypercubeHypothesis()
    directories = ['../bigpolyp', '../discovered']
    for prefix in directories:
        graphs = []
        for graph in tqdm(glob(prefix + '/*/*k={}*.txt'.format(hyp.k))):
            graph = Path(graph)
            bg = lcg.BaseGraph()
            bg.path = str(graph)
            bg.load_txt(bg.path)
            graphs += [bg]
        hyp.find_counterexample(graphs)