Ejemplo n.º 1
0
    def graphInfo(self, filename):
        if filename[-2:] == "gr":
            gl = [loadgraph(filename, readlist=False)]
        else:
            gl = loadgraph(filename, readlist=True)[0]
        print("This file contains %i graph%s"%(len(gl), "s" if len(gl) > 1 else ""))
        i = 0
        for g in gl:
            print("Graph %i:"%i)
            print("\tIs %sconnected, is %sa tree, has %i vertice%s and %i edge%s"
                  %("" if isConnected(g) else "not ",
                    "" if isTree(g) else "not ",
                    len(g.V()), "s" if len(g.V()) > 1 else "",
                    len(g.E()), "s" if len(g.E()) > 1 else ""))

            i+=1
Ejemplo n.º 2
0
 def __init__(self, filename, aut=False):
     self.filename = filename
     self.aut = aut
     if filename[-2:] == "gr":
         self.single = True
     else:
         self.single = False
     self.g = loadgraph(filename, readlist=not self.single)
     if not self.single:
         self.g = self.g[0]
     print("Launching job [%s]..."%filename)
     threading._start_new_thread(self.run, tuple())
Ejemplo n.º 3
0
TestDijkstraUndirected = False
TestKruskal = False

WriteDOTFiles = True

# Use these options to select the graphs to test your algorithms on:
# TestInstances = ["weightedexample.gr"]
# TestInstances = ["randomplanar.gr"]
# TestInstances = ["negativeweightexample.gr"]
# TestInstances = ["negativeweightcycleexample.gr"]
# TestInstances = ["WDE100.gr", "WDE200.gr", "WDE400.gr", "WDE800.gr", "WDE2000.gr"];
WriteDOTFiles = True
# TestInstances = ["bbf2000.gr"]
TestInstances = ["graph7.gr"]

writeDOT(loadgraph("negativeweightexample.gr"), "negativeweightexample.dot")

# If you have implemented a module fastgraphs.py (compatible with basicgraphs.py),
# you can set this option to True:
UseFastGraphs = False


def relax(u, v, e):
    if u.dist is not None and (v.dist is None or e.weight + u.dist < v.dist):
        v.dist = e.weight + u.dist
        v.inedge = e


def BellmanFordUndirected(G, start):
    """
	Arguments: <G> is a graph object, where edges have integer <weight> 
Ejemplo n.º 4
0





if __name__ == "__main__":
    from time import time

    if UseFastGraphs:
        import fastgraphs
    for FileName in TestInstances:
        if UseFastGraphs:
            print("\n\nLoading graph", FileName, "(Fast graph)")
            # G=loadgraph("graphs/"+FileName,graph)
            G = loadgraph(FileName, fastgraphs.graph)
        else:
            print("\n\nLoading graph", FileName)
            # G=loadgraph("graphs/"+FileName)
            G = loadgraph(FileName)

        for i in range(len(G.V())):
            G[i].colornum = i

        # Tuple arguments below:
        # First: printable string
        # Second: Boolean variable: should test be done?
        # Third: Function
        # Fourth: Filename
        # Fifth: Whether output should be directed
        for testalg in [("Bellman-Ford, undirected", TestBellmanFordUndirected, BellmanFordUndirected,
Ejemplo n.º 5
0
    print("\n\n")
    if automorphisms:
        print(str1, " Automorphisms:")
    else:
        print(str1)
    for group in isomorphisms:
        str2 = str([gl.index(g) for g in group])
        if automorphisms:
            print(str2, " " * (len(str1) - len(str2)), automorphisms[group[0]])
        else:
            print(str2)


def getIsomorphismGroups(graphList, aut=False):
    """[gl.index(g) for g in group]
    The full algorithm that converts a list of graphs to a list of groups of isomorphic graphs
    The outcome contains all elements of the input, in isomorphic groups. Every graph in a group is isomorphic with
    every other graph in the groups.
    :param graphList: A list of graphs
    :return: A list containing smaller list. The smaller lists are groups of isomorphic graphs.
    """
    groups, G = getAllIsomorphisms(graphList)
    further, automorphisms = refineFurther(groups, aut)
    output(graphList, further, automorphisms)
    return further

if __name__ == "__main__":
    gl = loadgraph("./../data/bigtrees1.grl", readlist=True)
    # gl = [[disjointUnionMulti([createCycleGraph(1), createCycleGraph(1)]), createCycleGraph(2), createCycleGraph(2)]]
    getIsomorphismGroups(gl[0], True)
Ejemplo n.º 6
0
        if v.dist != None:
            v.label = v.dist
        else:
            v.label = "inf"


if __name__ == "__main__":
    from time import time

    if UseFastGraphs:
        import fastgraphs
    for FileName in TestInstances:
        if UseFastGraphs:
            print("\n\nLoading graph", FileName, "(Fast graph)")
            # G=loadgraph("graphs/"+FileName,graph)
            G = loadgraph(FileName, fastgraphs.graph)
        else:
            print("\n\nLoading graph", FileName)
            # G=loadgraph("graphs/"+FileName)
            G = loadgraph(FileName)

        for i in range(len(G.V())):
            G[i].colornum = i

        # Tuple arguments below:
        # First: printable string
        # Second: Boolean variable: should test be done?
        # Third: Function
        # Fourth: Filename
        # Fifth: Whether output should be directed
        for testalg in [