Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
AgarwalSaurav committed Apr 25, 2024
1 parent 5634c25 commit 97748c7
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 341 deletions.
23 changes: 0 additions & 23 deletions cppsrc/main/coverage_algorithm.cpp
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
Expand Down
23 changes: 0 additions & 23 deletions cppsrc/main/world_idf.cpp
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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ repair-wheel-command = ""
# before-test=""
test-command = "pytest -ra --showlocals --ignore={project}/python/tests/deprecated {project}/python/tests/test_coverage_env_utils.py {project}/python/tests/test_coverage.py {project}/python/tests/test_env_io.py {project}/python/tests/test_map_generation.py {project}/python/tests/test_models.py {project}/python/tests/test_package.py {project}/python/tests/test_parameters.py {project}/python/tests/test_parity.py"

before-test = "pip install pytest torch torchvision torch_geometric && wget https://github.com/KumarRobotics/CoverageControl/releases/download/v1.1.0/pytest_data.tar.gz && tar -xvf pytest_data.tar.gz -C python/tests/ && rm pytest_data.tar.gz"
before-test = "pip install pytest torch torchvision torch_geometric && wget https://github.com/KumarRobotics/CoverageControl/releases/download/v1.2.0/pytest_data.tar.gz && tar -xvf pytest_data.tar.gz -C python/tests/ && rm pytest_data.tar.gz"
test-requires = []
test-extras = []

Expand Down
40 changes: 13 additions & 27 deletions python/scripts/coverage_env/coverage_class.py
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:
"""
Expand All @@ -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):
Expand All @@ -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:
Expand Down
26 changes: 3 additions & 23 deletions python/scripts/coverage_env/coverage_simple.py
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()

Expand All @@ -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
Expand Down
21 changes: 0 additions & 21 deletions python/scripts/coverage_env/world_idf.py
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
Expand Down
20 changes: 0 additions & 20 deletions python/scripts/coverage_env/world_map_numpy.py
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
"""
Expand Down
40 changes: 9 additions & 31 deletions python/scripts/data_generation/data_generation.py
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
#
Expand All @@ -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/"
Expand Down
Loading

0 comments on commit 97748c7

Please sign in to comment.