-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcoverage_simple.py
More file actions
44 lines (32 loc) · 1.06 KB
/
coverage_simple.py
File metadata and controls
44 lines (32 loc) · 1.06 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
"""
A simple example of using the CoverageControl library
"""
import coverage_control as cc
from coverage_control.algorithms import ClairvoyantCVT as CoverageAlgorithm
# Algorithms available:
# ClairvoyantCVT
# CentralizedCVT
# DecentralizedCVT
# NearOptimalCVT
params = cc.Parameters()
# CoverageSystem handles the environment and robots
env = cc.CoverageSystem(params)
init_cost = env.GetObjectiveValue()
print(f"Initial Coverage cost: {init_cost:.2e}")
# Runs the coverage control algorithm
controller = CoverageAlgorithm(params, env)
for i in range(0, params.pEpisodeSteps):
# Compute actions to be taken by the robots
controller.ComputeActions()
# Get actions from the controller
actions = controller.GetActions()
# Send actions to the environment
if env.StepActions(actions):
print(f"Error in step {i}")
break
if controller.IsConverged():
print(f"Converged in step {i}")
break
# print some metrics
current_cost = env.GetObjectiveValue()
print(f"Improvement %: {100 * (init_cost - current_cost)/init_cost:.2f}")