Skip to content

Commit

Permalink
Require Networkx
Browse files Browse the repository at this point in the history
  • Loading branch information
charwick committed Jul 28, 2022
1 parent af9be1b commit d0634d9
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ Helipad requires Python 3.7 or higher. The following libraries are also required

* [Matplotlib](https://matplotlib.org/) for visualization
* [Pandas](https://pandas.pydata.org/) for data collection
* [NetworkX](http://networkx.github.io/) for network analysis and spatial visualization

The following libraries are optional but recommended:

* [Jupyter](https://jupyter.org/), [Ipywidgets](https://pypi.org/project/ipywidgets/), and [ipympl](https://github.com/matplotlib/ipympl) to run Helipad in Jupyter notebooks
* [NetworkX](http://networkx.github.io/) for network analysis and spatial visualization
* [Readline](https://pypi.org/project/readline/) and Code for the debug console
* [Nest-asyncio](https://pypi.org/project/nest-asyncio/) to run Helipad from Spyder

## Version History

* [1.4](https://helipad.dev/2022/07/helipad-1-4/): More consistent container API, miscellaneous interface improvements
* [1.4](https://helipad.dev/2022/07/helipad-1-4/): More consistent container API, localization, miscellaneous interface improvements
* [1.3](https://helipad.dev/2021/06/helipad-1-3/): Allow mixing time series and other plots, display networks on spatial maps, goods API improvements
* [1.2](https://helipad.dev/2021/02/helipad-1-2/): Extensible visualization API, events, performance profiling, Jupyterlab support
* [1.1](https://helipad.dev/2020/10/helipad-1-1/): Virtual parameters, improved Jupyter flexibility, spatial pre-alpha, misc improvements
Expand Down
4 changes: 2 additions & 2 deletions helipad/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ def __getitem__(self, key):
if isinstance(key, str): return self.goods[key]['quantity']
elif isinstance(key, tuple):
if isinstance(key[1], str): return self.goods[key[0]][key[1]]
elif key[1]==True: return self.goods[key[0]]
elif key[1]==False: return self.goods[key]['quantity']
elif key[1] is True: return self.goods[key[0]]
elif key[1] is False: return self.goods[key]['quantity']
raise KeyError

def __setitem__(self, key, val):
Expand Down
4 changes: 0 additions & 4 deletions helipad/locales/helipad.pot
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ msgstr ""
msgid "Network density must take a value between 0 and 1."
msgstr ""

#: model.py:428
msgid "Network export requires Networkx."
msgstr ""

#: model.py:482
msgid "Breed '{0}' is not registered for the '{1}' primitive."
msgstr ""
Expand Down
7 changes: 3 additions & 4 deletions helipad/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# ==========

import os, sys, warnings, asyncio, time
import pandas
import gettext
import pandas
from random import shuffle, choice
from numpy import random

Expand All @@ -22,7 +22,7 @@ def __init__(self, locale='en'):
#Have to do this first so that _() is available early
if not hasattr(self, 'breed'):
gettext.translation('helipad', localedir=os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))+'/locales', languages=[locale]).install()

self.data = Data(self)
self.params = Params(self)
self.shocks = Shocks(self)
Expand Down Expand Up @@ -428,8 +428,7 @@ def createNetwork(self, density, kind='edge', prim=None):
return self.network(kind, prim)

def network(self, kind='edge', prim=None, excludePatches=False):
try: import networkx as nx
except: warnings.warn(_('Network export requires Networkx.'), None, 2)
import networkx as nx

#Have to use DiGraph in order to draw any arrows
G = nx.DiGraph(name=kind)
Expand Down
4 changes: 2 additions & 2 deletions helipad/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ def clear(self):

@property
def globals(self): return {k:v for k,v in self.items() if v.per is None}

@property
def perBreed(self): return {k:v for k,v in self.items() if v.per=='breed'}

@property
def perGood(self): return {k:v for k,v in self.items() if v.per=='good'}

Expand Down
7 changes: 0 additions & 7 deletions sample-models/Helicopter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ def step(self, stage):
#Just have a fixed inventory target, but update if params do
self.invTarget = {g:self.model.param(('prod','good',g))*self.model.param('num_agent')*2 for g in self.model.goods.nonmonetary}

#Keep track of typical demand
#Target sufficient inventory to handle 2 standard deviations above mean demand for the last 100 periods
# history = pandas.Series(self.model.data.getLast('demand-'+i, 100)) + pandas.Series(self.model.data.getLast('shortage-'+i, 100))
# avg[i], stdev[i] = history.mean(), history.std()
# itt = (1 if isnan(avg[i]) else avg[i]) + 2 * (1 if isnan(stdev[i]) else stdev[i])
# self.invTarget[i] = (self.invTarget[i] + itt)/2 #Smooth it a bit

#Produce stuff
self.portion[i] = (self.model.param('kImmob') * self.portion[i] + self.price[i]/tPrice) / (self.model.param('kImmob') + 1) #Calculate capital allocation
self.stocks[i] = self.stocks[i] + self.portion[i] * labor * self.model.param(('prod', 'good', i))
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
packages=setuptools.find_packages(),
package_dir={'helipad': 'helipad'},
include_package_data=True,
package_data={'': ['*.css']},
package_data={'': ['*.css', '*.mo', '*.po', '*.pot', '*.png']},
license='MIT',
install_requires=[
'matplotlib',
'pandas'
'pandas',
'networkx'
],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit d0634d9

Please sign in to comment.