Skip to content

Commit fd33141

Browse files
author
Saurav Agarwal
committed
Avoid copy construction
1 parent 8af7b23 commit fd33141

File tree

7 files changed

+76
-15
lines changed

7 files changed

+76
-15
lines changed

cppsrc/core/include/CoverageControl/coverage_system.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ class CoverageSystem {
440440
void PlotInitMap(std::string const &, std::string const &) const;
441441
void PlotRobotLocalMap(std::string const &, int const &, int const &);
442442
void PlotRobotSystemMap(std::string const &, int const &, int const &);
443-
void PlotRobotIDFMap(std::string const &, int const &, int const &);
444443
void PlotRobotExplorationMap(std::string const &, int const &, int const &);
445444
void PlotRobotSensorView(std::string const &, int const &, int const &);
446445
void PlotRobotObstacleMap(std::string const &, int const &, int const &);

cppsrc/core/include/CoverageControl/robot_model.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ class RobotModel {
7575
MapType
7676
local_exploration_map_; //!< Binary map: true for unexplored locations
7777
MapType exploration_map_; //!< Binary map: true for unexplored locations
78-
std::shared_ptr<const WorldIDF>
79-
world_idf_; //!< Robots cannot change the world
78+
// std::shared_ptr<const WorldIDF>
79+
// world_idf_; //!< Robots cannot change the world
80+
const WorldIDF *world_idf_; //!< Robots cannot change the world
8081
double time_step_dist_ = 0;
8182
double sensor_area_ = 0;
8283

@@ -130,7 +131,8 @@ class RobotModel {
130131
RobotModel(Parameters const &params, Point2 const &global_start_position,
131132
WorldIDF const &world_idf)
132133
: params_{params}, global_start_position_{global_start_position} {
133-
world_idf_ = std::make_shared<const WorldIDF>(world_idf);
134+
world_idf_ = &world_idf;
135+
// world_idf_ = std::make_shared<const WorldIDF>(world_idf);
134136
normalization_factor_ = world_idf_->GetNormalizationFactor();
135137
global_current_position_ = global_start_position_;
136138

cppsrc/core/src/coverage_system.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ void CoverageSystem::PlotRobotSystemMap(std::string const &dir_name,
561561
plotter.PlotMap(GetRobotSystemMap(robot_id), neighbours_positions);
562562
}
563563

564-
void CoverageSystem::PlotRobotIDFMap(std::string const &dir_name,
564+
void CoverageSystem::PlotRobotLocalMap(std::string const &dir_name,
565565
int const &robot_id, int const &step) {
566566
Plotter plotter(dir_name, params_.pLocalMapSize * params_.pResolution,
567567
params_.pResolution);
@@ -587,14 +587,6 @@ void CoverageSystem::PlotRobotSensorView(std::string const &dir_name,
587587
plotter.PlotMap(GetRobotSensorView(robot_id));
588588
}
589589

590-
void CoverageSystem::PlotRobotLocalMap(std::string const &dir_name,
591-
int const &robot_id, int const &step) {
592-
Plotter plotter(dir_name, params_.pLocalMapSize * params_.pResolution,
593-
params_.pResolution);
594-
plotter.SetPlotName("robot_map_" + std::to_string(robot_id) + "_", step);
595-
plotter.PlotMap(GetRobotLocalMap(robot_id));
596-
}
597-
598590
void CoverageSystem::PlotRobotObstacleMap(std::string const &dir_name,
599591
int const &robot_id,
600592
int const &step) {

cppsrc/python_bindings/core_binds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ void pyCoverageControl_core_coverage_system(py::module &m) {
363363
PointVector const &>(
364364
&CoverageSystem::PlotMapVoronoi, py::const_))
365365
.def("PlotRobotLocalMap", &CoverageSystem::PlotRobotLocalMap)
366-
.def("PlotRobotIDFMap", &CoverageSystem::PlotRobotIDFMap)
366+
// .def("PlotRobotIDFMap", &CoverageSystem::PlotRobotIDFMap)
367367
.def("PlotRobotExplorationMap", &CoverageSystem::PlotRobotExplorationMap)
368368
.def("PlotRobotSensorView", &CoverageSystem::PlotRobotSensorView)
369369
.def("PlotRobotSystemMap", &CoverageSystem::PlotRobotSystemMap)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Generates large number of random environments
3+
"""
4+
5+
# @ file env_generator.py
6+
# @brief Generates large number of random environments
7+
8+
import os
9+
import pathlib
10+
import argparse
11+
12+
from coverage_control import Parameters
13+
from coverage_control import CoverageSystem
14+
from coverage_control import IOUtils
15+
16+
17+
def main(env_config_file: str, num_envs: int, env_dir: str):
18+
"""
19+
Generates large number of random environments
20+
"""
21+
22+
env_config_file = IOUtils.sanitize_path(env_config_file)
23+
cc_params = Parameters(env_config_file)
24+
25+
envs_path = pathlib.Path(IOUtils.sanitize_path(env_dir))
26+
27+
if not os.path.exists(envs_path):
28+
print(f"Creating directory {envs_path}")
29+
os.makedirs(envs_path)
30+
31+
for i in range(num_envs):
32+
pos_file = str(envs_path / f"{i:04}.pos")
33+
env_file = str(envs_path / f"{i:04}.env")
34+
cc_system = CoverageSystem(cc_params)
35+
cc_system.WriteEnvironment(pos_file, env_file)
36+
37+
38+
if __name__ == "__main__":
39+
parser = argparse.ArgumentParser(
40+
description="Generates large number of random environments"
41+
)
42+
parser.add_argument("config", type=str, help="Environment configuration file")
43+
parser.add_argument("num_envs", type=int, help="Number of environments to generate")
44+
parser.add_argument("env_dir", type=str, help="Directory to save the environments")
45+
args = parser.parse_args()
46+
47+
main(args.config, args.num_envs, args.env_dir)

python/utils/plot_costs_time.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,3 @@ def run_analysis(self):
108108
base_dir = sys.argv[1]
109109
analyzer = CostAnalyzer(base_dir)
110110
analyzer.run_analysis()
111-

python/utils/split_env.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Check if there are any .env files
4+
if [ -z "$(ls *.env 2>/dev/null)" ]; then
5+
echo "No .env files found in the current directory."
6+
exit 1
7+
fi
8+
9+
# Loop over all files ending in .env
10+
for file in *.env; do
11+
# Extract the base name of the file without the .env extension
12+
# This strips the last four characters, assuming they are '.env'
13+
base_name="${file%.*}"
14+
15+
# Split the file into parts, each with 16 lines
16+
if ! split -l 16 -d --additional-suffix=".env" "$file" "${base_name}_"; then
17+
echo "Failed to split file $file"
18+
continue # Skip to the next file on failure
19+
fi
20+
21+
echo "Successfully split $file into 16-line parts."
22+
done

0 commit comments

Comments
 (0)