givp — GRASP-ILS-VND with Path Relinking
A direction-agnostic metaheuristic optimizer for continuous, integer or mixed black-box problems, available in five languages:
| Language | Distribution | Requires |
|---|---|---|
| Python (NumPy-native) | PyPI givp |
Python 3.10+, NumPy |
| Julia | JuliaHub GIVPOptimizer |
Julia 1.9+ |
| Rust | crates.io givp |
Rust 1.85+ |
| C++17 | Header-only (vcpkg / FetchContent / copy) | C++17 compiler, CMake 3.21+ |
| R | r-universe givp / GitHub / local source (r/) |
R 4.1+ |
The library bundles:
- GRASP — Greedy Randomized Adaptive Search Procedure
- ILS — Iterated Local Search
- VND — Variable Neighborhood Descent (with an adaptive variant)
- Path Relinking between elite solutions
- LRU evaluation cache, convergence monitor, optional thread-parallel candidate evaluation, and a wall-clock time budget
Code quality is enforced in CI with language-specific static analysis and formatting checks — analogous to mypy + ruff in Python — across all ports:
| Language | Linter / static analysis | Formatter | Type checker |
|---|---|---|---|
| Python | ruff | ruff | mypy (strict) |
| Julia | Aqua.jl | JuliaFormatter | JET.jl |
| Rust | Clippy (-D warnings, all targets) |
rustfmt | rustc (type system) |
| C++ | clang-tidy (--warnings-as-errors) |
clang-format (LLVM style) | compiler (-Wall -Wextra -Wpedantic -Werror) |
| R | lintr (linters_with_defaults()) |
— | — |
All checks run as mandatory CI gates. A monorepo SonarQube quality gate workflow runs in addition (CI SonarQube).
Table of contents
- givp — GRASP-ILS-VND with Path Relinking
- Table of contents
- Install
- Python
- Julia
- Rust
- C++
- R
- Comparison with other optimizers
- Empirical results
- Troubleshooting
- License
Install
Python installation
Recommended: install with the optional
cacheextra to use xxhash for a ~10× faster evaluation cache:Without
xxhash, the cache falls back to Python's built-inhashlib(SHA-256), which works correctly but is slower.
From source (editable):
Requires Python 3.10+ and NumPy.
Julia installation
Requires Julia 1.9+.
Rust installation
Add to your Cargo.toml:
[]
= "1.0.0"
From source:
Requires Rust 1.85+ (edition 2021).
C++ installation
The C++ port is header-only.
Install with vcpkg:
Then use in CMake:
find_package(givp CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE givp::givp)
Alternatively, use CMake FetchContent:
include(FetchContent)
FetchContent_Declare(
givp
GIT_REPOSITORY https://github.com/Arnime/grasp_ils_vnd_pr.git
GIT_TAG v1.0.0
SOURCE_SUBDIR cpp
)
FetchContent_MakeAvailable(givp)
target_link_libraries(my_app PRIVATE givp::givp)
Or copy the cpp/include/givp/ directory into your project and add it to your
include path. No external dependencies are required at runtime.
Requires a C++17 compiler (GCC 9+, Clang 10+, MSVC 2019+) and CMake 3.21+
(for the FetchContent approach).
Dependency-manager style alternatives:
- vcpkg manifest mode (recommended for application repos):
- FetchContent/CPM-style git dependency (no local copy required):
use the
FetchContentsnippet above pinningGIT_TAG.
R installation
Install from r-universe (binary/source, no local clone):
Template files for the Arnime.r-universe.dev repository are available in
docs/r-universe/.
Install directly from GitHub:
remotes::
From source:
Requires R 4.1+.
Python
Quick start
return
=
# best vector found
# best objective value
# number of evaluations performed
Default behavior:
- Minimization (
minimize=True/direction="minimize"). - All variables treated as continuous.
- Default hyper-parameters (
GIVPConfig()).
Choosing the optimization sense
The library is agnostic to whether you want the lowest or the highest
value of func. Two equivalent ways to declare it:
Boolean flag (recommended)
return # higher is better
=
assert ==
String flag (SciPy/Optuna compatible)
=
Both flags are accepted on givp, on GIVPOptimizer and on
GIVPConfig. Setting both simultaneously is allowed only when they
agree; conflicting values raise ValueError.
Internal note. The core algorithm always minimizes. When you ask for maximization the public API wraps your objective with a sign flip and restores the sign on
result.fun. This meansresult.funis always reported in your original sign — no need to negate it back yourself.
Bounds, integer variables and mixed problems
bounds is accepted in two equivalent forms:
# SciPy style: list of (low, high) per variable
=
# (lower, upper) tuple of two equally-sized sequences
=
By default every variable is continuous. To declare a mixed problem (some
continuous variables followed by some integer variables in the decision
vector), use integer_split on the configuration:
, = 12, 8
= * + *
= # indices >= n_cont are integer
=
Special cases:
integer_split |
Meaning |
|---|---|
None (public API default: num_vars) |
All-continuous problem. |
0 |
All-integer problem. |
n_vars |
All-continuous problem (explicit). |
k (0 < k < n) |
First k continuous, rest integer. |
Object-oriented API and multi-start
When you want to keep configuration around, run the optimizer multiple times
and track the best result automatically, use GIVPOptimizer:
=
opt.best_x and opt.best_fun always reflect the best result observed across
all run() calls, in the user's original sign.
Configuration cookbook
# 1) Fast triage (small budget, no warm-up)
=
# 2) Production-quality run with wall-clock budget
=
# 3) Expensive objective: maximize cache reuse, keep evaluations few
=
# 4) Maximization with hourly-shaped layout (3 plants × 24 hours)
=
Inspecting progress (callback and verbose)
Both givp and GIVPOptimizer accept:
verbose=True— prints per-iteration cost and cache statistics.iteration_callback=fn— callsfn(iteration_index, best_cost, best_solution)once per outer GRASP iteration. The callback receives the cost in the internal minimization sign (i.e., already sign-flipped if you asked for maximization). Useful to plot convergence or persist intermediate results.
=
=
API reference
givp(...) -> OptimizeResult
->
class GIVPOptimizer
Same constructor signature, exposes .run() -> OptimizeResult and tracks
.best_x, .best_fun, .history.
class GIVPConfig (dataclass)
All hyper-parameters listed in the glossary.
class OptimizeResult
| Field | Type | Meaning |
|---|---|---|
x |
np.ndarray |
Best solution vector. |
fun |
float |
Objective value at x, in the user's original sign. |
nit |
int |
GRASP outer iterations executed. |
nfev |
int |
Number of objective evaluations. |
success |
bool |
True when at least one feasible solution was produced. |
message |
str |
Human-readable termination reason. |
direction |
str |
'minimize' or 'maximize'. |
meta |
dict |
Algorithm-specific extras (cache stats, etc.). |
For backward compatibility the result is iterable: x, fun = result works.
Glossary of hyper-parameters
| Field | Default | Meaning |
|---|---|---|
max_iterations |
100 | GRASP outer iterations. |
alpha |
0.12 | Initial RCL randomization (0 = greedy, 1 = uniform). |
vnd_iterations |
200 | Maximum VND inner iterations. |
ils_iterations |
10 | Iterated Local Search loops per outer iteration. |
perturbation_strength |
4 | Magnitude of ILS perturbation (number of variables jolted). |
use_elite_pool |
True | Maintain a diverse pool of elite solutions for path relinking. |
elite_size |
7 | Maximum number of elite solutions kept. |
path_relink_frequency |
8 | Every N GRASP iterations, run path relinking on elite pairs. |
adaptive_alpha |
True | If True, alpha varies in [alpha_min, alpha_max] over iterations. |
alpha_min / alpha_max |
0.08 / 0.18 | Bounds for adaptive alpha. |
num_candidates_per_step |
20 | Candidates evaluated per construction step. |
use_cache |
True | Memoize evaluations via LRU cache. |
cache_size |
10000 | LRU cache capacity. |
early_stop_threshold |
80 | Iterations without improvement before terminating. |
use_convergence_monitor |
True | Enable diversification/restart heuristics. |
n_workers |
1 | Threads used to evaluate candidates concurrently in the GRASP construction phase. Set to os.cpu_count() or a fixed value (2–4) for CPU-bound objectives. Due to the Python GIL, gains are most visible when func releases the GIL (e.g. NumPy-heavy code). |
time_limit |
0.0 | Wall-clock budget in seconds (0 = unlimited). |
minimize |
None |
Boolean direction flag. True = minimize, False = maximize. |
direction |
'minimize' |
String direction flag (alternative form). |
integer_split |
None |
Index where integer variables begin in the decision vector. |
Adapting to a domain-specific model
The library knows nothing about your problem. Wrap your domain code so it
exposes a func(x: np.ndarray) -> float and a list of bounds. Penalty terms,
repair operators and constraint handling all live in your project.
Minimal pattern:
return
return # treat infeasibility as worst possible cost
return
=
For an end-to-end example with a mixed continuous/integer hydropower model,
see the SOG2 adapter in the upstream project repository
(givp.py).
Julia
The Julia port exposes the same algorithm with an idiomatic Julia API. Install via the Julia installation instructions above.
Julia quick start
using GIVPOptimizer
function sphere(x::Vector{Float64})::Float64
return sum(x .^ 2)
end
result = givp(sphere, [(-5.0, 5.0) for _ in 1:10])
println(result.x) # best vector found
println(result.fun) # best objective value
println(result.nfev) # number of evaluations
Maximization:
result = givp(my_score, bounds; direction=maximize)
Julia bounds and integer variables
bounds is a vector of (lower, upper) tuples, one per variable.
Use integer_split to declare mixed continuous/integer problems:
n_cont, n_int = 8, 4
bounds = vcat(fill((-5.0, 5.0), n_cont), fill((0.0, 3.0), n_int))
cfg = GIVPConfig(; integer_split=n_cont) # indices >= n_cont are integer
result = givp(my_obj, bounds; config=cfg)
Julia configuration cookbook
# 1) Fast triage
cfg_fast = GIVPConfig(;
max_iterations=20, vnd_iterations=50, ils_iterations=5,
use_elite_pool=false, use_convergence_monitor=false,
)
# 2) Production-quality with wall-clock budget
cfg_quality = GIVPConfig(;
max_iterations=200, vnd_iterations=300, ils_iterations=15,
elite_size=10, path_relink_frequency=5,
adaptive_alpha=true, alpha_min=0.05, alpha_max=0.20,
time_limit=600.0,
)
# 3) Maximization
cfg_max = GIVPConfig(; direction=maximize, max_iterations=100)
result = givp(sphere, bounds; config=cfg_quality, seed=42, verbose=true)
Julia result fields
| Field | Type | Meaning |
|---|---|---|
x |
Vector{Float64} |
Best solution vector. |
fun |
Float64 |
Objective value at x, in the original sign. |
nit |
Int |
Outer GRASP iterations executed. |
nfev |
Int |
Total objective-function evaluations. |
success |
Bool |
True when fun is finite. |
message |
String |
Human-readable termination reason. |
direction |
Direction |
minimize or maximize (enum). |
meta |
Dict{String,Any} |
Algorithm-specific extras (cache stats, etc.). |
Tuple unpacking works: x, fun = result.
Julia progress monitoring
costs = Float64[]
function log_iter(i, cost, sol)
push!(costs, cost)
end
result = givp(sphere, bounds; iteration_callback=log_iter, verbose=true)
Running Julia tests and benchmarks
Rust
The Rust port is a zero-dependency (no NumPy), native-performance implementation suitable for embedding in systems code or for maximum throughput. Install via the Rust installation instructions above.
Rust quick start
use ;
let sphere = ;
let bounds: = vec!;
let result = givp.unwrap;
println!;
println!;
println!;
Rust bounds and integer variables
Bounds are a &[(f64, f64)] slice. Use integer_split for mixed problems:
use ;
let n_cont = 8usize;
let mut bounds: = vec!;
bounds.extend; // 4 integer variables
let config = GivpConfig ;
let result = givp.unwrap;
Rust configuration cookbook
use ;
// Maximization
let cfg_max = GivpConfig ;
// Production-quality run with wall-clock budget
let cfg_quality = GivpConfig ;
let result = givp.unwrap;
Rust result fields
| Field | Type | Meaning |
|---|---|---|
x |
Vec<f64> |
Best solution vector. |
fun |
f64 |
Objective value at x, in the original sign. |
nit |
usize |
Outer GRASP iterations executed. |
nfev |
usize |
Total objective-function evaluations. |
success |
bool |
True when fun is finite. |
message |
String |
Human-readable termination reason. |
termination |
TerminationReason |
Typed termination enum. |
The function returns Result<OptimizeResult, GivpError> — use .unwrap() for
quick scripts or pattern-match for production code.
Running Rust tests and benchmarks
C++
The C++ port is a header-only, zero-runtime-dependency implementation. It uses the same algorithm and identical default hyper-parameters as the Python, Julia, and Rust ports.
C++ quick start
int
Maximization:
givp::GivpConfig cfg;
cfg.direction = givp::Direction::Maximize;
auto result = ;
C++ configuration
givp::GivpConfig cfg;
cfg.max_iterations = 50;
cfg.vnd_iterations = 100;
cfg.time_limit = 30.0; // wall-clock seconds
cfg.seed = 42;
cfg.integer_split = 8; // first 8 vars continuous
cfg.verbose = true;
givp::OptimizeResult r = ;
OptimizeResult fields mirror all other ports:
| Field | Type | Meaning |
|---|---|---|
x |
std::vector<double> |
Best solution vector. |
fun |
double |
Objective value at x, in the original sign. |
nit |
std::size_t |
Outer GRASP iterations executed. |
nfev |
std::size_t |
Total objective-function evaluations. |
success |
bool |
True when fun is finite. |
message |
std::string |
Human-readable termination reason. |
Running tests and benchmarks
# Configure and build
# Run the 41 Catch2 test cases
# Build and run nanobench benchmarks
R
The R port mirrors the same algorithm and public API shape as the other languages, with an idiomatic R interface.
R quick start
bounds <-
result <-
Maximization:
result <-
R bounds and integer variables
You can pass bounds either as:
- list of pairs, e.g.
list(c(-5, 5), c(0, 10), c(-1, 1)) - two-column numeric matrix
For mixed continuous/integer problems, set integer_split in config:
cfg <-
result <-
R configuration cookbook
# Fast triage
cfg_fast <-
# Quality run with wall-clock budget
cfg_quality <-
Running R tests and lint
GIVP_R_TEST_PROFILE=quick
GIVP_R_TEST_PROFILE=full
Comparison with other optimizers
| Library | Sense convention | Discrete vars? | Built-in cache | Built-in time budget | Language |
|---|---|---|---|---|---|
scipy.optimize.minimize |
Always minimize | No | No | No | Python |
scipy.optimize.differential_evolution |
Always minimize | Continuous only | No | Via callback | Python |
scipy.optimize.dual_annealing |
Always minimize | No | No | maxiter only |
Python |
optuna |
Explicit (direction) |
Yes | Per-trial only | Yes (timeout) |
Python |
pygad |
Always maximize | Yes | No | No | Python |
givp (Python / Julia / Rust) |
Explicit (minimize/direction) |
Yes (mixed) | LRU cache | Yes (time_limit) |
Python+Julia+Rust |
givp (C++) |
Explicit (Direction enum) |
Yes (mixed) | LRU cache | Yes (time_limit) |
C++17 |
givp (R) |
Explicit (direction) |
Yes (mixed) | LRU cache | Yes (time_limit) |
R |
Empirical results
Results of 30 independent runs (seeds 0–29) on four standard continuous benchmarks
(n = 10 dimensions) comparing the full GIVP pipeline against a GRASP-only baseline
(construction phase only, no ILS/VND/path relinking — equivalent to plain GRASP
as described by Feo & Resende, 1995).
Each run uses an explicit seed for full reproducibility. To reproduce, run the
Notebooks/benchmark_literature_comparison.ipynb
notebook.
Note: Values below are representative results from the notebook execution. Run the notebook on your machine to obtain hardware-specific timings.
Sphere — $f(\mathbf{x}) = \sum x_i^2$, global minimum 0 at 0
| Algorithm | Mean ± Std | Best | Median | NFev (mean) |
|---|---|---|---|---|
| GIVP-full | 0.0002 ± 0.0001 | 6.2935e-05 | 1.9862e-04 | 605 626 |
| GRASP-only | 2.1568 ± 0.4827 | 1.0564e+00 | 2.1947e+00 | 4 828 |
Rosenbrock — global minimum 0 at 1
| Algorithm | Mean ± Std | Best | Median | NFev (mean) |
|---|---|---|---|---|
| GIVP-full | 0.513 ± 0.325 | 1.0413e-02 | 5.1000e-01 | 571 765 |
| GRASP-only | 5441.154 ± 2232.312 | 1.6380e+03 | 5.3735e+03 | 4 834 |
Rastrigin — multimodal, global minimum 0 at 0
| Algorithm | Mean ± Std | Best | Median | NFev (mean) |
|---|---|---|---|---|
| GIVP-full | 0.8492 ± 0.6247 | 9.1427e-03 | 1.0144e+00 | 524 825 |
| GRASP-only | 28.0927 ± 4.9224 | 1.8621e+01 | 2.9218e+01 | 4 898 |
Ackley — multimodal, global minimum 0 at 0
| Algorithm | Mean ± Std | Best | Median | NFev (mean) |
|---|---|---|---|---|
| GIVP-full | 0.1525 ± 0.0277 | 1.0691e-01 | 1.5015e-01 | 477 840 |
| GRASP-only | 8.9242 ± 1.0037 | 7.2171e+00 | 9.2427e+00 | 4 852 |
References
- Feo, T.A. & Resende, M.G.C. (1995). Greedy randomized adaptive search procedures. Journal of Global Optimization, 6, 109–133.
- Festa, P. & Resende, M.G.C. (2011). GRASP: An annotated bibliography. Essays and Surveys in Metaheuristics. Springer.
Troubleshooting
ValueError: each element of upper must be strictly greater than lower
A bounds entry has low >= high. Even fixed values must use a strictly
positive interval ((v - 1e-9, v + 1e-9)) or be removed from the search.
ValueError: bounds length (...) does not match num_vars (...)
You passed num_vars explicitly but the bounds disagree. Drop num_vars to
let the library infer it from bounds, or fix the mismatch.
ValueError: 'minimize' and 'direction' disagree: ...
You passed both flags with conflicting values. Use one or the other (or pass
both with matching values).
Optimization converges to inf.
Your objective is raising or returning nan. The wrapper coerces non-finite
values to +inf so they are always comparable, but if every candidate is
infeasible the algorithm has nothing to improve. Lower perturbation_strength,
revisit your bounds, or relax the feasibility logic in func.
Run is too slow.
Try use_cache=True (with givp[cache] for maximum speed), increase
cache_size, raise n_workers (2–4 is a practical sweet spot under the
Python GIL; set n_workers=os.cpu_count() for NumPy-heavy objectives),
lower num_candidates_per_step, or set a time_limit. For very expensive
objectives, also reduce vnd_iterations and ils_iterations.
Final solution looks too "rough" / integer values look noisy.
Make sure integer_split is set correctly. With the default (None /
num_vars) all variables are treated as continuous and the integer-aware
neighborhoods are skipped.
License
MIT