-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interaction_Multi_BrightLightExcitedVisitor_and_Env.py
106 lines (80 loc) · 4.45 KB
/
Interaction_Multi_BrightLightExcitedVisitor_and_Env.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 7 23:09:52 2018
@author: lingheng
"""
import tensorflow as tf
import numpy as np
import time
import matplotlib.pyplot as plt
from Environment.LASEnv import LASEnv
from LASAgent.RandomLASAgent import RandomLASAgent
from LASAgent.LASAgent_Actor_Critic import LASAgent_Actor_Critic
from Environment.BrightLightExcitedVisitorEnv import BrightLightExcitedVisitorEnv
from VisitorAgent.BrightLightExcitedVisitorAgent import BrightLightExcitedVisitorAgent
if __name__ == '__main__':
# Instantiate visitor environment object
envVisitor = BrightLightExcitedVisitorEnv('127.0.0.1', 19999)
# Instantiate a red light excited visitor0
visitor = BrightLightExcitedVisitorAgent("Visitor",envVisitor.lights_num)
# Instantiate a red light excited visitor0
visitor0 = BrightLightExcitedVisitorAgent("Visitor#0",envVisitor.lights_num)
# Instantiate a red light excited visitor1
visitor1 = BrightLightExcitedVisitorAgent("Visitor#1",envVisitor.lights_num)
# Instantiate a red light excited visitor2
visitor2 = BrightLightExcitedVisitorAgent("Visitor#2",envVisitor.lights_num)
# Instantiate a red light excited visitor2
visitor3 = BrightLightExcitedVisitorAgent("Visitor#3",envVisitor.lights_num)
observation_For_Visitor = envVisitor._self_observe(visitor._visitorName)
observation_For_Visitor0 = envVisitor._self_observe(visitor0._visitorName)
observation_For_Visitor1 = envVisitor._self_observe(visitor1._visitorName)
observation_For_Visitor2 = envVisitor._self_observe(visitor2._visitorName)
observation_For_Visitor3 = envVisitor._self_observe(visitor3._visitorName)
# Step counter
i = 1
done = False
reward_for_Visitor = 0
reward_for_Visitor0 = 0
reward_for_Visitor1 = 0
reward_for_Visitor2 = 0
reward_for_Visitor3 = 0
light_num_change = []
try:
while True:
# Visitor interacts with environment.
visitorName, action = visitor.perceive_and_act(observation_For_Visitor,reward_for_Visitor,done)
observation_For_Visitor, reward_for_Visitor, done, [] = envVisitor.step(visitorName, action)
print("Visitor Step: {}, brigh_light_num: {}".format(i, visitor.bright_light_num))
# Visitor0 interacts with environment.
visitorName0, action = visitor0.perceive_and_act(observation_For_Visitor0,reward_for_Visitor0,done)
observation_For_Visitor0, reward_for_Visitor0, done, [] = envVisitor.step(visitorName0, action)
print("Visitor Step: {}, brigh_light_num: {}".format(i, visitor0.bright_light_num))
# Visitor1 interacts with environment.
visitorName1, action = visitor1.perceive_and_act(observation_For_Visitor1,reward_for_Visitor1,done)
observation_For_Visitor1, reward_for_Visitor1, done, [] = envVisitor.step(visitorName1, action)
print("Visitor Step: {}, brigh_light_num: {}".format(i, visitor1.bright_light_num))
# Visitor2 interacts with environment.
visitorName2, action = visitor2.perceive_and_act(observation_For_Visitor2,reward_for_Visitor2,done)
observation_For_Visitor2, reward_for_Visitor2, done, [] = envVisitor.step(visitorName2, action)
print("Visitor Step: {}, brigh_light_num: {}".format(i, visitor2.bright_light_num))
# Visitor3 interacts with environment.
visitorName3, action = visitor3.perceive_and_act(observation_For_Visitor3,reward_for_Visitor3,done)
observation_For_Visitor3, reward_for_Visitor3, done, [] = envVisitor.step(visitorName3, action)
print("Visitor Step: {}, brigh_light_num: {}".format(i, visitor3.bright_light_num))
time.sleep(0.1)
# Plot bright_light_number
plt.scatter(i, visitor3.bright_light_num, c="r")
if i % 200 == 0:
plt.show()
plt.pause(0.05)
# reset all visitors out of the range of LAS
move = 1
action = [move, -6, np.random.randint(-3,2), 0]
envVisitor.step(visitorName0, action)
envVisitor.step(visitorName1, action)
envVisitor.step(visitorName2, action)
envVisitor.step(visitorName3, action)
#time.sleep(0.01)
i += 1
except KeyboardInterrupt:
envVisitor.destroy()