예제 #1
0
from main.dimacs import load_weighted_graph
from main.lab4.graph import Graph

path = 'graphs/vcover/nonplanar-ex1'

g = Graph(load_weighted_graph(path))
print(g.find_min_vertex_cover())

예제 #2
0
import heapq

from main.dimacs import load_weighted_graph
from main.lab3.graph import Graph

g = Graph(load_weighted_graph('graphs-lab3/clique100'))
print(g.find_min_cut())
    def connect_to(self, v):
        self.out.add(v)


def check_lex_bfs(G, vs):
    n = len(G)
    pi = [None] * n
    for i, v in enumerate(vs):
        pi[v] = i

    for i in range(n - 1):
        for j in range(i + 1, n - 1):
            Ni = G[vs[i]].out
            Nj = G[vs[j]].out

            verts = [pi[v] for v in Nj - Ni if pi[v] < i]
            if verts:
                viable = [pi[v] for v in Ni - Nj]
                if not viable or min(verts) <= min(viable):
                    return False
    return True

(V, L) = load_weighted_graph(path)

G = [None] + [Node(i) for i in range(1, V + 1)]  # żeby móc indeksować numerem wierzchołka

for (u, v, _) in L:
    G[u].connect_to(v)
    G[v].connect_to(u)
예제 #4
0
from main.dimacs import load_weighted_graph
from main.lab1.graph import Graph

g = load_weighted_graph('graphs-lab1/rand1000_100000')
graph = Graph(g)
weights = graph.dijkstra_max_current(1)
print(weights[2])
def main():
    g = load_weighted_graph('graphs-lab1/clique5')
    g[1].sort(key=lambda x: x[2], reverse=True)
    print(zad(g, 0, 1))