Пример #1
0
def drawProgress(G, v, color, done, queue=None):
    global fileNum
    for vv in G.V():
        vv.colornum = -1
    for dv in done:
        dv.colornum = 1
    if queue:
        for c in queue:
            if type(c) == tuple:
                vertex, p = c
                vertex.colornum = 4
            else:
                for cv in c:
                    cv.colornum = 4
    for cv in color:
        cv.colornum = 2
    if v:
        v.colornum = 3
    writeDOT(G, "progress%i.dot" % fileNum)
    fileNum += 1
Пример #2
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> 
Пример #3
0
                print("\n\nTesting", testalg[0])
                startt = time()
                if testalg[0] == "Kruskal":
                    ST = testalg[2](G)
                    totalweight = 0
                    for e in ST:
                        totalweight += e.weight
                else:
                    testalg[2](G, G[0])
                endt = time()
                print("Elapsed time in seconds:", endt - startt)

                if testalg[0] != "Kruskal":
                    printmaxdist(G)
                    preparedrawing(G)
                else:
                    if len(ST) < len(G.V()) - 1:
                        print("Total weight of maximal spanning forest:", totalweight)
                    else:
                        print("Total weight of spanning tree:", totalweight)
                    for e in G.E():
                        e.colornum = 0
                    for e in ST:
                        e.colornum = 1
                    for v in G.V():
                        v.label = v._label

                if WriteDOTFiles:
                    # writeDOT(G,'graphs/'+testalg[3]+'.dot',directed=testalg[4])
                    writeDOT(G, testalg[3] + ".dot", directed=testalg[4])
Пример #4
0
                print("\n\nTesting", testalg[0])
                startt = time()
                if testalg[0] == "Kruskal":
                    ST = testalg[2](G)
                    totalweight = 0
                    for e in ST:
                        totalweight += e.weight
                else:
                    testalg[2](G, G[0])
                endt = time()
                print("Elapsed time in seconds:", endt - startt)

                if testalg[0] != "Kruskal":
                    printmaxdist(G)
                    preparedrawing(G)
                else:
                    if len(ST) < len(G.V()) - 1:
                        print("Total weight of maximal spanning forest:", totalweight)
                    else:
                        print("Total weight of spanning tree:", totalweight)
                    for e in G.E():
                        e.colornum = 0
                    for e in ST:
                        e.colornum = 1
                    for v in G.V():
                        v.label = v._label

                if WriteDOTFiles:
                    # writeDOT(G,'graphs/'+testalg[3]+'.dot',directed=testalg[4])
                    writeDOT(G, testalg[3] + '.dot', directed=testalg[4])
Пример #5
0
                startt = time()
                if testalg[0] == "Kruskal":
                    ST = testalg[2](G)
                    totalweight = 0
                    for e in ST:
                        totalweight += e.weight
                else:
                    testalg[2](G, G[0])
                endt = time()
                print("Elapsed time in seconds:", endt - startt)

                if testalg[0] != "Kruskal":
                    printmaxdist(G)
                    preparedrawing(G)
                else:
                    if len(ST) < len(G.V()) - 1:
                        print("Total weight of maximal spanning forest:",
                              totalweight)
                    else:
                        print("Total weight of spanning tree:", totalweight)
                    for e in G.E():
                        e.colornum = 0
                    for e in ST:
                        e.colornum = 1
                    for v in G.V():
                        v.label = v._label

                if WriteDOTFiles:
                    # writeDOT(G,'graphs/'+testalg[3]+'.dot',directed=testalg[4])
                    writeDOT(G, testalg[3] + '.dot', directed=testalg[4])