commit bf1e2a25471e6f130dc6dccb8dce9364230bd96a Author: Pete Shadbolt Date: Mon Feb 15 15:28:48 2016 +0000 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..585129b --- /dev/null +++ b/.gitignore @@ -0,0 +1,57 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# PYC +*.pyc diff --git a/abp.py b/abp.py new file mode 100644 index 0000000..fa51621 --- /dev/null +++ b/abp.py @@ -0,0 +1,28 @@ +class Vertex(object): + def __init__(self): + self.neighbors = set() + + def __str__(self): + return "v: {}".format(", ".join(map(str, self.neighbors))) + +class GraphRegister(object): + def __init__(self, n): + self.vertices = [Vertex() for i in xrange(n)] + + def add_edge(self, v1, v2): + self.vertices[v1].neighbors.add(v2) + self.vertices[v2].neighbors.add(v1) + + + def del_edge(self, v1, v2): + self.vertices[v1].neighbors.remove(v2) + self.vertices[v2].neighbors.remove(v1) + + def __str__(self, ): + return "\n".join(str(v) for v in self.vertices) + +if __name__ == '__main__': + g = GraphRegister(10) + g.add_edge(0,1) + print g +