-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflu_initial.py
More file actions
71 lines (49 loc) · 1.63 KB
/
flu_initial.py
File metadata and controls
71 lines (49 loc) · 1.63 KB
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
import sys
sys.path.append('/home/konrad/ICM/cog-abm-tutorial/COG-ABM/src')
# TODO adapt to your instalations^^^^
import random
from cog_abm.core import Simulation, Agent
from cog_abm.core.interaction import Interaction
from cog_abm.extras.additional_tools import generate_simple_network
from cog_abm.extras.tools import avg
NUM_AGENTS = 100
NUM_DOCTORS =
NUM_ILL = 5
INFECT_PROBAB = 0.75
CURE_PROB = 0.95
ITERS = 500000
DUMP_FREQ = ITERS / 100
class FluAgentState(object):
# TODO
class FluInteraction(Interaction):
def num_agents(self):
return 2
def interact(self, agent1, agent2):
ags1, ags2 = agent1.state, agent2.state
# TODO
def prepare_agents(num_agents, num_doctors, num_ill):
agents = [Agent(state=FluAgentState())
for _ in xrange(num_agents)]
#TODO and adapt ^^^^
def flu_experiment(num_agents, num_doctors, num_ill, iters):
agents = prepare_agents(num_agents, num_doctors, num_ill)
topology = generate_simple_network(agents)
s = Simulation(topology, FluInteraction(), agents)
return s.run(iters, DUMP_FREQ)
def analyze(results):
def tmp(agents):
return avg([ for agent in agents])
# TODO ^^^^^^ 1 - infected, 0 - not infected
return [(it, tmp(agents)) for it, agents in results]
def present_results(analysis):
import pprint
pprint.pprint(analysis)
from presenter.charts import wykres
wykres(analysis, "iteration", "ill percentage")
def main(args):
res = \
flu_experiment(NUM_AGENTS, NUM_DOCTORS, NUM_ILL, ITERS)
analysis = analyze(res)
present_results(analysis)
if __name__ == '__main__':
main(sys.argv[1:])