fixed one bug in dijkstra backtracking
This commit is contained in:
parent
a7539c1cad
commit
9ba52e80f1
|
@ -1,6 +1,6 @@
|
|||
|
||||
config = {
|
||||
"use_sqlite": False
|
||||
"use_sqlite": True
|
||||
, "mysql_server": "172.17.0.2"
|
||||
, "mysql_user": "wikipedia"
|
||||
, "mysql_password": "wikipediastuff"
|
||||
|
|
|
@ -27,7 +27,8 @@ class DijkstraHelper(object):
|
|||
return cls(nodes, connections)
|
||||
|
||||
def dijkstra(self, root):
|
||||
self.recursive_dijkstra([root], 0)
|
||||
self._nodes[root] = 0
|
||||
self.recursive_dijkstra([root], 1)
|
||||
|
||||
def recursive_dijkstra(self, todos, depth):
|
||||
if(not todos):
|
||||
|
@ -58,4 +59,4 @@ class DijkstraHelper(object):
|
|||
cursor.executemany(sql.statements["insert_dijkstra_values"], [(k, sqlize(v)) for k,v in self._nodes.items()])
|
||||
|
||||
|
||||
|
||||
connection.commit()
|
||||
|
|
|
@ -9,7 +9,7 @@ from dijkstra import prepare_dijkstra, dijkstra
|
|||
from connectivity import shortest_path
|
||||
|
||||
from graph import DijkstraHelper
|
||||
from db_util import get_page_id
|
||||
from db_util import get_page_id, get_page_title
|
||||
|
||||
cache = get_cache("./cache/", "Angela_Merkel")
|
||||
receive_link_graph("Angela_Merkel", cache, 2)
|
||||
|
@ -21,7 +21,6 @@ print(cursor.fetchall())
|
|||
#prepare_dijkstra(cache)
|
||||
#dijkstra("Angela_Merkel", cache)
|
||||
#
|
||||
#print(shortest_path("Angela_Merkel", "Germany", cache))
|
||||
|
||||
|
||||
angela = get_page_id("Angela_Merkel", cache)
|
||||
|
@ -29,4 +28,7 @@ angela = get_page_id("Angela_Merkel", cache)
|
|||
dijkstra = DijkstraHelper.from_db(cache)
|
||||
dijkstra.dijkstra(angela)
|
||||
dijkstra.write_back(cache)
|
||||
print({k:v for k,v in dijkstra._nodes.items() if v != float("inf")})
|
||||
#print({k:v for k,v in dijkstra._nodes.items() if v != float("inf")})
|
||||
print([get_page_title(id_, cache) for id_ in shortest_path("Angela_Merkel", "Germany", cache)])
|
||||
print([get_page_title(id_, cache) for id_ in shortest_path("Angela_Merkel", "2012_Nobel_Peace_Prize", cache)])
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ sql_statements = {
|
|||
, "mysql": "SELECT COUNT(destination) FROM links WHERE destination=%s"}
|
||||
, "dijkstra_backtrack_one": {"sqlite": '''SELECT links.source
|
||||
FROM links
|
||||
LEFT JOIN dijkstra_helper ON links.destination=dijkstra_helper.page
|
||||
LEFT JOIN dijkstra_helper ON links.source=dijkstra_helper.page
|
||||
WHERE links.destination=?
|
||||
ORDER BY dijkstra_helper.value ASC
|
||||
LIMIT 1'''
|
||||
|
|
Loading…
Reference in New Issue
Block a user