Пример #1
0
import os
from graphlib.DirectedGraph import DirectedGraph
from graphlib.algorithms.Algorithms import Algorithms

graph = DirectedGraph.create_from_file(
    os.path.dirname(__file__) + "/files/pagerank_list.json", "adjacency_list")

dict = Algorithms().pagerank_randomwalk(graph)

print("========= Błądzenie przypadkowe =========")
for key, value in dict.items():
    print(f"({key}) ==> ", value)

dict2 = Algorithms().pagerank_randomwalk(graph)

print("========= Metoda iteracyjna =========")
for key, value in dict2.items():
    print(f"({key}) ==> ", value)
Пример #2
0
import os

from graphlib.DirectedGraph import DirectedGraph
from graphlib.representations.AdjacencyList import DirectedAdjacencyList
from graphlib.representations.AdjacencyMatrix import DirectedAdjacencyMatrix

directed_adjacency_list_graph = DirectedGraph.create_from_file(
    os.path.dirname(__file__) + "/files/directed_adjacency_list.json",
    "adjacency_list")
print(directed_adjacency_list_graph)

directed_adjacency_matrix_graph = DirectedGraph.create_from_file(
    os.path.dirname(__file__) + "/files/directed_adjacency_matrix.json",
    "adjacency_matrix")
print(directed_adjacency_matrix_graph)

directed_incidence_matrix_graph = DirectedGraph.create_from_file(
    os.path.dirname(__file__) + "/files/directed_incidence_matrix.json",
    "incidence_matrix")
print(directed_incidence_matrix_graph)

DirectedAdjacencyList(directed_incidence_matrix_graph).print()
Пример #3
0
from graphlib.algorithms.Algorithms import Algorithms
import os

from graphlib.representations.AdjacencyList import DirectedAdjacencyList

np_graph = Generator.directed_graph_generator_np(5, 0.7)

np_graph.draw("graph_2.png")

print("ilość spójnych składowych:", np_graph.SCCs(np_graph))

DirectedAdjacencyList(np_graph).print()

print("------ example ------")
# ex_g = DirectedGraph.create_from_file(os.path.dirname(__file__) + "/files/digraph_ex.json", "adjacency_list")
ex_g = DirectedGraph.create_from_file(
    os.path.dirname(__file__) + "/files/example.json", "adjacency_list")
DirectedAdjacencyList(ex_g).print()

comp3 = ex_g.SCCs(ex_g)
print("ilość spójnych składowych:", comp3)

print("------ example ------")
g = DirectedGraph()
g.add_weighted_edge(Node(0), Node(1), weight=-1)
g.add_weighted_edge(Node(1), Node(0), weight=4)
g.add_weighted_edge(Node(0), Node(2), weight=-4)
g.add_weighted_edge(Node(2), Node(1), weight=2)

D = Algorithms().johnson(g)
for i in range(len(D)):
    print(D[i])