Coverage Control Library
Loading...
Searching...
No Matches
coverage_algorithm.cpp
Go to the documentation of this file.
1
22// #include <CoverageControl/algorithms/centralized_cvt.h>
23// #include <CoverageControl/algorithms/decentralized_cvt.h>
24// #include <CoverageControl/algorithms/near_optimal_cvt.h>
25// #include <CoverageControl/algorithms/simul_explore_exploit.h>
26/* #include <CoverageControl/bivariate_normal_distribution.h> */
27
28#include <iostream>
29#include <memory>
30#include <string>
31
33/* typedef CoverageControl::CentralizedCVT CoverageAlgorithm; */
34/* typedef CoverageControl::DecentralizedCVT CoverageAlgorithm; */
35/* typedef CoverageControl::DecentralizedCVT CoverageAlgorithm; */
36/* typedef CoverageControl::NearOptimalCVT CoverageAlgorithm; */
37
43
44int main(int argc, char** argv) {
46 Parameters params;
47 /* params.pSensorSize = 16; */
48 if (argc >= 2) {
49 std::string parameter_file = argv[1];
50 params = Parameters(parameter_file);
51 }
52
53 std::unique_ptr<CoverageSystem> env;
54
55 if (argc == 3) {
56 std::cerr << "Please provide both position and IDF files" << std::endl;
57 std::cerr << "Usage: ./coverage_algorithm [parameter_file] "
58 "[<position_file> <idf_file>]"
59 << std::endl;
60 return 1;
61 } else if (argc == 4) {
62 std::string pos_file = argv[2];
63 std::string idf_file = argv[3];
64 WorldIDF world_idf(params, idf_file);
65 env = std::make_unique<CoverageSystem>(params, world_idf, pos_file);
66 } else {
67 env = std::make_unique<CoverageSystem>(params);
68 }
69
70 auto init_objective = env->GetObjectiveValue();
71 std::cout << "Initial objective: " << init_objective << std::endl;
72
73 CoverageAlgorithm algorithm(params, *env);
74 auto goals = algorithm.GetGoals();
75
76 for (int ii = 0; ii < params.pEpisodeSteps; ++ii) {
77 algorithm.ComputeActions();
78 auto actions = algorithm.GetActions();
79 if (env->StepActions(actions)) {
80 std::cout << "Invalid action" << std::endl;
81 break;
82 }
83 if (ii % 100 == 0) {
84 std::cout << "Step: " << ii << std::endl;
85 }
86 if (algorithm.IsConverged()) {
87 break;
88 }
89 }
90 auto final_objective = env->GetObjectiveValue();
91 std::cout << "Improvement %: "
92 << (init_objective - final_objective) / init_objective * 100
93 << std::endl;
94 return 0;
95}
Clairvoyant CVT algorithm.
The CoverageSystem class is the main class for the coverage control library.
static void SetUseCuda(bool use_cuda)
Definition cuda_utils.h:61
Class to store parameters.
Definition parameters.h:48
Class for Importance Density Function (IDF) for the world.
Definition world_idf.h:61
CoverageControl::ClairvoyantCVT CoverageAlgorithm
int main(int argc, char **argv)
The file contains the CoverageSystem class, which is the main class for the coverage control library.
std::vector< Point2 > PointVector
Definition typedefs.h:51
Eigen::Vector2d Point2
Definition typedefs.h:44
Contains parameters.
Contains typedefs for the library.
Contains the class for Importance Density Function (IDF) for the world.