Skip to content

Commit

Permalink
Switch to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
fontanf committed Apr 24, 2024
1 parent ab0d907 commit 7313ddc
Show file tree
Hide file tree
Showing 70 changed files with 346 additions and 579 deletions.
10 changes: 0 additions & 10 deletions .bazelrc

This file was deleted.

10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8"]

env:
STABLE_DATA: ${{ github.workspace }}/data/

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -25,7 +28,10 @@ jobs:
python3 -m pip install gdown
python3 scripts/download_data.py
- name: Build
run: bazel build -- //...
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release --parallel
cmake --install build --config Release --prefix install
- name: Run tests
run: python3 -u scripts/run_tests.py test_results
- name: Checkout main branch
Expand All @@ -38,4 +44,4 @@ jobs:
- name: Run tests
run: python3 -u scripts/run_tests.py test_results_ref
- name: Process tests
run: python3 ./bazel-stablesolver/external/optimizationtools/scripts/process_tests.py --ref test_results_ref --new test_results
run: python3 -u ./build/_deps/optimizationtools-src/scripts/process_tests.py --ref test_results_ref --new test_results
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.15.0)

project(StableSolver LANGUAGES CXX)

option(STABLESOLVER_USE_CBC "Use CPLEX" ON)
option(STABLESOLVER_USE_CPLEX "Use CPLEX" OFF)

# Require C++11.
set(CMAKE_CXX_STANDARD 11)

# Enable output of compile commands during generation.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Set MSVC_RUNTIME_LIBRARY.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

# Add sub-directories.
add_subdirectory(extern)
add_subdirectory(src)
add_subdirectory(test)
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ Download and uncompress the instances in the `data/` folder:

Compile:
```shell
bazel build -- //...
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release --parallel
cmake --install build --config Release --prefix install
```

To enable algorithms using CPLEX, replace the first step by:
```
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DSTABLESOLVER_USE_CBC=OFF -DSTABLESOLVER_USE_CPLEX=ON
```

Download data:
Expand All @@ -61,7 +68,7 @@ python3 scripts/download_data.py
Examples:

```shell
./bazel-bin/stablesolver/stable/main --verbosity-level 1 --input "data/dimacs1992/brock200_1.clq" --format dimacs1992 --algorithm "local-search-row-weighting-2" --maximum-number-of-iterations 3000 -certificate solution.txt
./install/bin/stablesolver_stable --verbosity-level 1 --input "data/dimacs1992/brock200_1.clq" --format dimacs1992 --algorithm "local-search-row-weighting-2" --maximum-number-of-iterations 3000 --certificate solution.txt
```
```
====================================
Expand Down Expand Up @@ -126,7 +133,7 @@ Weight: 21
```

```shell
./bazel-bin/stablesolver/stable/main --verbosity-level 1 --input "data/dimacs2010/clustering/caidaRouterLevel.graph" --format dimacs2010 --algorithm "local-search-row-weighting-1" --maximum-number-of-iterations 300000
./install/bin/stablesolver_stable --verbosity-level 1 --input "data/dimacs2010/clustering/caidaRouterLevel.graph" --format dimacs2010 --algorithm "local-search-row-weighting-1" --maximum-number-of-iterations 300000
```
```
=====================================
Expand Down
44 changes: 44 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Enable FetchContent.
include(FetchContent)

# Fetch boost.
set(BOOST_INCLUDE_LIBRARIES thread filesystem system program_options)
set(BOOST_ENABLE_CMAKE ON)
include(FetchContent)
FetchContent_Declare(
Boost
GIT_REPOSITORY https://github.com/boostorg/boost.git
GIT_TAG boost-1.84.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(Boost)

# Fetch fontanf/optimizationtools.
FetchContent_Declare(
optimizationtools
GIT_REPOSITORY https://github.com/fontanf/optimizationtools.git
GIT_TAG 33a3966ece149d390ec7ce08699669b5267e64aa)
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../optimizationtools/")
FetchContent_MakeAvailable(optimizationtools)

# Fetch fontanf/localsearchsolver.
FetchContent_Declare(
localsearchsolver
GIT_REPOSITORY https://github.com/fontanf/localsearchsolver.git
GIT_TAG ecb15ef667d107f25ea51d056368f9c4e15545e2)
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../localsearchsolver/")
FetchContent_MakeAvailable(localsearchsolver)

# Fetch fontanf/mathoptsolverscmake.
if(STABLESOLVER_USE_CBC)
set(MATHOPTSOLVERSCMAKE_USE_CBC ON)
endif()
if(STABLESOLVER_USE_CPLEX)
set(MATHOPTSOLVERSCMAKE_USE_CPLEX ON)
endif()
FetchContent_Declare(
mathoptsolverscmake
GIT_REPOSITORY https://github.com/fontanf/mathoptsolverscmake.git
GIT_TAG 56190725f424249a3acd8fce3ff50e08fe675cc6)
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../mathoptsolverscmake/")
FetchContent_MakeAvailable(mathoptsolverscmake)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#if CPLEX_FOUND

#include "stablesolver/clique/solution.hpp"

namespace stablesolver
Expand All @@ -20,5 +18,3 @@ const Output milp_cplex(

}
}

#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#if COINOR_FOUND

#include "stablesolver/stable/algorithm.hpp"

namespace stablesolver
Expand All @@ -21,5 +19,3 @@ const Output milp_1_cbc(

}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#if CPLEX_FOUND

#include "stablesolver/stable/algorithm.hpp"

namespace stablesolver
Expand Down Expand Up @@ -29,5 +27,3 @@ const Output milp_3_cplex(

}
}

#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 11 additions & 12 deletions scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@


stable_main = os.path.join(
"bazel-bin",
"stablesolver",
"stable",
"main")
"install",
"bin",
"stablesolver_stable")
data_dir = os.environ['STABLE_DATA']


greedy_data = [
Expand All @@ -41,7 +41,7 @@

for instance, instance_format in greedy_data:
instance_path = os.path.join(
"data",
data_dir,
instance)
json_output_path = os.path.join(
args.directory,
Expand Down Expand Up @@ -73,7 +73,7 @@

for instance, instance_format in greedy_data:
instance_path = os.path.join(
"data",
data_dir,
instance)
json_output_path = os.path.join(
args.directory,
Expand Down Expand Up @@ -105,7 +105,7 @@

for instance, instance_format in greedy_data:
instance_path = os.path.join(
"data",
data_dir,
instance)
json_output_path = os.path.join(
args.directory,
Expand All @@ -131,10 +131,9 @@


clique_main = os.path.join(
"bazel-bin",
"stablesolver",
"clique",
"main")
"install",
"bin",
"stablesolver_clique")


if args.tests is None or "clique-greedy-gwmin" in args.tests:
Expand All @@ -144,7 +143,7 @@

for instance, instance_format in greedy_data:
instance_path = os.path.join(
"data",
data_dir,
instance)
json_output_path = os.path.join(
args.directory,
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(clique)
add_subdirectory(stable)
30 changes: 30 additions & 0 deletions src/clique/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
add_library(StableSolver_clique)
target_sources(StableSolver_clique PRIVATE
instance.cpp
solution.cpp
algorithm_formatter.cpp)
target_include_directories(StableSolver_clique PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(StableSolver_clique PUBLIC
OptimizationTools::utils
OptimizationTools::containers
OptimizationTools::graph)
add_library(StableSolver::clique ALIAS StableSolver_clique)

add_subdirectory(algorithms)

add_executable(StableSolver_clique_main)
target_sources(StableSolver_clique_main PRIVATE
main.cpp)
target_link_libraries(StableSolver_clique_main PUBLIC
StableSolver_clique_greedy
StableSolver_clique_local_search
Boost::program_options)
if(STABLESOLVER_USE_CPLEX)
target_compile_definitions(StableSolver_clique_main PUBLIC
CPLEX_FOUND=1)
target_link_libraries(StableSolver_clique_main PUBLIC
StableSolver_clique_milp_cplex)
endif()
set_target_properties(StableSolver_clique_main PROPERTIES OUTPUT_NAME "stablesolver_clique")
install(TARGETS StableSolver_clique_main)
File renamed without changes.
30 changes: 30 additions & 0 deletions src/clique/algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
add_library(StableSolver_clique_greedy)
target_sources(StableSolver_clique_greedy PRIVATE
greedy.cpp)
target_include_directories(StableSolver_clique_greedy PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(StableSolver_clique_greedy PUBLIC
StableSolver_clique)
add_library(StableSolver::clique::greedy ALIAS StableSolver_clique_greedy)

if(STABLESOLVER_USE_CPLEX)
add_library(StableSolver_clique_milp_cplex)
target_sources(StableSolver_clique_milp_cplex PRIVATE
milp_cplex.cpp)
target_include_directories(StableSolver_clique_milp_cplex PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(StableSolver_clique_milp_cplex PUBLIC
StableSolver_clique
MathOptSolversCMake::cplex)
add_library(StableSolver::clique::milp_cplex ALIAS StableSolver_clique_milp_cplex)
endif()

add_library(StableSolver_clique_local_search)
target_sources(StableSolver_clique_local_search PRIVATE
local_search.cpp)
target_include_directories(StableSolver_clique_local_search PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(StableSolver_clique_local_search PUBLIC
StableSolver_clique
LocalSearchSolver::localsearchsolver)
add_library(StableSolver::clique::local_search ALIAS StableSolver_clique_local_search)
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7313ddc

Please sign in to comment.