def _get_shortest_path(start, end, skips): key = _get_path_cache_key(start, end, skips) path_string = r.get(key) if not path_string: length, aids = sd.bidirectional_dijkstra(G, start, end, weight='weight', skipset=skips) path_string = ','.join(aids) else: print "cache hit", key, ' ', path_string aids = path_string.split(',') length = len(aids) # always set to reset the cache expiration time r.set(key, path_string, ex=cache_expiration_time) return length, aids
def artist_raw_path(start_aid, end_aid, weighted=True, skipset=None): start = time.time() try: if weighted: weight = 'weight' else: weight = 'None' length, aids = sd.bidirectional_dijkstra(G, start_aid, end_aid, weight='weight', skipset=skipset) end = time.time() score = score_path(aids) print 'path calculated in', end - start, 'secs', 'length:', len(aids), 'score:', score return score, aids except nx.NetworkXNoPath: return 0, None