py-dag
Python implementation of directed acyclic graph
This library is largely provided as-is. Breaking changes may happen without warning. If you choose to use it, you should peg your dependencies to a specific version.
Python implementation of directed acyclic graph
License: MIT License
Python implementation of directed acyclic graph
This library is largely provided as-is. Breaking changes may happen without warning. If you choose to use it, you should peg your dependencies to a specific version.
Why you gotta be all lazy?
:-)
What is the point of using a class if you pass in the graph as a parameter anyways?
As a starting-point: I've hacked py-dag to barely work for Python 3 in saxifrage/caac-map@962610b.
Really enjoying playing with this library to learn some Python.
Here's a graph that's used a lot in the tests:
dag.from_dict({'a': ['b', 'c'],
'b': ['d'],
'c': ['d'],
'd': []})
For this graph the shortest path from a to d is a => b = d
Here's how this algo can be implemented:
def iter_flatten(iterable):
it = iter(iterable)
for e in it:
if isinstance(e, (list, tuple)):
for f in iter_flatten(e):
yield f
else:
yield e
def shortest_path(self, start, end, graph=None):
if graph is None:
graph = self.graph
dist = {start: [start]}
q = deque([start])
while len(q):
at = q.popleft()
for next in graph[at]:
if next not in dist:
dist[next] = [dist[at], next]
q.append(next)
a = dist.get(end)
return [i for i in iter_flatten(a)]
The iter_flatten
is a hack and could probably be improved a bunch, but it works!
Let me know if you'd be open to adding this and I can send a pull request with some tests.
On 19 February 2017, Python 3 will be 3,000 days old! We are interested to see if we can get at least 50% of the Top 5,000 PyPI packages to compatible with Python 3 by that date. We are really close and given that this package is in the PyPI Top 5,000, we seek your assistance in pushing us over that threshold.
So, if this package already supports Python 3 then please consider adding an appropriate trove classifier "Programming Language :: Python :: 3" to this package's PyPI page so that tools can automaticly determine its Python 3 compatibility.
Right now the method for doing a topological sort is DAG._topological_sort
, which follows the python convention for labelling "private" methods. I believe this is actually a first class feature of this library, and should follow the convention for "public" methods (so it would be DAG.topological_sort
).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.