Created two python packages. One for algorithms implementations of the master thesis and the other for methods, classes and structures meant to help with the use of those algorithms.
This commit is contained in:
parent
c272c732d7
commit
10437a49c3
@ -0,0 +1,6 @@
|
|||||||
|
dijkstry:<br>
|
||||||
|
https://pl.wikipedia.org/wiki/Algorytm_Dijkstry
|
||||||
|
|
||||||
|
kopce:<br>
|
||||||
|
https://ufkapano.github.io/algorytmy/lekcja09/heap.html
|
||||||
|
https://docs.python.org/3/library/heapq.html
|
0
algorithms/__init__.py
Normal file
0
algorithms/__init__.py
Normal file
0
algorithms/a_star.py
Normal file
0
algorithms/a_star.py
Normal file
0
algorithms/bidirectional.py
Normal file
0
algorithms/bidirectional.py
Normal file
6
algorithms/dijkstra.py
Normal file
6
algorithms/dijkstra.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
def dijkstra_algorithm(graph, s ):
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print()
|
498202
dataset/deezer_clean_data/HR_edgeswith_weight.csv
Normal file
498202
dataset/deezer_clean_data/HR_edgeswith_weight.csv
Normal file
File diff suppressed because it is too large
Load Diff
25
main.py
25
main.py
@ -1,24 +1,5 @@
|
|||||||
def read_graph_from_file(path, separator=",", read_first_line=False, is_directed=False, has_weight=False):
|
import tools.file_service as op_file
|
||||||
edges = dict()
|
|
||||||
with open(path, 'r') as file:
|
|
||||||
read_line = read_first_line
|
|
||||||
line = file.readline()
|
|
||||||
while line != '':
|
|
||||||
if read_line:
|
|
||||||
if line[0] != "#":
|
|
||||||
split = line.split(separator)
|
|
||||||
node1 = int(split[0])
|
|
||||||
node2 = int(split[1])
|
|
||||||
if not is_directed:
|
|
||||||
if not has_weight:
|
|
||||||
edges[(node1, node2)] = 1
|
|
||||||
else:
|
|
||||||
read_line = True
|
|
||||||
line = file.readline()
|
|
||||||
return edges
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
e = read_graph_from_file("dataset/deezer_clean_data/HR_edges.csv")
|
e = op_file.read_graph_from_file("dataset/deezer_clean_data/HR_edges.csv")
|
||||||
print(e)
|
op_file.add_weight_to_file(e, "dataset/deezer_clean_data/HR_edges", ".csv")
|
||||||
|
|
||||||
|
0
tools/__init__.py
Normal file
0
tools/__init__.py
Normal file
30
tools/file_service.py
Normal file
30
tools/file_service.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import random as rand
|
||||||
|
|
||||||
|
|
||||||
|
def read_graph_from_file(path, separator=",", read_first_line=False, is_directed=False, has_weight=False):
|
||||||
|
edges = dict()
|
||||||
|
with open(path, 'r') as file:
|
||||||
|
read_line = read_first_line
|
||||||
|
line = file.readline()
|
||||||
|
while line != '':
|
||||||
|
if read_line:
|
||||||
|
if line[0] != "#":
|
||||||
|
split = line.split(separator)
|
||||||
|
node1 = int(split[0])
|
||||||
|
node2 = int(split[1])
|
||||||
|
if not is_directed:
|
||||||
|
if not has_weight:
|
||||||
|
edges[(node1, node2)] = 1
|
||||||
|
else:
|
||||||
|
edges[(node1, node2)] = split[2]
|
||||||
|
else:
|
||||||
|
read_line = True
|
||||||
|
line = file.readline()
|
||||||
|
return edges
|
||||||
|
|
||||||
|
|
||||||
|
def add_weight_to_file(graph, path, extension, separator=",", weight_scale=(1, 100)):
|
||||||
|
with open(path + "with_weight" + extension, 'w') as file:
|
||||||
|
for key in graph.keys():
|
||||||
|
file.write(str(key[0]) + separator + str(key[1]) + separator + str(rand.randint(weight_scale[0],
|
||||||
|
weight_scale[1])) + "\n")
|
Loading…
Reference in New Issue
Block a user