Skip to content

Commit 23611cf

Browse files
Saurav AgarwalSaurav Agarwal
authored andcommitted
Linting and Parity
1 parent 287edc0 commit 23611cf

34 files changed

+363
-285
lines changed

cppsrc/core/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ FetchContent_Declare(CMakeExtraUtils
77
FetchContent_MakeAvailable(CMakeExtraUtils)
88

99
include(DynamicVersion)
10-
dynamic_version(PROJECT_PREFIX "CoverageControl_" GIT_ARCHIVAL_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../../.git_archival.txt")
10+
dynamic_version(PROJECT_PREFIX "CoverageControl_" GIT_ARCHIVAL_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../../.git_archival.txt"
11+
FALLBACK_VERSION 0.0.1)
1112

1213
project(CoverageControl VERSION ${PROJECT_VERSION} LANGUAGES CXX)
1314

cppsrc/core/include/CoverageControl/algorithms/abstract_controller.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#ifndef CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ALGORITHMS_ABSTRACT_CONTROLLER_H_
3030
#define CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ALGORITHMS_ABSTRACT_CONTROLLER_H_
3131

32-
#include "CoverageControl/typedefs.h"
33-
#include "CoverageControl/parameters.h"
3432
#include "CoverageControl/coverage_system.h"
33+
#include "CoverageControl/parameters.h"
34+
#include "CoverageControl/typedefs.h"
3535

3636
namespace CoverageControl {
3737

cppsrc/core/include/CoverageControl/algorithms/near_optimal_cvt.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ namespace CoverageControl {
5959
* \class NearOptimalCVT
6060
* @}
6161
* The algorithm has knowledge of the entire map in a centralized manner.
62-
* It runs several trials; for each trial, it generates random initial positions for the sites.
63-
* Then uses the CVT to compute optimal centroids.
64-
* It performs the Hungarian algorithm to assign robots to the centroids.
65-
* Finally, the trial with the minimum cost is selected.
62+
* It runs several trials; for each trial, it generates random initial positions
63+
*for the sites. Then uses the CVT to compute optimal centroids. It performs the
64+
*Hungarian algorithm to assign robots to the centroids. Finally, the trial with
65+
*the minimum cost is selected.
6666
**/
6767
class NearOptimalCVT : public AbstractController {
6868
private:

cppsrc/core/include/CoverageControl/bivariate_normal_distribution.h

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,27 @@ class BivariateNormalDistribution {
139139
Point2 TransformPoint(Point2 const &in_point) const {
140140
if (is_circular_) {
141141
return Point2((in_point - mean_) / sigma_.x());
142-
} else {
143-
Point2 translated = in_point - mean_;
144-
Point2 normalized(translated.x() / sigma_.x(),
145-
translated.y() / sigma_.y());
146-
return Point2((normalized.x() - rho_ * normalized.y()) /
147-
(std::sqrt(1 - rho_ * rho_)),
148-
normalized.y());
149142
}
143+
Point2 translated = in_point - mean_;
144+
Point2 normalized(translated.x() / sigma_.x(), translated.y() / sigma_.y());
145+
return Point2(
146+
(normalized.x() - rho_ * normalized.y()) / (std::sqrt(1 - rho_ * rho_)),
147+
normalized.y());
148+
}
149+
150+
Point2f TransformPoint(Point2f const &in_point_f) const {
151+
Point2f mean_f = mean_.cast<float>();
152+
Point2f sigma_f = sigma_.cast<float>();
153+
float rho_f = static_cast<float>(rho_);
154+
if (is_circular_ or std::abs(rho_f) < kEpsf) {
155+
return Point2f((in_point_f - mean_f) / sigma_f.x());
156+
}
157+
Point2f translated = in_point_f - mean_f;
158+
Point2f normalized(translated.x() / sigma_f.x(),
159+
translated.y() / sigma_f.y());
160+
return Point2f(
161+
(normalized.x() - rho_f * normalized.y()) / (sqrt(1 - rho_f * rho_f)),
162+
normalized.y());
150163
}
151164

152165
/*!
@@ -158,18 +171,16 @@ class BivariateNormalDistribution {
158171
* @return Value of the integral
159172
*/
160173
double IntegrateQuarterPlane(Point2 const &point) const {
161-
auto transformed_point = TransformPoint(point);
174+
Point2 transformed_point = TransformPoint(point);
162175
return scale_ * std::erfc(transformed_point.x() * kOneBySqrt2) *
163176
std::erfc(transformed_point.y() * kOneBySqrt2) / 4.;
164177
}
165178

166-
float IntegrateQuarterPlaneF(Point2 const &point) const {
167-
auto transformed_point = TransformPoint(point);
168-
float x = static_cast<float>(transformed_point.x());
169-
float y = static_cast<float>(transformed_point.y());
170-
float scale = static_cast<float>(scale_);
171-
return scale * std::erfc(x * kOneBySqrt2f) * std::erfc(y * kOneBySqrt2f) /
172-
4.f;
179+
float IntegrateQuarterPlane(Point2f const &point) const {
180+
float scale_f = static_cast<float>(scale_);
181+
Point2f transformed_point = TransformPoint(point);
182+
return scale_f * std::erfc(transformed_point.x() * kOneBySqrt2f) *
183+
std::erfc(transformed_point.y() * kOneBySqrt2f) / 4.f;
173184
}
174185
};
175186

cppsrc/core/include/CoverageControl/constants.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ namespace CoverageControl {
4747
*/
4848

4949
double const kEps = 1e-10; /*!< Epsilon for double comparison */
50+
float const kEpsf = 1e-6f; /*!< Epsilon for float comparison */
5051
double const kLargeEps = 1e-4; /*!< Large epsilon for double comparison */
5152
double const kSqrt2 = std::sqrt(2); /*!< Square root of 2 */
5253
double const kOneBySqrt2 = 1. / std::sqrt(2); /*!< 1 by square root of 2 */
53-
float const kOneBySqrt2f = 1.f / std::sqrt(2.f); /*!< 1 by square root of 2 */
54+
float const kOneBySqrt2f = 1.f / sqrtf(2.f); /*!< 1 by square root of 2 */
5455
double const kInfD =
5556
std::numeric_limits<double>::infinity(); /*!< Infinity for double */
5657
constexpr auto kMaxPrecision{std::numeric_limits<long double>::digits10 +

cppsrc/core/include/CoverageControl/coverage_system.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <fstream>
3939
#include <iostream>
4040
#include <list>
41-
/* #include <mutex> */
41+
#include <mutex>
4242
#include <random>
4343
#include <string>
4444
#include <utility>
@@ -78,7 +78,7 @@ class CoverageSystem {
7878
mutable std::random_device
7979
rd_; //!< Random device for random number generation
8080
mutable std::mt19937 gen_; //!< Mersenne Twister random number generator
81-
/* mutable std::mutex mutex_; */
81+
mutable std::mutex mutex_;
8282
std::uniform_real_distribution<>
8383
distrib_pts_; //!< Uniform distribution for generating random points
8484
PointVector robot_global_positions_; //!< Global positions of the robots
@@ -95,8 +95,6 @@ class CoverageSystem {
9595
0; //!< Weighted ratio of explored locations
9696
double total_idf_weight_ = 0; //!< Total weight of the world IDF
9797
std::vector<PlotterData> plotter_data_; //!< Stores data for plotting
98-
std::vector<std::vector<int>>
99-
adjacency_matrix_; //!< Adjacency matrix for communication
10098
std::vector<std::vector<Point2>>
10199
relative_positions_neighbors_; //!< Relative positions of neighboring
102100
//!< robots for each robot
@@ -108,6 +106,7 @@ class CoverageSystem {
108106

109107
//! Update the exploration map, explored IDF map, and system map
110108
void UpdateSystemMap() {
109+
// This is not necessarily thread safe. Do NOT parallelize this for loop
111110
for (size_t i = 0; i < num_robots_; ++i) {
112111
MapUtils::MapBounds index, offset;
113112
MapUtils::ComputeOffsets(params_.pResolution, robot_global_positions_[i],

cppsrc/core/include/CoverageControl/cuda_utils.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
#include <iostream>
3333
#include <limits>
3434
#include <sstream>
35-
#include <vector>
3635
#include <string>
36+
#include <vector>
3737

3838
#include "CoverageControl/Config.h"
3939
namespace CoverageControl {
@@ -57,11 +57,6 @@ class CudaUtils {
5757
*/
5858
CudaUtils() = delete;
5959

60-
/*!
61-
* Destructor deleted as we don't want to create an instance of this class
62-
*/
63-
~CudaUtils() = delete;
64-
6560
static bool UseCuda() { return use_cuda_; }
6661

6762
static void SetUseCuda(bool use_cuda) { use_cuda_ = use_cuda; }

cppsrc/core/include/CoverageControl/plotter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#include <filesystem>
3434
#include <iostream>
3535
#include <list>
36-
#include <vector>
3736
#include <string>
37+
#include <vector>
3838

3939
#include "CoverageControl/typedefs.h"
4040
#include "CoverageControl/voronoi.h"

cppsrc/core/include/CoverageControl/robot_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
#ifndef CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ROBOT_MODEL_H_
3434
#define CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ROBOT_MODEL_H_
3535

36+
#include <algorithm>
3637
#include <cmath>
3738
#include <iostream>
3839
#include <memory>
39-
#include <algorithm>
4040
#include <vector>
4141

4242
#include "CoverageControl/constants.h"

cppsrc/core/include/CoverageControl/typedefs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ namespace CoverageControl {
4141
* @{
4242
*/
4343

44-
typedef Eigen::Vector2d Point2; /*!< Point2 is a 2D vector of doubles */
45-
typedef Eigen::Vector3d Point3; /*!< Point3 is a 3D vector of doubles */
44+
typedef Eigen::Vector2d Point2; /*!< Point2 is a 2D vector of doubles */
45+
typedef Eigen::Vector2f Point2f; /*!< Point2 is a 2D vector of doubles */
46+
typedef Eigen::Vector3d Point3; /*!< Point3 is a 3D vector of doubles */
4647
typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
4748
MapType; /*!< MapType is a 2D matrix of floats. Note: It is RowMajor */
4849

0 commit comments

Comments
 (0)