-
Notifications
You must be signed in to change notification settings - Fork 2
/
policies.py
66 lines (58 loc) · 1.83 KB
/
policies.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
import gi
def pro_poor(node):
pool = []
for curr in gi.neighbors(node):
e = gi.get_edge(curr,node)
pool.append((gi.edge_importance(e),e))
importance,e = sorted(pool, key=lambda x: -x[0])[-1]
return {e: node.budget}
def pro_rich(node):
pool = []
for curr in gi.neighbors(node):
e = gi.get_edge(curr,node)
pool.append((gi.edge_importance(e),e))
importance,e = sorted(pool, key=lambda x: x[0])[-1]
return {e: node.budget}
def simple(node):
"""
chooses a random edge and returns the action that
represents an increase of its weight, according to the budget.
returns a request for increasing the weight of
edge e in the amount of the total budget
"""
n = gi.random_neighbor(node) #hood
e = gi.get_edge(n,node)
return {e: node.budget}
def passive(node):
"""
chooses the same edge that has been damaged, to be reinforced.
this will be the baseline, where essentially the same weight-damage is inflicted
to the graph, but there is no counteraction.
a trick to get the edge: find the node's neighbor that also has a budget max(budget A+budget b)
"""
pool = []
for curr in gi.neighbors(node):
e = gi.get_edge(curr,node)
bu1, bu2 =0,0
bu1, bu2= e.source.budget, e.target.budget
buds=[bu1,bu2]
if None in buds:
buds.remove(None)
totbud= sum(buds)
pool.append((totbud,e))
e_damaged,e = sorted(pool, key=lambda x: x[0])[-1]
print pool
print e_damaged
return{e: node.budget}
#TODO: Policy_shortpath
#TODO: Policy_prorich
#TODO: Policy_propoor
#TODO: Policy_proheavy
#TODO: Policy_prolight
#TODO: Policy_proweightrich
#TODO: Policy_proweightpoor
def get(name):
"""
returns the policy specified by the given name
"""
return globals()[name]