-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] add GFACS and replace PyVRP with HGS for CVRP local search #236
Open
hyeok9855
wants to merge
16
commits into
ai4co:main
Choose a base branch
from
hyeok9855:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a79c565
add gfacs
hyeok9855 5a3323d
change cvrp local search to HGS
hyeok9855 d84da62
make test happy
hyeok9855 dcd5821
make test happy
hyeok9855 99a05f3
make test happy
hyeok9855 d038bff
add validity checker in HGS-based local search
hyeok9855 8270199
fix bug in CVRPEdgeEmbedding and some minor refactorings
hyeok9855 eaaba4e
minor refactorings
hyeok9855 8012b2c
[Chore] backwards compatibility Python 3.9 (match -> if-elif-else)
fedebotu 25f9fcb
[Chore] woopsie revert new syntax #237
fedebotu dc18bf9
[Chore] drop Python 3.9; cleanup
fedebotu a93c830
[BugFix] test training without local search
fedebotu 57063d0
Merge branch 'main' into main
fedebotu 3f8a1a9
resolve conflicts
hyeok9855 bc4a8f8
Merge branch 'ai3co-main' into main
hyeok9855 9ea2a9a
better typing following the upstream
hyeok9855 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# @package _global_ | ||
|
||
defaults: | ||
- override /model: gfacs.yaml | ||
- override /env: tsp.yaml | ||
- override /callbacks: default.yaml | ||
- override /trainer: default.yaml | ||
- override /logger: wandb.yaml | ||
|
||
env: | ||
generator_params: | ||
num_loc: 50 | ||
|
||
logger: | ||
wandb: | ||
project: "rl4co" | ||
tags: ["gfacs", "${env.name}"] | ||
group: ${env.name}${env.generator_params.num_loc} | ||
name: gfacs-${env.name}${env.generator_params.num_loc} | ||
|
||
model: | ||
batch_size: 20 | ||
val_batch_size: 20 | ||
test_batch_size: 20 | ||
train_data_size: 400 | ||
val_data_size: 20 | ||
test_data_size: 100 | ||
optimizer: "AdamW" | ||
optimizer_kwargs: | ||
lr: 1e-3 | ||
weight_decay: 0 | ||
lr_scheduler: | ||
"MultiStepLR" | ||
lr_scheduler_kwargs: | ||
milestones: [15, 35] | ||
gamma: 0.1 | ||
|
||
train_with_local_search: True | ||
ls_reward_aug_W: 0.99 | ||
|
||
policy_kwargs: | ||
n_ants: | ||
train: 30 | ||
val: 30 | ||
test: 100 | ||
n_iterations: | ||
train: 1 # unused value | ||
val: 5 | ||
test: 10 | ||
temperature: 1.0 | ||
top_p: 0.0 | ||
top_k: 0 | ||
aco_kwargs: | ||
alpha: 1.0 | ||
beta: 1.0 | ||
decay: 0.95 | ||
use_local_search: True | ||
use_nls: True | ||
n_perturbations: 5 | ||
local_search_params: | ||
max_iterations: 1000 | ||
perturbation_params: | ||
max_iterations: 20 | ||
k_sparse: 5 # this should be adjusted based on the `num_loc` value | ||
|
||
beta_min: 100 | ||
beta_max: 500 | ||
beta_flat_epochs: 5 | ||
|
||
trainer: | ||
max_epochs: 50 | ||
|
||
seed: 1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
_target_: rl4co.models.DeepACO | ||
|
||
baseline: "exponential" | ||
baseline: "no" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_target_: rl4co.models.GFACS | ||
|
||
baseline: "no" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
# Test build files | ||
Test/CMakeFiles/ | ||
Test/CMakeCache.txt | ||
|
||
# build files | ||
build/ | ||
|
||
# IDE files | ||
.vscode | ||
.idea | ||
cmake-build-* | ||
[Dd]ebug/ | ||
[Dd]ebugPublic/ | ||
[Rr]elease/ | ||
[Rr]eleases/ | ||
[Xx]64/ | ||
[Xx]86/ | ||
*.user | ||
.vs/ | ||
|
||
|
||
# Prerequisites | ||
*.d | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.mod | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(HGS_CVRP) | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
set( | ||
src_files | ||
Program/Genetic.cpp | ||
Program/Individual.cpp | ||
Program/LocalSearch.cpp | ||
Program/Params.cpp | ||
Program/Population.cpp | ||
Program/Split.cpp | ||
Program/InstanceCVRPLIB.cpp | ||
Program/AlgorithmParameters.cpp | ||
Program/C_Interface.cpp) | ||
|
||
if (MSVC) | ||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
endif (MSVC) | ||
|
||
include_directories(Program) | ||
|
||
# Build Executable | ||
add_executable(bin | ||
Program/main.cpp | ||
${src_files}) | ||
|
||
set_target_properties(bin PROPERTIES OUTPUT_NAME hgs) | ||
|
||
# Build Library | ||
add_library(lib SHARED ${src_files}) | ||
set_target_properties(lib PROPERTIES OUTPUT_NAME hgscvrp) | ||
|
||
|
||
# Install | ||
install(TARGETS lib | ||
DESTINATION lib) | ||
install(TARGETS bin | ||
DESTINATION bin) | ||
install(FILES Program/AlgorithmParameters.h Program/C_Interface.h | ||
DESTINATION include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Thibaut Vidal | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
50 changes: 50 additions & 0 deletions
50
rl4co/envs/routing/cvrp/HGS-CVRP/Program/AlgorithmParameters.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Created by chkwon on 3/23/22. | ||
// | ||
|
||
#include "AlgorithmParameters.h" | ||
#include <iostream> | ||
|
||
extern "C" | ||
struct AlgorithmParameters default_algorithm_parameters() { | ||
struct AlgorithmParameters ap{}; | ||
|
||
ap.nbGranular = 20; | ||
ap.mu = 25; | ||
ap.lambda = 40; | ||
ap.nbElite = 4; | ||
ap.nbClose = 5; | ||
|
||
ap.nbIterPenaltyManagement = 100; | ||
ap.targetFeasible = 0.2; | ||
ap.penaltyDecrease = 0.85; | ||
ap.penaltyIncrease = 1.2; | ||
|
||
ap.seed = 0; | ||
ap.nbIter = 20000; | ||
ap.nbIterTraces = 500; | ||
ap.timeLimit = 0; | ||
ap.useSwapStar = 1; | ||
|
||
return ap; | ||
} | ||
|
||
void print_algorithm_parameters(const AlgorithmParameters & ap) | ||
{ | ||
std::cout << "=========== Algorithm Parameters =================" << std::endl; | ||
std::cout << "---- nbGranular is set to " << ap.nbGranular << std::endl; | ||
std::cout << "---- mu is set to " << ap.mu << std::endl; | ||
std::cout << "---- lambda is set to " << ap.lambda << std::endl; | ||
std::cout << "---- nbElite is set to " << ap.nbElite << std::endl; | ||
std::cout << "---- nbClose is set to " << ap.nbClose << std::endl; | ||
std::cout << "---- nbIterPenaltyManagement is set to " << ap.nbIterPenaltyManagement << std::endl; | ||
std::cout << "---- targetFeasible is set to " << ap.targetFeasible << std::endl; | ||
std::cout << "---- penaltyDecrease is set to " << ap.penaltyDecrease << std::endl; | ||
std::cout << "---- penaltyIncrease is set to " << ap.penaltyIncrease << std::endl; | ||
std::cout << "---- seed is set to " << ap.seed << std::endl; | ||
std::cout << "---- nbIter is set to " << ap.nbIter << std::endl; | ||
std::cout << "---- nbIterTraces is set to " << ap.nbIterTraces << std::endl; | ||
std::cout << "---- timeLimit is set to " << ap.timeLimit << std::endl; | ||
std::cout << "---- useSwapStar is set to " << ap.useSwapStar << std::endl; | ||
std::cout << "==================================================" << std::endl; | ||
} |
38 changes: 38 additions & 0 deletions
38
rl4co/envs/routing/cvrp/HGS-CVRP/Program/AlgorithmParameters.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Created by chkwon on 3/23/22. | ||
// | ||
|
||
// This header file must be readable in C. | ||
|
||
#ifndef ALGORITHMPARAMETERS_H | ||
#define ALGORITHMPARAMETERS_H | ||
|
||
struct AlgorithmParameters { | ||
int nbGranular; // Granular search parameter, limits the number of moves in the RI local search | ||
int mu; // Minimum population size | ||
int lambda; // Number of solutions created before reaching the maximum population size (i.e., generation size) | ||
int nbElite; // Number of elite individuals | ||
int nbClose; // Number of closest solutions/individuals considered when calculating diversity contribution | ||
|
||
int nbIterPenaltyManagement; // Number of iterations between penalty updates | ||
double targetFeasible; // Reference proportion for the number of feasible individuals, used for the adaptation of the penalty parameters | ||
double penaltyDecrease; // Multiplier used to decrease penalty parameters if there are sufficient feasible individuals | ||
double penaltyIncrease; // Multiplier used to increase penalty parameters if there are insufficient feasible individuals | ||
|
||
int seed; // Random seed. Default value: 0 | ||
int nbIter; // Nb iterations without improvement until termination (or restart if a time limit is specified). Default value: 20,000 iterations | ||
int nbIterTraces; // Number of iterations between traces display during HGS execution | ||
double timeLimit; // CPU time limit until termination in seconds. Default value: 0 (i.e., inactive) | ||
int useSwapStar; // Use SWAP* local search or not. Default value: 1. Only available when coordinates are provided. | ||
}; | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
#endif | ||
struct AlgorithmParameters default_algorithm_parameters(); | ||
|
||
#ifdef __cplusplus | ||
void print_algorithm_parameters(const AlgorithmParameters & ap); | ||
#endif | ||
|
||
#endif //ALGORITHMPARAMETERS_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About
HGS-CVRP
: I think the best way for us would be to provide instructions for the user on how to download this repo and install it? If the code was modified (as it seems to be) I think we can upload it as a separate repo that can be downloaded as optional - this is for us not to maintain in a single repo RL-based solvers and pure heuristics 👀For example, we could provide instructions like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Yes, it's modified by DeepACO.
But I'm wondering if it is worth uploading it as a separate repo because it is almost the same as the original HGS but has a function for local_search.
@henry-yeh, @Furffico Do you guys have any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both options seem fine to me, but I lean slightly towards optional downloading. It would make RL4CO more purely RL-based and lighter to use.