-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
452 lines (388 loc) · 13.2 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
cmake_minimum_required(VERSION 3.16)
project(BALDES LANGUAGES C CXX)
# Check if Clang is available
find_program(CLANG_C_COMPILER clang)
find_program(CLANG_CXX_COMPILER clang++)
if(CLANG_C_COMPILER AND CLANG_CXX_COMPILER)
# Set Clang as the default compiler
set(CMAKE_C_COMPILER
"${CLANG_C_COMPILER}"
CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER
"${CLANG_CXX_COMPILER}"
CACHE STRING "" FORCE)
message(STATUS "Clang found: using Clang as the default compiler")
else()
message(STATUS "Clang not found: using default compiler")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
string(REPLACE "-fconcepts-diagnostics-depth=10" "" CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS}")
endif()
# C++ standard
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Enable Interprocedural Optimization (Link Time Optimization)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API_BOTH TRUE)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message(STATUS "ccache found: using ccache for compilation")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_PROGRAM}")
endif()
# Include directories
include_directories(include)
include_directories(include/bucket)
include_directories(include/algebra)
include_directories(include/cuts)
include_directories(include/extra)
include_directories(include/utils)
include_directories(third_party/hgs_vrptw)
# Build types and flags
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
"RelWithDebInfo"
CACHE STRING "Choose the type of build." FORCE)
endif()
set(CMAKE_CXX_FLAGS_RELEASE
"-O3 -march=native -flto -Xclang -Wno-unknown-warning-option")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"-O3 -g -march=native -flto -Xclang -Wno-unknown-warning-option")
set(CMAKE_CXX_FLAGS_DEBUG
"-Og -g -Wall -Wextra -Xclang -Wno-unknown-warning-option")
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -std=c++20")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unknown-argument")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-error=unused-command-line-argument")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Include the generated config.h file
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
option(RIH "Enable RIH compilation option" OFF)
option(RCC "Enable RCC compilation option" ON)
option(SRC "Enable SRC compilation option" ON)
# option(GET_TBB "Enable TBB compilation option" OFF)
option(UNREACHABLE_DOMINANCE "Enable Unreachable Dominance compilation option"
OFF)
option(SORTED_LABELS "Enable Sorted Labels compilation option" ON)
option(MCD "Enable MCD compilation option" OFF)
option(FIX_BUCKETS "Enable Fixed Buckets compilation option" ON)
option(AVX "Enable AVX compilation option" OFF)
option(IPM "Enable IPM compilation option" ON)
option(TR "Enable TR compilation option" OFF)
option(GET_SUITESPARSE "Enable SuiteSparse compilation option" OFF)
option(EXACT_RCC "Enable Exact RCC compilation option" OFF)
option(EVRP "Enable EVRPTW compilation option" OFF)
option(WITH_PYTHON "Enable Python bindings" OFF)
option(MTW "Enable MTW compilation option" OFF)
option(SCHRODINGER "Enable Schrodinger compilation option" OFF)
option(CLIQUER "Enable Cliquer compilation option" OFF)
option(VERBOSE "Enable verbose output" OFF)
option(JEMALLOC "Enable jemalloc" OFF)
option(GUROBI "Enable GUROBI" OFF)
option(HIGHS "Enable HIGHS" ON)
option(NSYNC "Enable nsync" OFF)
option(CHOLMOD "Enable cholmod" OFF)
option(IPM_ACEL "Enable ipm acelleration" OFF)
option(BALDES "Enable baldes compilation" ON)
option(HGS "Enable HGS" OFF)
# Resource Definitions
set(R_SIZE
1
CACHE STRING "Number of resources")
set(N_SIZE
102
CACHE STRING "Number of nodes")
set(MAX_SRC_CUTS
50
CACHE STRING "Maximum number of SRC cuts")
set(BUCKET_CAPACITY
100
CACHE STRING "Bucket capacity")
set(TIME_INDEX
0
CACHE STRING "Time index")
set(N_ADD
10
CACHE STRING "Number of additional nodes")
set(HGS_TIME
2
CACHE STRING "HGS max running time")
# Git Commit Hash
execute_process(
COMMAND git rev-parse --short HEAD
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_definitions(-DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
add_definitions(-DN_SIZE=${N_SIZE})
add_definitions(-DR_SIZE=${R_SIZE})
add_definitions(-DMAX_SRC_CUTS=${MAX_SRC_CUTS})
add_definitions(-DBUCKET_CAPACITY=${BUCKET_CAPACITY})
add_definitions(-DTIME_INDEX=${TIME_INDEX})
add_definitions(-DN_ADD=${N_ADD})
# if IPM is disabled, force STAB to be enabled
if(NOT IPM)
message(STATUS "IPM is disabled, enabling STAB")
set(STAB ON)
else()
message(STATUS "IPM is enabled, disabling STAB")
set(STAB OFF)
endif()
# Configure the config.h file
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in # Input file (config.h.in)
${CMAKE_CURRENT_BINARY_DIR}/config.h # Output file (config.h)
)
if(STAB AND IPM)
message(
FATAL_ERROR
"Both STAB and IPM cannot be enabled at the same time. Please choose only one."
)
endif()
# Attempt to include CPM.cmake from provided path
include(cmake/CPM.cmake OPTIONAL)
# Check if CPM was included, if not, fetch and include CPM
if(NOT COMMAND CPMAddPackage)
# Include FetchContent module
include(FetchContent)
# Declare CPM.cmake as a FetchContent
FetchContent_Declare(
CPM
GIT_REPOSITORY https://github.com/cpm-cmake/CPM.cmake.git
GIT_TAG v0.40.2)
# Fetch CPM
FetchContent_MakeAvailable(CPM)
# Include CPM.cmake after it has been fetched
include(${cpm_SOURCE_DIR}/cmake/CPM.cmake)
endif()
cpmaddpackage(
NAME
stdexec
GITHUB_REPOSITORY
NVIDIA/stdexec
GIT_TAG
main
OPTIONS
"STDEXEC_BUILD_TESTS OFF"
"STDEXEC_BUILD_EXAMPLES OFF"
"STDEXEC_BUILD_BENCHMARKS OFF"
"STDEXEC_BUILD_DOCS OFF"
"BUILD_TESTING OFF")
string(REPLACE "-fconcepts-diagnostics-depth=10" "" CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS}")
find_package(xxhash)
if(NOT xxhash_FOUND)
cpmaddpackage(
NAME
xxhash
GITHUB_REPOSITORY
Cyan4973/xxHash
GIT_TAG
origin/dev
SOURCE_SUBDIRECTORY
cmake_unofficial # Specify the folder with CMake configuration
)
include_directories(${xxhash_SOURCE_DIR})
add_subdirectory(${xxhash_SOURCE_DIR}/cmake_unofficial)
endif()
cpmaddpackage(NAME ankerl_unordered_dense GITHUB_REPOSITORY
martinus/unordered_dense GIT_TAG origin/main)
include_directories(${ankerl_unordered_dense_SOURCE_DIR}/include)
if(NSYNC)
set(nsync_ADDED ON)
cpmaddpackage(
NAME
nsync
GITHUB_REPOSITORY
google/nsync
GIT_TAG
origin/master
OPTIONS
"NSYNC_ENABLE_TESTS OFF")
endif()
find_package(FMT)
if(NOT FMT_FOUND)
message(STATUS "FMT not found, using bundled version")
cpmaddpackage(NAME fmt GITHUB_REPOSITORY fmtlib/fmt GIT_TAG 11.0.2)
endif()
if(IPM)
endif()
if(HIGHS)
cpmaddpackage(
NAME
Highs
GITHUB_REPOSITORY
ERGO-Code/HiGHS
GIT_TAG
origin/master
OPTIONS
"BUILD_SHARED_LIBS ON"
"BUILD_EXAMPLES OFF"
"BUILD_CXX_EXAMPLE OFF"
"BUILD_CSHARP_EXAMPLE OFF"
"BUILD_TESTING OFF"
"USE_DOTNET_STD_21 OFF")
include_directories(${Highs_SOURCE_DIR}/src ${Highs_INCLUDE_DIR})
# Path to your patch file
set(PATCH_FILE "${CMAKE_CURRENT_LIST_DIR}/highs.patch")
# echo the patch file
message(STATUS "Patch file: ${PATCH_FILE}")
# Apply the patch using execute_process
execute_process(
COMMAND patch -p1 -i ${PATCH_FILE}
WORKING_DIRECTORY ${Highs_SOURCE_DIR}
RESULT_VARIABLE PATCH_RESULT
ERROR_VARIABLE PATCH_ERROR)
endif()
if(WITH_PYTHON)
cpmaddpackage(NAME pybind11 GITHUB_REPOSITORY pybind/pybind11 GIT_TAG v2.13.6)
endif()
set(GUROBI_HOME $ENV{GUROBI_HOME})
include_directories(${GUROBI_HOME}/include)
# Source files
set(SOURCES src/BCP.cpp src/BucketGraph.cpp src/MIPHandler.cpp
src/Branching.cpp src/BucketPSTEP.cpp)
set(CVRPSEP_SOURCES
third_party/cvrpsep/basegrph.cpp
third_party/cvrpsep/capsep.cpp
third_party/cvrpsep/cnstrmgr.cpp
third_party/cvrpsep/memmod.cpp
third_party/cvrpsep/compcuts.cpp
third_party/cvrpsep/strngcmp.cpp
third_party/cvrpsep/compress.cpp
third_party/cvrpsep/cutbase.cpp
third_party/cvrpsep/fcapfix.cpp
third_party/cvrpsep/mxf.cpp
# third_party/cvrpsep/twomatch.cpp third_party/cvrpsep/glmsep.cpp
# third_party/cvrpsep/binpack.cpp
third_party/cvrpsep/combsep.cpp
third_party/cvrpsep/fcits.cpp
third_party/cvrpsep/grsearch.cpp
# third_party/cvrpsep/hpmstar.cpp third_party/cvrpsep/strcomb.cpp
# third_party/cvrpsep/blocks.cpp
third_party/cvrpsep/sort.cpp)
set(HGS_SOURCES
third_party/hgs_vrptw/Genetic.cpp third_party/hgs_vrptw/Individual.cpp
third_party/hgs_vrptw/LocalSearch.cpp third_party/hgs_vrptw/Params.cpp
third_party/hgs_vrptw/Population.cpp third_party/hgs_vrptw/Split.cpp)
set(FPSOURCE
third_party/fpmax/fpmax.cpp third_party/fpmax/buffer.cpp
third_party/fpmax/data.cpp third_party/fpmax/fsout.cpp
third_party/fpmax/fp_tree.cpp third_party/fpmax/fp_node.cpp)
set(MUSSPSOURCE third_party/muSSP/Graph.cpp third_party/muSSP/Sink.cpp)
set(IPM_SOURCES src/IPSolver.cpp)
set(SRC_SOURCES src/SRC.cpp src/HighOrderSRC.cpp)
# Define a list for the source files that will be included
set(EXECUTABLE_SOURCES ${SOURCES} ${HGS_SOURCES} ${FPSOURCE} ${MUSSPSOURCE})
# Append sources based on the flags
if(RCC)
message(STATUS "RCC is set, adding CVRPSEP_SOURCES.")
list(APPEND EXECUTABLE_SOURCES ${CVRPSEP_SOURCES})
list(APPEND EXECUTABLE_SOURCES src/RCC.cpp)
endif()
if(IPM OR IPM_ACEL)
message(STATUS "IPM is set, adding IPM_SOURCES.")
list(APPEND EXECUTABLE_SOURCES ${IPM_SOURCES})
endif()
if(SRC)
message(STATUS "SRC is set, adding SRC_SOURCES.")
list(APPEND EXECUTABLE_SOURCES ${SRC_SOURCES})
endif()
if(IPM OR IPM_ACEL)
cpmaddpackage(
NAME
Eigen
GIT_REPOSITORY
https://gitlab.com/libeigen/eigen.git
GIT_TAG
3.4.0
DOWNLOAD_ONLY
YES # Only download Eigen, don't configure or build it
)
endif()
# Common Libraries List
set(COMMON_LIBRARIES STDEXEC::stdexec fmt::fmt xxhash)
if(HIGHS)
list(APPEND COMMON_LIBRARIES highs::highs)
endif()
if(NSYNC)
list(APPEND COMMON_LIBRARIES nsync)
include_directories(${nsync_SOURCE_DIR}/public)
endif()
set(GUROBI_VERSION_MAJOR 120) # Adjust based on Gurobi version
if(APPLE)
# macOS detected, use .dylib for linking
list(APPEND COMMON_LIBRARIES ${GUROBI_HOME}/lib/libgurobi_c++.a
${GUROBI_HOME}/lib/libgurobi100.dylib)
else()
# Non-macOS (Linux or other platforms), use .so and .a files
list(APPEND COMMON_LIBRARIES ${GUROBI_HOME}/lib/libgurobi_c++.a
${GUROBI_HOME}/lib/libgurobi${GUROBI_VERSION_MAJOR}.so tbb)
endif()
if(BALDES)
# Add the executable with the combined sources
add_executable(baldes src/Baldes.cpp ${EXECUTABLE_SOURCES})
if(JEMALLOC)
find_library(JEMALLOC_LIBRARY jemalloc)
if(JEMALLOC_LIBRARY)
message(STATUS "jemalloc found: ${JEMALLOC_LIBRARY}")
target_link_libraries(baldes PRIVATE ${JEMALLOC_LIBRARY})
else()
message(STATUS "jemalloc not found")
endif()
endif()
message(STATUS "Gurobi version: ${GUROBI_VERSION_MAJOR}")
target_compile_options(baldes PRIVATE -Wno-c++26-extensions
-Wno-deprecated-declarations)
# target_precompile_headers( baldes PRIVATE include/Common.h
# ${CVRPSEP_HEADERS} ${FPMAX_HEADERS} include/Arc.h include/Dual.h
# include/VRPNode.h third_party/pdqsort.h)
if(IPM OR IPM_ACEL)
target_include_directories(baldes PRIVATE ${Eigen_SOURCE_DIR})
target_include_directories(baldes PRIVATE ${Eigen_SOURCE_DIR}/unsupported)
endif()
target_link_libraries(baldes PRIVATE ${COMMON_LIBRARIES})
endif()
if(CLIQUER)
add_executable(cliquer src/Original.cpp src/BucketGraph.cpp)
endif()
if(MTW)
add_executable(vrpmtw mtw/VRPMTW.cpp ${EXECUTABLE_SOURCES} ${HGS_SOURCES}
${FPSOURCE})
target_compile_options(vrpmtw PRIVATE -Wno-c++26-extensions
-Wno-deprecated-declarations)
target_link_libraries(vrpmtw PRIVATE ${COMMON_LIBRARIES})
endif()
if(WITH_PYTHON)
pybind11_add_module(
pybaldes
src/BucketBindings.cpp
src/BCP.cpp
src/BucketGraph.cpp
src/MIPHandler.cpp
src/Branching.cpp
${EXECUTABLE_SOURCES})
target_link_libraries(pybaldes PRIVATE ${COMMON_LIBRARIES})
set_target_properties(pybaldes PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(pybaldes PRIVATE -Wno-c++26-extensions
-Wno-deprecated-declarations)
# link pybind
target_link_libraries(pybaldes PRIVATE pybind11::module)
set_target_properties(pybaldes PROPERTIES PREFIX "")
if(IPM OR IPM_ACEL)
target_include_directories(pybaldes PRIVATE ${Eigen_SOURCE_DIR})
target_include_directories(pybaldes PRIVATE ${Eigen_SOURCE_DIR}/unsupported)
endif()
endif()
if(HGS)
add_executable(hgs src/HGS.cpp ${HGS_SOURCES} ${FPSOURCE})
target_link_libraries(hgs PRIVATE ${COMMON_LIBRARIES})
target_compile_options(hgs PRIVATE -Wno-c++26-extensions
-Wno-deprecated-declarations)
endif()
string(REPLACE "-fconcepts-diagnostics-depth=10" "" CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS}")