Пример #1
0
from w2_graphs.graphIO import loadgraph, savegraph
from w2_graphs.basicgraphs import *
from w2_graphs.ex1 import createCycleGraph

def complement(g: graph):
    h = graph(len(g.V()))
    for i in range(len(g.V())):
        for j in range(i+1, len(g.V())):
            if g.findedge(g[i], g[j]) is None:
                h.addedge(h[i], h[j])
    return h


if __name__ == "__main__":
    print(complement(createCycleGraph(10)))
    print(complement(graph(4)))

    g = loadgraph('examplegraph.gr')
    savegraph(complement(g), 'complementexamplegraph.gr')
Пример #2
0
import time

from w2_graphs.graphIO import loadgraph, savegraph
from w2_graphs.ex4 import graphSearch

g = loadgraph('graph8000.gr')
i = 0
times = []
for n in [1000, 2000, 4000, 8000]:
    g = loadgraph('graph%i.gr'%n)
    times.append(0)
    for j in range(5):
        ts = time.time()
        graphSearch(g[0], False)
        t = time.time() - ts
        times[i] += t
    times[i] /= 10
    i += 1

print(times)