-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_possible_action.py
66 lines (61 loc) · 1.76 KB
/
generate_possible_action.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
import Environment as env
import IO
import numpy as np
actions = [] # Contains all combinations of action
device = [] # Contains combinations of (interface, power level) of one device
action_device = [0,0]
sub_channel = np.full(env.NUM_OF_SUB_CHANNEL,0)
mW_beam = np.full(env.NUM_OF_BEAM,0)
def gen_one_device(device,action,k):
if(k==2):
device.append(action.copy())
return
if(k==0):
for i in range(3):
action[k]=i
gen_one_device(device,action,k+1)
else:
# number of beam = number of subchannel
for i in range(env.NUM_OF_BEAM):
action[k]=i
gen_one_device(device,action,k+1)
gen_one_device(device,action_device,0)
allocated = np.full(len(device),0)
def mark_allocated(i):
interface = device[i][0]
if(interface == 0):
allocated[i] = 1
return
else:
beam = device[i][1]
for j in range(len(device)):
if(device[j][1] == beam):
allocated[j] = 1
return
def mark_unallocated(i):
interface = device[i][0]
if(interface == 0):
allocated[i] = 0
return
else:
beam = device[i][1]
for j in range(len(device)):
if(device[j][1] == beam):
allocated[j] = 0
return
action = [0,0,0]
def gen(actions,action,k):
if(k==env.NUM_OF_DEVICE):
# actions.append(tuple([tuple(row) for row in action.copy()]))
actions.append(action.copy())
return
for i in range(len(device)):
if(allocated[i]==0):
action[k] = device[i]
mark_allocated(i)
gen(actions,action,k+1)
mark_unallocated(i)
else:
continue
gen(actions,action,0)
IO.save(actions,'possible_actions')