-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,198 additions
and
675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
code/ARAX/ARAXQuery/Path_Finder/BidirectionalPathFinder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import sys | ||
import os | ||
import math | ||
import threading | ||
|
||
sys.path.append(os.path.dirname(os.path.abspath(__file__))) | ||
from BreadthFirstSearch import BreadthFirstSearch | ||
from model.Node import Node | ||
from model.Path import Path | ||
from model.PathContainer import PathContainer | ||
|
||
|
||
class BidirectionalPathFinder: | ||
|
||
def __init__(self, repository): | ||
self.repo = repository | ||
|
||
def find_all_paths(self, node_id_1, node_id_2, hops_numbers=1): | ||
result = set() | ||
if hops_numbers == 0: | ||
return result | ||
if node_id_1 == node_id_2: | ||
return result | ||
|
||
hops_numbers_1 = math.floor((hops_numbers + 1) / 2) | ||
hops_numbers_2 = math.floor(hops_numbers / 2) | ||
|
||
path_container_1 = PathContainer() | ||
bfs_1 = BreadthFirstSearch(self.repo, path_container_1) | ||
|
||
path_container_2 = PathContainer() | ||
bfs_2 = BreadthFirstSearch(self.repo, path_container_2) | ||
|
||
thread_1 = threading.Thread(target=lambda: bfs_1.traverse(node_id_1, hops_numbers_1)) | ||
thread_2 = threading.Thread(target=lambda: bfs_2.traverse(node_id_2, hops_numbers_2)) | ||
thread_1.start() | ||
thread_2.start() | ||
thread_1.join() | ||
thread_2.join() | ||
|
||
intersection_list = path_container_1.path_dict.keys() & path_container_2.path_dict.keys() | ||
|
||
for node in intersection_list: | ||
for path_1 in path_container_1.path_dict[node]: | ||
for path_2 in path_container_2.path_dict[node]: | ||
temp_path_1 = [Node(link.id, link.weight) for link in path_1.links] | ||
temp_path_2 = [] | ||
for i in range(len(path_2.links) - 2, -1, -1): | ||
temp_path_2.append(Node(path_2.links[i].id, path_2.links[i + 1].weight)) | ||
temp_path_1.extend(temp_path_2) | ||
if len(temp_path_1) == len(set(temp_path_1)): | ||
result.add(Path(0, temp_path_1)) | ||
|
||
result = sorted(list(result), key=lambda path: path.compute_weight()) | ||
|
||
return result |
Oops, something went wrong.