-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5634c25
commit 97748c7
Showing
13 changed files
with
202 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,3 @@ | ||
/* | ||
* This file is part of the CoverageControl library | ||
* | ||
* Author: Saurav Agarwal | ||
* Contact: [email protected], [email protected] | ||
* Repository: https://github.com/KumarRobotics/CoverageControl | ||
* | ||
* Copyright (c) 2024, Saurav Agarwal | ||
* | ||
* The CoverageControl library is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* The CoverageControl library is distributed in the hope that it will be | ||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* CoverageControl library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/*! | ||
* \file coverage_algorithm.cpp | ||
* \brief Program to test the CVT-based (Lloyd's) coverage control algorithms | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,3 @@ | ||
/* | ||
* This file is part of the CoverageControl library | ||
* | ||
* Author: Saurav Agarwal | ||
* Contact: [email protected], [email protected] | ||
* Repository: https://github.com/KumarRobotics/CoverageControl | ||
* | ||
* Copyright (c) 2024, Saurav Agarwal | ||
* | ||
* The CoverageControl library is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* The CoverageControl library is distributed in the hope that it will be | ||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* CoverageControl library. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/*! | ||
* \file world_idf.cpp | ||
* \brief Program to test generation of IDF | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,18 @@ | ||
# This file is part of the CoverageControl library | ||
# | ||
# Author: Saurav Agarwal | ||
# Contact: [email protected], [email protected] | ||
# Repository: https://github.com/KumarRobotics/CoverageControl | ||
# | ||
# Copyright (c) 2024, Saurav Agarwal | ||
# | ||
# The CoverageControl library is free software: you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or (at your | ||
# option) any later version. | ||
# | ||
# The CoverageControl library is distributed in the hope that it will be | ||
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# CoverageControl library. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
""" | ||
An example class to use the CoverageControl library to run a coverage algorithm | ||
""" | ||
|
||
import sys | ||
import coverage_control as cc # Main library | ||
from coverage_control import CoverageSystem | ||
|
||
import coverage_control as cc # Main library | ||
from coverage_control import CoverageSystem | ||
from coverage_control.algorithms import ClairvoyantCVT as CoverageAlgorithm | ||
# Algorithms available: | ||
# ClairvoyantCVT | ||
# CentralizedCVT | ||
# DecentralizedCVT | ||
# NearOptimalCVT | ||
from coverage_control.algorithms import ClairvoyantCVT as CoverageAlgorithm | ||
|
||
|
||
class RunCoverageAlgorithm: | ||
""" | ||
|
@@ -45,15 +26,18 @@ def __init__(self, params_filename=None): | |
self.params_ = cc.Parameters() | ||
|
||
self.env = CoverageSystem(self.params_) | ||
self.controller = CoverageAlgorithm(self.params_, self.params_.pNumRobots, self.env) | ||
self.controller = CoverageAlgorithm( | ||
self.params_, self.params_.pNumRobots, self.env | ||
) | ||
|
||
def step(self): | ||
""" | ||
Run one step of the coverage algorithm | ||
""" | ||
self.controller.ComputeActions(); | ||
self.controller.ComputeActions() | ||
actions = self.controller.GetActions() | ||
error_flag = self.env.StepActions(actions) | ||
|
||
return error_flag | ||
|
||
def execute(self): | ||
|
@@ -68,19 +52,21 @@ def execute(self): | |
while num_steps <= self.params_.pEpisodeSteps: | ||
if self.step(): | ||
print(f"Error in step {num_steps}") | ||
|
||
break | ||
|
||
if self.controller.IsConverged(): | ||
print(f"Converged in step {num_steps}") | ||
|
||
break | ||
|
||
num_steps = num_steps + 1 | ||
|
||
final_cost = self.env.GetObjectiveValue() | ||
print(f"Improvement %: {100 * (init_cost - final_cost)/init_cost:.2f}") | ||
|
||
if __name__ == '__main__': | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) > 1: | ||
cc = RunCoverageAlgorithm(sys.argv[1]) | ||
else: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,14 @@ | ||
# This file is part of the CoverageControl library | ||
# | ||
# Author: Saurav Agarwal | ||
# Contact: [email protected], [email protected] | ||
# Repository: https://github.com/KumarRobotics/CoverageControl | ||
# | ||
# Copyright (c) 2024, Saurav Agarwal | ||
# | ||
# The CoverageControl library is free software: you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or (at your | ||
# option) any later version. | ||
# | ||
# The CoverageControl library is distributed in the hope that it will be | ||
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# CoverageControl library. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
""" | ||
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 | ||
from coverage_control.algorithms import ClairvoyantCVT as CoverageAlgorithm | ||
|
||
params = cc.Parameters() | ||
|
||
|
@@ -53,10 +31,12 @@ | |
|
||
if env.StepActions(actions): | ||
print(f"Error in step {i}") | ||
|
||
break | ||
|
||
if controller.IsConverged(): | ||
print(f"Converged in step {i}") | ||
|
||
break | ||
|
||
# print some metrics | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,8 @@ | ||
# This file is part of the CoverageControl library | ||
# | ||
# Author: Saurav Agarwal | ||
# Contact: [email protected], [email protected] | ||
# Repository: https://github.com/KumarRobotics/CoverageControl | ||
# | ||
# Copyright (c) 2024, Saurav Agarwal | ||
# | ||
# The CoverageControl library is free software: you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or (at your | ||
# option) any later version. | ||
# | ||
# The CoverageControl library is distributed in the hope that it will be | ||
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# CoverageControl library. If not, see <https://www.gnu.org/licenses/>. | ||
""" | ||
A simple example of using WorldIDF | ||
""" | ||
|
||
import coverage_control | ||
import numpy as np | ||
|
||
params = coverage_control.Parameters() | ||
params.pNumRobots = 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,3 @@ | ||
# This file is part of the CoverageControl library | ||
# | ||
# Author: Saurav Agarwal | ||
# Contact: [email protected], [email protected] | ||
# Repository: https://github.com/KumarRobotics/CoverageControl | ||
# | ||
# Copyright (c) 2024, Saurav Agarwal | ||
# | ||
# The CoverageControl library is free software: you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or (at your | ||
# option) any later version. | ||
# | ||
# The CoverageControl library is distributed in the hope that it will be | ||
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# CoverageControl library. If not, see <https://www.gnu.org/licenses/>. | ||
""" | ||
A simple example of using WorldIDF | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,6 @@ | ||
# This file is part of the CoverageControl library | ||
# | ||
# Author: Saurav Agarwal | ||
# Contact: [email protected], [email protected] | ||
# Repository: https://github.com/KumarRobotics/CoverageControl | ||
# | ||
# Copyright (c) 2024, Saurav Agarwal | ||
# | ||
# The CoverageControl library is free software: you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or (at your | ||
# option) any later version. | ||
# | ||
# The CoverageControl library is distributed in the hope that it will be | ||
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# CoverageControl library. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
# @file data_generation.py | ||
# This file contains the code to generate a dataset for learning | ||
# | ||
|
||
# DataDir = "${CoverageControl_ws}/datasets/lpac" # Absolute location | ||
# EnvironmentConfig = "${CoverageControl_ws}/datasets/lpac/coverage_control_params.toml" # Absolute location | ||
# | ||
|
@@ -48,30 +26,30 @@ | |
# TrainRatio = 0.7 | ||
# ValRatio = 0.2 | ||
# TestRatio = 0.1 | ||
|
||
## @file data_generation.py | ||
# @file data_generation.py | ||
# @brief Class to generate CoverageControl dataset for LPAC architecture | ||
|
||
import os | ||
import sys | ||
import pathlib | ||
import datetime | ||
import math | ||
import os | ||
import pathlib | ||
import sys | ||
|
||
import coverage_control | ||
import torch | ||
from coverage_control import CoverageSystem, IOUtils | ||
from coverage_control import CoverageSystem | ||
from coverage_control import IOUtils | ||
from coverage_control.algorithms import ClairvoyantCVT as CoverageAlgorithm | ||
from coverage_control.nn import CoverageEnvUtils | ||
|
||
## @ingroup python_api | ||
# @ingroup python_api | ||
|
||
|
||
class DatasetGenerator: | ||
""" | ||
Class to generate CoverageControl dataset for LPAC architecture | ||
""" | ||
|
||
def __init__(self, config_file, append_dir=None): | ||
|
||
self.config = IOUtils.load_toml(config_file) | ||
self.data_dir = IOUtils.sanitize_path(self.config["DataDir"]) | ||
self.dataset_dir = self.data_dir + "/data/" | ||
|
Oops, something went wrong.