forked from stablum/soa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (52 loc) · 1.51 KB
/
main.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
import environment
import config
import behaviour
import gi
import stats
from config import g
count_steps = 0
def wakeup_nodes(nodes):
"""
wakes up the affected nodes for action. this will call 'behaviour'
"""
for node in nodes:
behaviour.node_method(node) # the action is defined there...
def step(): # what happens in each cycle. Main calls happen here.
global count_steps
count_steps += 1
print "count_steps "+str(count_steps)
nodes = environment.step()
wakeup_nodes(nodes) # calls their behaviour, which calls the policy (what to do), and finally applies actions
print "killed edges: "+str(stats.collector.num_kills)
stats.snapshot()
print "total graph weight:"+str(stats.collector.total_weight)
stats.new_collector()
def termination_condition3():
if gi.num_edges() <= 0:
return True
return False
def termination_condition():
global count_steps
if count_steps >= config.max_steps:
return True
return False
def initialize():
"""
initialization procedures. For example: attaching methods to nodes.
"""
global count_steps
count_steps = 0
stats.new_collector()
for node in gi.nodes():
if node is not None:
setattr(node, "weight", 1.0)
def end():
stats.write_history()
def run(gephi_stuff): # the Highest function
global count_steps
config.set_g(gephi_stuff['g'])
config.set_gephi(gephi_stuff)
initialize()
while not termination_condition():
step()
end()