{ "info": { "author": "Kent Kawashima", "author_email": "i@kentwait.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Education", "Intended Audience :: Science/Research", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Scientific/Engineering" ], "description": "`nxsim`_\r\n========\r\n\r\nNxsim is a Python package for simulating agents connected by any type of\r\nnetwork using SimPy and Networkx in Python 3.4.\r\n\r\nInstall\r\n-------\r\n\r\n::\r\n\r\n pip3 install nxsim # from PyPI\r\n pip3 install git+git://github.com/kentwait/nxsim.git # from GitHub\r\n\r\n\r\nQuickstart\r\n----------\r\n\r\nNxsim provides a framework for doing forward-time simulations of events\r\noccurring in a network. It uses Networkx to create a network and SimPy 3\r\nto create agents over each node in the network.\r\n\r\nTo create a simulation, nxsim requires a graph generated by Networkx and\r\nan \u201cagent\u201d class to populate each node of the network.\r\n\r\nFirst, create a graph using Networkx.\r\n\r\n::\r\n\r\n import networkx as nx\r\n\r\n number_of_nodes = 10\r\n G = nx.complete_graph(number_of_nodes)\r\n\r\nThen, subclass *BaseNetworkAgent* to create your own agent based on your\r\nneeds.\r\n\r\n::\r\n\r\n from nxsim import BaseNetworkAgent\r\n\r\n # Just like subclassing a process in SimPy\r\n class MyAgent(BaseNetworkAgent):\r\n def __init__(self, environment=None, agent_id=0, state=()): # Make sure to have these three keyword arguments\r\n super().__init__(environment=environment, agent_id=agent_id, state=state)\r\n # Add your own attributes here\r\n\r\n def run(self):\r\n # Add your behaviors here\r\n\r\nNotice that \u201cagents\u201d in nxsim use the same concepts as \u201cprocesses\u201d in\r\nSimPy 3 except that their interactions can be limited by the graph in\r\nthe simulation environment. For more information about SimPy, they have\r\na great introduction posted on their `website`_.\r\n\r\nHere is a graph-based example:\r\n\r\n::\r\n\r\n import random\r\n from nxsim import BaseNetworkAgent\r\n\r\n class ZombieOutbreak(BaseNetworkAgent):\r\n def __init__(self, environment=None, agent_id=0, state=()):\r\n super().__init__(environment=environment, agent_id=agent_id, state=state)\r\n self.bite_prob = 0.05\r\n\r\n def run(self):\r\n while True:\r\n if self.state['id'] == 1:\r\n self.zombify()\r\n yield self.env.timeout(1)\r\n else:\r\n yield self.env.event()\r\n\r\n def zombify(self):\r\n normal_neighbors = self.get_neighboring_agents(state_id=0)\r\n for neighbor in normal_neighbors:\r\n if random.random() < self.bite_prob:\r\n neighbor.state['id'] = 1 # zombie\r\n print(self.env.now, self.id, neighbor.id, sep='\\t')\r\n break\r\n\r\nYou can now set-up your simulation by creating a *NetworkSimulation*\r\ninstance.\r\n\r\n::\r\n\r\n from nxsim import NetworkSimulation\r\n\r\n # Initialize agent states. Let's assume everyone is normal.\r\n # Add keys as as necessary, but \"id\" must always refer to that state category\r\n init_states = [{'id': 0, } for _ in range(number_of_nodes)]\r\n\r\n # Seed a zombie\r\n init_states[5] = {'id': 1}\r\n sim = NetworkSimulation(topology=G, states=init_states, agent_type=ZombieOutbreak,\r\n max_time=30, dir_path='sim_01', num_trials=1, logging_interval=1.0)\r\n\r\nAnd finally, start it up.\r\n\r\n::\r\n\r\n sim.run_simulation()\r\n\r\nRunning the simulation saves pickled dictionaries into the *dir\\_path*\r\nfolder, in this case to \u201csim\\_01\u201d. Now, let\u2019s retrieve the history and\r\nstates of the trial\r\n\r\n::\r\n\r\n trial = BaseLoggingAgent.open_trial_state_history(dir_path='sim_01', trial_id=0)\r\n\r\nAnd plot the number of zombies per time interval using matplotlib:\r\n\r\n::\r\n\r\n from matplotlib import pyplot as plt\r\n zombie_census = [sum([1 for node_id, state in g.items() if state['id'] == 1]) for t,g in trial.items()]\r\n plt.plot(zombie_census)\r\n\r\nAnd that\u2019s it!\r\n\r\nNote\r\n====\r\n\r\nThis package is still under development. If you encounter a bug, please\r\nfile an issue at https://github.com/kentwait/nxsim/issues to get it\r\nresolved.\r\n\r\nAcknowledgment\r\n==============\r\n\r\nThanks to Jo\u00e9 Schaul for bringing `ComplexNetworkSim`_ to the world.\r\nThis project is a SimPy 3- and Python 3.4-compatible fork of\r\nComplexNetworkSim.\r\n\r\nLinks\r\n=====\r\n\r\n- `nxsim - Github`_\r\n- `nxsim - PyPI`_\r\n- `SimPy v3.0 Documentation`_\r\n- `Networkx v1.9 Documentation`_\r\n- `matplotlib v1.4.3 Documentation`_\r\n- `ComplexNetworkSim Documentation`_\r\n\r\n.. _nxsim: https://github.com/kentwait/nxsim\r\n.. _website: https://simpy.readthedocs.org/en/latest/simpy_intro/index.html\r\n.. _ComplexNetworkSim: https://github.com/jschaul/ComplexNetworkSim\r\n.. _nxsim - Github: https://github.com/kentwait/nxsim\r\n.. _nxsim - PyPI: https://pypi.python.org/pypi/nxsim\r\n.. _SimPy v3.0 Documentation: https://simpy.readthedocs.org/en/latest/contents.html\r\n.. _Networkx v1.9 Documentation: http://networkx.github.io/documentation/networkx-1.9.1\r\n.. _matplotlib v1.4.3 Documentation: http://matplotlib.org/users/\r\n.. _ComplexNetworkSim Documentation: https://pythonhosted.org/ComplexNetworkSim", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/kentwait/nxsim/archive/master.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/kentwait/nxsim", "keywords": "networks, simulation, complex networks, discrete event simulation, forward simulation, temporal networks", "license": "Apache License, Version 2.0", "maintainer": "", "maintainer_email": "", "name": "nxsim", "package_url": "https://pypi.org/project/nxsim/", "platform": "", "project_url": "https://pypi.org/project/nxsim/", "project_urls": { "Download": "https://github.com/kentwait/nxsim/archive/master.zip", "Homepage": "http://github.com/kentwait/nxsim" }, "release_url": "https://pypi.org/project/nxsim/0.1.2/", "requires_dist": null, "requires_python": null, "summary": "nxsim is a Python package for simulating agents in a network.", "version": "0.1.2" }, "last_serial": 1623557, "releases": { "0.1.2": [ { "comment_text": "", "digests": { "md5": "59ee54470768a6b5693857634252841f", "sha256": "b8bb8a03b21bac69b7de51435b37835629b3affa7994357346a8ca6f9819616f" }, "downloads": -1, "filename": "nxsim-0.1.2.tar.gz", "has_sig": false, "md5_digest": "59ee54470768a6b5693857634252841f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5199, "upload_time": "2015-07-03T00:03:40", "url": "https://files.pythonhosted.org/packages/1a/9b/54dc90f75a1a1bb0b6ca1e7de668859925b99fa15dd34bb44d6cda415085/nxsim-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "59ee54470768a6b5693857634252841f", "sha256": "b8bb8a03b21bac69b7de51435b37835629b3affa7994357346a8ca6f9819616f" }, "downloads": -1, "filename": "nxsim-0.1.2.tar.gz", "has_sig": false, "md5_digest": "59ee54470768a6b5693857634252841f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5199, "upload_time": "2015-07-03T00:03:40", "url": "https://files.pythonhosted.org/packages/1a/9b/54dc90f75a1a1bb0b6ca1e7de668859925b99fa15dd34bb44d6cda415085/nxsim-0.1.2.tar.gz" } ] }