Created
March 8, 2016 03:52
-
-
Save zshihang/9d93de0bcd98547d9d85 to your computer and use it in GitHub Desktop.
Simple implementation of graph
This file contains hidden or 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
class SimpleGraph(object): | |
def __init__(self, edges, weights=None): | |
self._edges = edges | |
self._weights = weights | |
def neighbors(self, id): | |
return self._edges[id] | |
def cost(self, start, end): | |
return self._weights[(start, end)] | |
@property | |
def nodes(self): | |
return self._edges.keys() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment