1- # This file is part of the CoverageControl library
2- #
3- # Author: Saurav Agarwal
4- 5- # Repository: https://github.com/KumarRobotics/CoverageControl
6- #
7- # Copyright (c) 2024, Saurav Agarwal
8- #
9- # The CoverageControl library is free software: you can redistribute it and/or
10- # modify it under the terms of the GNU General Public License as published by
11- # the Free Software Foundation, either version 3 of the License, or (at your
12- # option) any later version.
13- #
14- # The CoverageControl library is distributed in the hope that it will be
15- # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17- # Public License for more details.
18- #
19- # You should have received a copy of the GNU General Public License along with
20- # CoverageControl library. If not, see <https://www.gnu.org/licenses/>.
21-
221"""
232An example class to use the CoverageControl library to run a coverage algorithm
243"""
4+
255import sys
26- import coverage_control as cc # Main library
27- from coverage_control import CoverageSystem
286
7+ import coverage_control as cc # Main library
8+ from coverage_control import CoverageSystem
9+ from coverage_control .algorithms import ClairvoyantCVT as CoverageAlgorithm
2910# Algorithms available:
3011# ClairvoyantCVT
3112# CentralizedCVT
3213# DecentralizedCVT
3314# NearOptimalCVT
34- from coverage_control . algorithms import ClairvoyantCVT as CoverageAlgorithm
15+
3516
3617class RunCoverageAlgorithm :
3718 """
@@ -45,15 +26,18 @@ def __init__(self, params_filename=None):
4526 self .params_ = cc .Parameters ()
4627
4728 self .env = CoverageSystem (self .params_ )
48- self .controller = CoverageAlgorithm (self .params_ , self .params_ .pNumRobots , self .env )
29+ self .controller = CoverageAlgorithm (
30+ self .params_ , self .params_ .pNumRobots , self .env
31+ )
4932
5033 def step (self ):
5134 """
5235 Run one step of the coverage algorithm
5336 """
54- self .controller .ComputeActions ();
37+ self .controller .ComputeActions ()
5538 actions = self .controller .GetActions ()
5639 error_flag = self .env .StepActions (actions )
40+
5741 return error_flag
5842
5943 def execute (self ):
@@ -68,19 +52,21 @@ def execute(self):
6852 while num_steps <= self .params_ .pEpisodeSteps :
6953 if self .step ():
7054 print (f"Error in step { num_steps } " )
55+
7156 break
7257
7358 if self .controller .IsConverged ():
7459 print (f"Converged in step { num_steps } " )
60+
7561 break
7662
7763 num_steps = num_steps + 1
7864
7965 final_cost = self .env .GetObjectiveValue ()
8066 print (f"Improvement %: { 100 * (init_cost - final_cost )/ init_cost :.2f} " )
8167
82- if __name__ == '__main__' :
8368
69+ if __name__ == "__main__" :
8470 if len (sys .argv ) > 1 :
8571 cc = RunCoverageAlgorithm (sys .argv [1 ])
8672 else :
0 commit comments