Skip to content

Commit 66618b1

Browse files
committed
Integrate GLKH-Solver
1 parent 49d80cb commit 66618b1

33 files changed

+491
-537
lines changed

install/prepare-jenkins-slave.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ ROS_VERSION=`rosversion -d`
44
echo "ROS version: ${ROS_VERSION}"
55

66
# Build dependencies.
7-
sudo apt-get install -y python-wstool python-catkin-tools
7+
sudo apt-get install -y python3-wstool python3-catkin-tools
88

99
# Package dependencies.
1010
echo "Installing MAV_COMM dependencies."
1111
sudo apt-get install -y ros-${ROS_VERSION}-mav-msgs
1212
echo "Installing CGAL dependencies."
1313
sudo apt-get install -y libgmp-dev libmpfr-dev
14-
echo "Installing MONO dependencies."
15-
sudo apt-get install -y mono-devel
1614
echo "Installig GLOG dependencices."
1715
sudo apt-get install -y libgoogle-glog-dev

polygon_coverage_planners/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ set(CMAKE_CXX_STANDARD 17)
1212
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
1313
set(CMAKE_BUILD_TYPE Release)
1414

15-
# TODO(rikba): Make catkin package.
16-
find_package(PkgConfig)
17-
pkg_check_modules(MONO mono-2 REQUIRED)
18-
include_directories(${MONO_INCLUDE_DIRS})
19-
2015
#############
2116
# LIBRARIES #
2217
#############

polygon_coverage_planners/src/graphs/sweep_plan_graph.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <polygon_coverage_geometry/tcd.h>
3131
#include <polygon_coverage_geometry/visibility_polygon.h>
3232

33-
#include <polygon_coverage_solvers/gk_ma.h>
33+
#include <polygon_coverage_solvers/glkh.h>
3434

3535
#include <CGAL/Boolean_set_operations_2.h>
3636
#include <CGAL/create_offset_polygons_from_polygon_with_holes_2.h>
@@ -522,20 +522,20 @@ bool SweepPlanGraph::solve(const Point_2& start, const Point_2& goal,
522522
const size_t goal_idx = temp_gtsp_graph.size() - 1;
523523
const size_t start_idx = temp_gtsp_graph.size() - 2;
524524

525-
// Solve using GK MA.
525+
// Solve using GLKH.
526526
std::vector<std::vector<int>> m = temp_gtsp_graph.getAdjacencyMatrix();
527527
std::vector<std::vector<int>> clusters;
528528
if (!temp_gtsp_graph.getClusters(&clusters)) {
529529
ROS_ERROR("Cannot get clusters.");
530530
return false;
531531
}
532-
gk_ma::Task task(m, clusters);
533-
gk_ma::GkMa& solver = gk_ma::GkMa::getInstance();
532+
glkh::Task task(m, clusters);
533+
glkh::Glkh& solver = glkh::Glkh::getInstance();
534534
solver.setSolver(task);
535535

536536
ROS_INFO("Start solving GTSP");
537537
if (!solver.solve()) {
538-
ROS_ERROR("GkMa solution failed.");
538+
ROS_ERROR("GLKH solution failed.");
539539
return false;
540540
}
541541
ROS_INFO("Finished solving GTSP");

polygon_coverage_planners/src/planners/polygon_stripmap_planner.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ bool PolygonStripmapPlanner::runSolver(const Point_2& start,
9999
std::vector<Point_2>* solution) const {
100100
ROS_ASSERT(solution);
101101

102-
ROS_INFO("Start solving GTSP using GK MA.");
102+
ROS_INFO("Start solving GTSP using GLKH.");
103103
return sweep_plan_graph_.solve(start, goal, solution);
104104
}
105105

polygon_coverage_solvers/CMakeLists.txt

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,18 @@ set(CMAKE_CXX_STANDARD 17)
88

99
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
1010

11-
# Add mono to invoke gk_ma.
12-
find_package(PkgConfig)
13-
pkg_check_modules(MONO mono-2 REQUIRED)
14-
include_directories(${MONO_INCLUDE_DIRS})
15-
16-
# Download gk_ma
17-
set(GKMA_INCLUDE_DIR ${CMAKE_BINARY_DIR}/gk_ma-prefix/src/gk_ma)
11+
# Download glkh
1812
include(ExternalProject)
1913
ExternalProject_Add(
20-
gk_ma
21-
URL http://www.cs.nott.ac.uk/~pszdk/gtsp_ma_source_codes.zip
22-
URL https://polybox.ethz.ch/index.php/s/H4NXeaNPWo6VBrf/download
23-
DOWNLOAD_NAME gtsp_ma_source_codes.zip
24-
URL_MD5 765fad8e3746fa3dd9b81be0afb34d35
25-
PATCH_COMMAND \\
26-
patch GkMa/OurHeuristic/Algorithm.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/Algorithm.patch && \\
27-
patch NativeHelper/ClusterOptimisation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/patches/ClusterOptimisationCpp.patch && \\
28-
patch GkMa/OurHeuristic/Types/Generation.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/Generation.patch && \\
29-
patch GkMa/OurHeuristic/GeneticAlgorithm.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/GeneticAlgorithm.patch && \\
30-
patch GkMa/Helper.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/Helper.patch && \\
31-
patch NativeHelper/ClusterOptimisation.h ${CMAKE_CURRENT_SOURCE_DIR}/patches/ClusterOptimisationH.patch && \\
32-
patch NativeHelper/ImprovementManager.h ${CMAKE_CURRENT_SOURCE_DIR}/patches/ImprovementManagerH.patch && \\
33-
patch NativeHelper/Insert.cpp ${CMAKE_CURRENT_SOURCE_DIR}/patches/InsertCpp.patch && \\
34-
patch NativeHelper/Insert.h ${CMAKE_CURRENT_SOURCE_DIR}/patches/InsertH.patch && \\
35-
patch NativeHelper/NativeHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/patches/NativeHelperCpp.patch && \\
36-
patch NativeHelper/Swap.cpp ${CMAKE_CURRENT_SOURCE_DIR}/patches/SwapCpp.patch && \\
37-
patch NativeHelper/NativeHelper.h ${CMAKE_CURRENT_SOURCE_DIR}/patches/NativeHelperH.patch && \\
38-
patch GkMa/OurHeuristic/NativeHelper.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/NativeHelper.patch && \\
39-
patch GkMa/OurSolver.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/OurSolver.patch && \\
40-
patch GkMa/OurHeuristic/Types/Permutation.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/Permutation.patch && \\
41-
patch GkMa/Program.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/Program.patch && \\
42-
patch GkMa/Solver.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/Solver.patch && \\
43-
patch GkMa/Loader/Task.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/Task.patch && \\
44-
patch GkMa/OurHeuristic/Types/Tour.cs ${CMAKE_CURRENT_SOURCE_DIR}/patches/Tour.patch
45-
UPDATE_COMMAND ""
46-
CONFIGURE_COMMAND \\
47-
cp ${PROJECT_SOURCE_DIR}/patches/MakefileCpp ./MakefileCpp && \\
48-
cp ${PROJECT_SOURCE_DIR}/patches/MakefileCs ./MakefileCs
49-
BUILD_COMMAND \\
50-
$(MAKE) -f MakefileCs BUILD_PATH="${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" \\
51-
COMMAND $(MAKE) -f MakefileCpp BUILD_PATH="${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
52-
INSTALL_COMMAND \\
53-
COMMAND ${CMAKE_COMMAND} -E create_symlink /usr/lib/libmono-native.so ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/System.Native
14+
glkh
15+
URL http://webhotel4.ruc.dk/~keld/research/GLKH/GLKH-1.0.tgz
16+
DOWNLOAD_NAME glkh_source_codes.tgz
17+
URL_MD5 9b0ba92053dac798f550c5c8a9524120
18+
BINARY_DIR ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_BIN_DESTINATION}
19+
PATCH_COMMAND
20+
COMMAND patch --forward ./SRC/SolveTSP.c < ${PROJECT_SOURCE_DIR}/patches/SolveTSP.patch
21+
COMMAND cp ${PROJECT_SOURCE_DIR}/patches/CMakeLists.txt ./
22+
INSTALL_COMMAND ""
5423
)
5524

5625
# Download GTSP test instances.
@@ -71,30 +40,32 @@ ExternalProject_Add(
7140
# LIBRARIES #
7241
#############
7342
cs_add_library(${PROJECT_NAME}
74-
src/gk_ma.cc
43+
src/glkh.cc
7544
src/combinatorics.cc
7645
src/boolean_lattice.cc
7746
)
78-
target_link_libraries(${PROJECT_NAME} ${MONO_LIBRARIES})
7947

8048
#########
8149
# TESTS #
8250
#########
8351
catkin_add_gtest(test_combinatorics
8452
test/combinatorics-test.cpp
8553
)
86-
target_link_libraries(test_combinatorics
87-
${PROJECT_NAME})
54+
target_link_libraries(test_combinatorics ${PROJECT_NAME})
8855

89-
catkin_add_gtest(test_gk_ma
90-
test/gk_ma-test.cpp
56+
catkin_add_gtest(test_glkh
57+
test/glkh-test.cpp
9158
)
92-
target_link_libraries(test_gk_ma
93-
${PROJECT_NAME})
59+
target_link_libraries(test_glkh ${PROJECT_NAME})
9460

9561

9662
##########
9763
# EXPORT #
9864
##########
65+
install(DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_BIN_DESTINATION}/
66+
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
67+
)
68+
9969
cs_install()
70+
cs_install_scripts(scripts/run_glkh.bash)
10071
cs_export()

polygon_coverage_solvers/include/polygon_coverage_solvers/gk_ma.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include <string>
2424
#include <vector>
2525

26-
#include <mono/metadata/object.h>
27-
2826
// Interfaces with the GK MA GTSP solver.
2927
namespace polygon_coverage_planning {
3028
namespace gk_ma {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* polygon_coverage_planning implements algorithms for coverage planning in
3+
* general polygons with holes. Copyright (C) 2019, Rik Bähnemann, Autonomous
4+
* Systems Lab, ETH Zürich
5+
*
6+
* This program is free software: you can redistribute it and/or modify it under
7+
* the terms of the GNU General Public License as published by the Free Software
8+
* Foundation, either version 3 of the License, or (at your option) any later
9+
* version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef POLYGON_COVERAGE_SOLVERS_GLKH_H_
21+
#define POLYGON_COVERAGE_SOLVERS_GLKH_H_
22+
23+
#include <string>
24+
#include <vector>
25+
26+
// Interfaces with the GLKH GTSP solver.
27+
namespace polygon_coverage_planning {
28+
namespace glkh {
29+
struct Task {
30+
Task(const std::vector<std::vector<int>>& m,
31+
const std::vector<std::vector<int>>& clusters)
32+
: m(m), clusters(clusters) {}
33+
bool mIsSymmetric() const;
34+
bool mIsSquare() const;
35+
std::vector<std::vector<int>> m;
36+
std::vector<std::vector<int>> clusters;
37+
};
38+
39+
// References GLKH. Singleton, because it may only be referenced once during
40+
// runtime.
41+
// https://stackoverflow.com/questions/1008019/c-singleton-design-pattern
42+
class Glkh {
43+
public:
44+
inline static Glkh& getInstance() {
45+
static Glkh instance;
46+
return instance;
47+
}
48+
Glkh(Glkh const&) = delete;
49+
void operator=(Glkh const&) = delete;
50+
51+
void setSolver(const std::string& file, bool binary);
52+
void setSolver(const Task& task);
53+
bool solve();
54+
inline std::vector<int> getSolution() const { return solution_; }
55+
56+
private:
57+
Glkh();
58+
~Glkh() = default;
59+
60+
std::vector<int> solution_;
61+
};
62+
} // namespace glkh
63+
} // namespace polygon_coverage_planning
64+
65+
#endif // POLYGON_COVERAGE_SOLVERS_GLKH_H_

polygon_coverage_solvers/patches/Algorithm.patch

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)