-
Notifications
You must be signed in to change notification settings - Fork 5
/
bootstrap.py
85 lines (65 loc) · 2.85 KB
/
bootstrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# A template for bootstrapping new models.
# See https://helipad.dev/ for complete documentation
#===============
# SETUP
# Instantiate the object and add parameters, breeds, and goods below.
#===============
from helipad import Helipad
# from utility import CobbDouglas
def setup():
heli = Helipad()
heli.name = 'Model Name'
heli.agents.order = 'random' #Can be changed to 'linear' or 'match'
heli.stages = 1 #Change to create a multi-stage model
# heli.params.add('name', 'title', 'type (slider, menu, or check)', dflt=default, opts={depends on type})
# heli.goods.add('good1','hex color', lambda breed: endowment)
# heli.agents.addBreed('name1', 'hex color')
# heli.agents.addBreed('name2', 'hex color')
#===============
# BEHAVIOR
# A list of hooks and their function signatures can be found at http://helipad-docs.nfshost.com/hooks/
#===============
#Any variables or properties the agent should keep track of should have default values set here.
@heli.hook
def agentInit(agent, model):
#agent.myAgentProperty = 0
#agent.utility = CobbDouglas(['good1'])
pass
#Any global variables that should be kept track of should have default values set here.
@heli.hook
def modelPostSetup(model):
#model.myModelProperty = 0
pass
#Agent logic should be written here.
@heli.hook
def agentStep(agent, model, stage):
pass
#Any global code to be run each period should be hooked to modelStep, modelPreStep, or modelPostStep.
#modelStep will run as many times per period as there are stages. modelPreStep and modelPostStep
#will run at the beginning and end of each period, respectively, and do not take a stage argument.
@heli.hook
def modelStep(model, stage):
pass
#===============
# DATA AND VISUALIZATION
# Register reporters, plots, and series here
#===============
from helipad.visualize import TimeSeries
viz = heli.useVisual(TimeSeries)
#Reporters collect data from the model each period, generally from parameters set in agentInit and modelPostSetup.
# heli.data.addReporter('myReporter1', heli.data.agentReporter('myAgentProperty', 'agent', stat='mean'))
# heli.data.addReporter('myReporter2', heli.data.modelReporter('myModelProperty'))
#Plots are areas on the graph where series can be drawn to keep track of reporter data in real time.
myplot = viz.addPlot('myplot', 'Custom Properties', logscale=False, selected=True)
#Series draw reporter data on a plot. Here we draw two series on the same plot.
#The Plot object can also be accessed later with heli['myplot'], so the following two methods are identical.
# myplot.addSeries('myplot', 'myReporter1', 'My Agent Property', 'hex color')
# heli['myplot'].addSeries('myplot', 'myReporter2', 'My Model Property', 'hex color')
return heli
#===============
# LAUNCH THE GUI
#===============
#Only launch the cpanel if we haven't embedded
if __name__ == '__main__':
heli = setup()
heli.launchCpanel()