Skip to content

Commit

Permalink
Initial release.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhouxing-Su committed May 12, 2023
0 parents commit de814df
Show file tree
Hide file tree
Showing 201 changed files with 19,260 additions and 0 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: LLVM
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Created by https://www.toptal.com/developers/gitignore/api/cmake
# Edit at https://www.toptal.com/developers/gitignore?templates=cmake

### CMake ###
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

### CMake Patch ###
# External projects
*-prefix/

# End of https://www.toptal.com/developers/gitignore/api/cmake

build/
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "cvrp/CVRPController"]
path = cvrp/CVRPController
url = https://github.com/laser-ufpb/CVRPController.git
[submodule "irp/dimacs-irp-verifier"]
path = irp/dimacs-irp-verifier
url = https://github.com/sbeyer/dimacs-irp-verifier.git
[submodule "carp/HGS-CARP"]
path = carp/HGS-CARP
url = https://github.com/vidalt/HGS-CARP.git
60 changes: 60 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.14)
project(AlkaidSD)

set(CMAKE_CXX_STANDARD 20)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast -march=native")
if (PGO STREQUAL "generate")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-instr-generate=${CMAKE_SOURCE_DIR}/pgo-clang/dimacs-sd-%p.profraw")
endif ()
if (PGO STREQUAL "use")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-instr-use=${CMAKE_SOURCE_DIR}/pgo-clang/dimacs-sd.profdata")
endif ()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -fuse-ld=lld")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast -march=native")
if (PGO STREQUAL "generate")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-generate=${CMAKE_SOURCE_DIR}/pgo-gcc/dimacs-sd-%q{PROFILE_FILE}")
endif ()
if (PGO STREQUAL "use")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-use=${CMAKE_SOURCE_DIR}/pgo-gcc/dimacs-sd")
endif ()
endif()

include(cmake/cli11.cmake)
include(cmake/json.cmake)
include(cmake/mimalloc.cmake)

include_directories(src)

add_library(
alkaid-sd
src/algorithm/construction.cc
src/algorithm/operator/cross.cc
src/algorithm/operator/exchange.cc
src/algorithm/operator/or_opt.cc
src/algorithm/operator/relocate.cc
src/algorithm/operator/repair.cc
src/algorithm/operator/sd_swap_one_one.cc
src/algorithm/operator/sd_swap_star.cc
src/algorithm/operator/sd_swap_two_one.cc
src/algorithm/operator/split_reinsertion.cc
src/algorithm/operator/swap_star.cc
src/algorithm/operator/swap.cc
src/algorithm/ruin_method.cc
src/algorithm/solver.cc
src/algorithm/sorter.cc
src/config/config.cc
src/distance_matrix.cc
src/model/route_context.cc
src/problem.cc
src/util/solution_utils.cc
src/util/submit.cc
src/util/timer.cc)

target_link_libraries(alkaid-sd nlohmann_json::nlohmann_json)

add_executable(alkaid-sd-main src/main.cc)

target_link_libraries(alkaid-sd-main PRIVATE alkaid-sd CLI11::CLI11 mimalloc-static)
163 changes: 163 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# AlkaidSD: An Efficient Iterated Local Search Heuristic for the Split Delivery Vehicle Routing Problem

DIMACS-12 competition: http://dimacs.rutgers.edu/programs/challenge/vrp/vrpsd/

## Build

### Linux

```bash
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
```

Then the executable file is under `./build/`

### Windows (MSVC)

```bash
mkdir build
cd build
cmake ..
cmake --build . --config Release
```

Then the executable file is under `.\build\Release\`

## Run

```
Usage: ./alkaid-sd-main [OPTIONS] config instance output
Positionals:
config TEXT REQUIRED Config path
instance TEXT REQUIRED Instance name
output TEXT REQUIRED Output
Options:
-h,--help Print this help message and exit
-s INT Random Seed
```

## Examples

```bash
# Solve instance `p05_3070` and output solution to `out_p05_3070.txt`
$ ./alkaid-sd-main ./config/AlkaidSD.json p05_3070 out_p05_3070.txt

# time, value
0.0729653,6207
0.0941946,6112
0.112931,6018
0.190977,5806
0.242988,5671
0.258149,5668
0.328725,5643
0.376124,5579
...

$ cat out_p05_3070.txt

Route 1: 0 - 97 ( 121 ) - 187 ( 79 ) - 0
...
Route 102: 0 - 152 ( 0 ) - 173 ( 109 ) - 171 ( 91 ) - 0
5320
Intel Core i7-8700 @ 3.20GHz
1347.01
```

## Config
```json5
{
"problem_dir": "data/",
"random_seed": 42,

// Processor type as listed in PassMark. See rule http://dimacs.rutgers.edu/files/3816/3754/6419/SDVRP-Rules.pdf
"processor": "Intel Core i7-8700 @ 3.20GHz",
"time_limit": 1347,

// Possible time limit types:
// - real
// - cpu
"time_limit_type": "real",

// Possible acceptance rules:
//
// - type: HC (Hill Climbing)
//
// - type: HCWE (Hill Climbing With Equal)
//
// - type: LAHC (Late Acceptance Hill Climbing)
// length: 83
//
// - type: SA (Simulated Annealing)
// initial_temperature: 1000
// decay: 0.99
//
"acceptance_rule": {
"type": "LAHC",
"length": 83
},

// Possible ruin methods:
//
// - type: SISRs
// average_customers: 36
// max_length: 8
// split_rate: 0.740
// preserved_probability: 0.096
//
// - type: Random
// num_perturb_customers: [5, 6, 7]
//
"ruin_method": {
"type": "SISRs",
"average_customers": 36,
"max_length": 8,
"split_rate": 0.740,
"preserved_probability": 0.096
},

"sorter": {
"random": 0.078,
"demand": 0.225,
"far": 0.942,
"close": 0.120
},
"blink_rate": 0.021,

// Operators for HRVND (Hierarchical random variable neighborhood descent)
// Possible inter-route operators:
// - Swap<2, 0>
// - Swap<2, 1>
// - Swap<2, 2>
// - Relocate
// - SwapStar
// - Cross
// - SdSwapStar
// - SdSwapOneOne
// - SdSwapTwoOne
"inter_operators": [
[
"Relocate",
"Swap<2, 0>",
"Swap<2, 1>",
"Swap<2, 2>",
"Cross",
"SwapStar",
"SdSwapStar"
]
],
// Possible intra-route operators:
// - Exchange
// - OrOpt<1>
// - OrOpt<2>
// - OrOpt<3>
"intra_operators": [
"Exchange",
"OrOpt<1>"
]
}
```
6 changes: 6 additions & 0 deletions cmake/cli11.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include(FetchContent)
FetchContent_Declare(
cli11
GIT_REPOSITORY https://github.com/CLIUtils/CLI11
GIT_TAG v2.3.2)
FetchContent_MakeAvailable(cli11)
4 changes: 4 additions & 0 deletions cmake/json.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include(FetchContent)
FetchContent_Declare(json
URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
FetchContent_MakeAvailable(json)
6 changes: 6 additions & 0 deletions cmake/mimalloc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include(FetchContent)
FetchContent_Declare(
mimalloc
GIT_REPOSITORY https://github.com/microsoft/mimalloc
GIT_TAG v2.0.9)
FetchContent_MakeAvailable(mimalloc)
40 changes: 40 additions & 0 deletions config/AlkaidSD.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"problem_dir": "data/",
"random_seed": 42,
"processor": "Intel Core i7-8700 @ 3.20GHz",
"time_limit": 1347,
"time_limit_type": "real",
"acceptance_rule": {
"type": "LAHC",
"length": 83
},
"ruin_method": {
"type": "SISRs",
"average_customers": 36,
"max_length": 8,
"split_rate": 0.740,
"preserved_probability": 0.096
},
"sorter": {
"random": 0.078,
"demand": 0.225,
"far": 0.942,
"close": 0.120
},
"blink_rate": 0.021,
"inter_operators": [
[
"Relocate",
"Swap<2, 0>",
"Swap<2, 1>",
"Swap<2, 2>",
"Cross",
"SwapStar",
"SdSwapStar"
]
],
"intra_operators": [
"Exchange",
"OrOpt<1>"
]
}
Binary file added data/SDVRP-instances-description.pdf
Binary file not shown.
12 changes: 12 additions & 0 deletions data/SET-1/SD1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
8 100
60 90 60 90 60 90 60 90
0 0
1000 0
0 1000
-1000 0
-0 -1000
2000 0
0 2000
-2000 0
-0 -2000

Loading

0 comments on commit de814df

Please sign in to comment.