-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_simulation.py
More file actions
70 lines (58 loc) · 1.97 KB
/
run_simulation.py
File metadata and controls
70 lines (58 loc) · 1.97 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
67
68
69
70
from simulators.rover_domain_simulator import RoverDomain
from teams.rover_team import RoverTeam
from policies.policy import RandomPolicy
from policies.policy import CCEA
from policies.policy import Evo_MLP
from rewards.g import GlobalReward
import yaml
import sys
def EvaluateTeam(team, domain, reward, steps):
for step in range(steps):
#print(domain)
# Get States from Rover Doman
joint_state = domain.get_jointstate()
# Get the actions from the team
actions = team.get_jointaction(joint_state)
# Pass actions to domain to update
domain.apply_actions(actions)
# Update the joint state
joint_state = domain.get_jointstate()
reward.record_history(joint_state)
# Compute the Global Reward
reward_G = reward.calculate_reward()
print("Reward: ", reward_G)
return team, domain, reward_G
def main():
"""
"""
# Read and store parameters from configuration file.
if len(sys.argv) is 1:
config_f = "config.yml"
else:
config_f = sys.argv[1]
with open(config_f, 'r') as f:
config = yaml.load(f)
# Initialize the rover domain.
domain = RoverDomain(
config["Seed"],
config["Initial POI Locations"],
config["Initial Agent Positions"],
config["Number of Agents"],
config["Number of POIs"],
config["World Width"],
config["World Length"])
agent_policies = {}
for i in range(config["Number of Agents"]):
agent_policies["agent_"+str(i)] = Evo_MLP(8, 2)
team = RoverTeam(agent_policies)
# Initialize the reward function
global_reward = GlobalReward(
config["Coupling"],
config["Observation Radius"],
config["Minimum Distance"])
for generation in range(config["Epochs"]):
team, domain, fitness = EvaluateTeam(team, domain, global_reward, config["Steps"])
# CCEA Evaluation
CCEA(team, fitness)
if __name__ == '__main__':
main()