Coverage Control Library
Loading...
Searching...
No Matches
near_optimal_cvt.h
Go to the documentation of this file.
1/*
2 * This file is part of the CoverageControl library
3 *
4 * Author: Saurav Agarwal
5 * Contact: sauravag@seas.upenn.edu, agr.saurav1@gmail.com
6 * Repository: https://github.com/KumarRobotics/CoverageControl
7 *
8 * Copyright (c) 2024, Saurav Agarwal
9 *
10 * The CoverageControl library is free software: you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or (at your
13 * option) any later version.
14 *
15 * The CoverageControl library is distributed in the hope that it will be
16 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18 * Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * CoverageControl library. If not, see <https://www.gnu.org/licenses/>.
22 */
23
33#ifndef CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ALGORITHMS_NEAR_OPTIMAL_CVT_H_
34#define CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ALGORITHMS_NEAR_OPTIMAL_CVT_H_
35
36#include <omp.h>
37
38#include <algorithm>
39#include <fstream>
40#include <iostream>
41#include <queue>
42#include <random>
43#include <set>
44#include <vector>
45
49#include "CoverageControl/extern/lsap/Hungarian.h"
53
54namespace CoverageControl {
55
68 private:
69 Parameters const params_;
70 size_t num_robots_ = 0;
71 CoverageSystem &env_;
72 Voronoi voronoi_;
73 PointVector robot_global_positions_;
74 PointVector goals_, actions_;
75
76 bool is_converged_ = false;
77
78 public:
79 NearOptimalCVT(Parameters const &params, CoverageSystem &env)
80 : NearOptimalCVT(params, params.pNumRobots, env) {}
81 NearOptimalCVT(Parameters const &params, size_t const &num_robots,
82 CoverageSystem &env)
83 : params_{params}, num_robots_{num_robots}, env_{env} {
84 robot_global_positions_ = env_.GetRobotPositions();
85 actions_.resize(num_robots_);
86 goals_ = robot_global_positions_;
87 ComputeGoals();
88 }
89
90 PointVector GetActions() { return actions_; }
91
92 auto GetGoals() { return goals_; }
93
94 auto &GetVoronoi() { return voronoi_; }
95
96 void ComputeGoals() {
97 goals_ = NearOptimalCVTAlgorithm(
98 params_.pLloydNumTries, params_.pLloydMaxIterations, num_robots_,
99 env_.GetWorldMap(), params_.pWorldMapSize, params_.pResolution,
100 robot_global_positions_, voronoi_);
101 }
102
104 is_converged_ = true;
105 robot_global_positions_ = env_.GetRobotPositions();
106 for (size_t iRobot = 0; iRobot < num_robots_; ++iRobot) {
107 actions_[iRobot] = Point2(0, 0);
108 Point2 diff = goals_[iRobot] - robot_global_positions_[iRobot];
109 double dist = diff.norm();
110 if (dist < kEps) {
111 continue;
112 }
113 double speed = dist / params_.pTimeStep;
114 speed = std::min(params_.pMaxRobotSpeed, speed);
115 Point2 direction(diff);
116 direction.normalize();
117 actions_[iRobot] = speed * direction;
118 is_converged_ = false;
119 }
120 return 0;
121 }
122
123 bool IsConverged() { return is_converged_; }
124};
125
126} /* namespace CoverageControl */
127#endif // CPPSRC_CORE_INCLUDE_COVERAGECONTROL_ALGORITHMS_NEAR_OPTIMAL_CVT_H_
Contains the abstract class for coverage control algorithms.
The CoverageSystem class is the main class for the coverage control library.
PointVector GetRobotPositions(bool force_no_noise=false)
Get the global positions of all robots.
const MapType & GetWorldMap() const
Get the world map.
Class to store parameters.
Definition parameters.h:50
double pTimeStep
Each time step corresponds to pTimeStep seconds.
Definition parameters.h:141
Class for computing Voronoi cells.
Definition voronoi.h:119
The file contains the CoverageSystem class, which is the main class for the coverage control library.
double const kEps
Definition constants.h:49
std::vector< Point2 > PointVector
Definition typedefs.h:51
Eigen::Vector2d Point2
Definition typedefs.h:44
Utility functions for transforming maps.
Namespace for the CoverageControl library.
Near Optimal Centroidal Voronoi Tessellation (CVT) algorithm Near-optimal Centroidal Voronoi Tessella...
Contains parameters.
Contains typedefs for the library.