示例#1
0
def run_graph(graph_file, output_file, neighborhood, flag = None):
    print "==== New graph ===="
    print "Input:", graph_file
    print "Output:", output_file
    print "Neighborhood:", neighborhood
    print ""

    print "Loading graph"
    print "Start time: %s" % (datetime.now())
    g=nx.read_gml(graph_file)
    print "End time: %s" % (datetime.now())

    gflag = None
    if flag == None:
        print "Creating flag complex"
        print "Start time: %s" % (datetime.now())
        gedgelist = map(list,g.edges(data=False))
        gflag = sh.flag(gedgelist,4)
        print "End time: %s" % (datetime.now())
    else:
        print "Using passed in flag complex"
        gflag = flag

    for n in range(neighborhood+1):
        print "Finding the local homology (n = %d)" % (n)
        print "Start time: %s" % (datetime.now())
        graph = graph_file.split("/")[-1]
        print output_file
        ofile = open(output_file, 'w')
        ofile.write("Local Homology (neighborhood=%d) of flag complex generated by %s\n" % (n, graph))
        locHomTable(gflag, {}, n, ofile)
        print "End time: %s" % (datetime.now())
        print "\n"

    return gflag
示例#2
0
    "VT" : [2630,185],
    "ME" : [3010,40],
    "ND" : [935,225]
}

graph_file = "usa.txt"

# ALL OF THESE ARE FOR N0 NEIGHBORHOODS
g = nx.read_edgelist(graph_file, nodetype=int)
gflag = None
gedgelist = map(list,g.edges(data=False))

startTime = tm.time()

print "finding flag complex"
cplx = sh.flag(gedgelist,3)
print "getting simplices"
cplx_grph=sh.ksimplices(cplx,0)+sh.ksimplices(cplx,1)+sh.ksimplices(cplx,2)+sh.ksimplices(cplx,3)
print "creating colors1"
colors_grph_1=[sh.localHomology(1,cplx,[spx],True) for spx in cplx_grph]
print "creating colors2"
colors_grph_2=[sh.localHomology(2,cplx,[spx],True) for spx in cplx_grph]
print "creating colors3"
colors_grph_3=[sh.localHomology(3,cplx,[spx],True) for spx in cplx_grph]

endTime = tm.time()
print "\n**** Total time = %f s ****\n" % (endTime-startTime)

print "creating locations array"
locations = [[coords[states[i]][0], -coords[states[i]][1]] for i in range(1,50)]
locations = [[0,0]] + locations
示例#3
0
        name = ""
        if ascdict != {}:
            for idx in range(len(A[0])):
                name += ascdict[A[0][idx]]

        if name == "":
            name = ','.join(map(str,splx))

        if outfile == None:
            print  k, "\t\t", H1 , "\t" , H2, "\t", H3, "\t\t", name
            k += 1
        else:
            ofile.write(str(k) + "\t\t" + str(H1) + "\t" + str(H2) + "\t" + str(H3) + "\t\t" + str(name) + "\n")
            k += 1

    ofile.close()

############## 7x6 Example  ###############################################
#toplexes = [[0,1],[0,2],[1,2,3],[2,3,4,5],[5,6]]
##flagtoplexes = [[0,1,2],[1,2,3],[2,3,4,5],[5,6]]
#ascdict = {0:"E", 1:"C", 2:"A", 3:"K", 4:"V", 5:"T2", 6:"T1"}
#print("Local Homology of flag complex generated by original 7 by 6 diagram")
#locHomTable(sh.flag(toplexes),"7x6",ascdict,1,"LH.txt")

############################################################################

############## 7x6 Example AS version ######################################
edgeList76 = [[0,1],[0,2],[1,2],[1,3],[2,3],[2,4],[2,5],[3,4],[3,5],[4,5],[5,6]]
ascdict = {0:"E", 1:"C", 2:"A", 3:"K", 4:"V", 5:"T2", 6:"T1"}
gflag = sh.flag(edgeList76,4)
locHomTable(gflag,"7x6",ascdict,1,"LHAS.txt")