-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgym_example.py
More file actions
66 lines (45 loc) · 1.89 KB
/
gym_example.py
File metadata and controls
66 lines (45 loc) · 1.89 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
"""
An example using the rover domain gym-style interface and the standard, included CCEA learning algorithms.
This is a minimal example, showing the minimal Gym interface.
"""
from rover_domain_core_gym import RoverDomainGym
import code.ccea_2 as ccea
import code.agent_domain_2 as domain
import mods
episodeCount = 1000 # Number of learning episodes
sim = RoverDomainGym()
#mods.sequentialPoi(sim)
mods.recipePoi(sim)
#mods.lowVisibility(sim)
obs=sim.reset()
sim.data["Coupling"]=3
obs_size=len(obs[0])
print(obs_size)
ccea.initCcea(input_shape=obs_size, num_outputs=2, num_units=32)(sim.data)
for episodeIndex in range(episodeCount):
sim.data["Episode Index"] = episodeIndex
populationSize=len(sim.data['Agent Populations'][0])
GlobalRewards=[0.0]
for worldIndex in range(populationSize):
sim.data["World Index"]=worldIndex
obs = sim.reset()
#ccea.assignCceaPolicies(sim.data)
mods.assignHomogeneousPolicy(sim)
done = False
stepCount = 0
while not done:
#mods.poiVelocity(sim)
# Select actions and create the joint action from the simulation data
# Note that this specific function extracts "obs" from the data structure directly, which is why obs is not
# directly used in this example.
domain.doAgentProcess(sim.data)
#mods.abilityVariation(sim)
jointAction = sim.data["Agent Actions"]
obs, reward, done, info = sim.step(jointAction)
stepCount += 1
if ( episodeIndex%50==49 and worldIndex==0):
sim.render()
GlobalRewards.append(sim.data["Global Reward"])
ccea.rewardCceaPolicies(sim.data)
ccea.evolveCceaPolicies(sim.data)
print(episodeIndex,max(GlobalRewards))