RapidSolve

This library provides a metaheuristic framework for solving combinatorial optimization problems.
Overview
Metaheuristics
The following metaheuristics are included:
- local search (with several neighborhood exploration strategies, supports recursion for multiple modifications in one step)
- parallel local search
(the neighborhood is explored in parallel using
rayon, supports recursion) - threshold accepting
- simulated annealing
- tabu search (and a faster parallel version)
Hierarchical Objective
The framework supports hierarchical objective, i.e., objectives that consists of multiple levels of linear combinations. The first level is first minimized and only for tie-breaks the next level is considered. This is useful to model hard-constraints as high-priority soft-constraints (via a violation measure), such that normally infeasible solutions are considered feasible. The solver than minimizes these constraints first until the violation is zero and then starts to optimize the remaining objective levels.
Examples
As an example we provide a simple implementation of the Traveling Salesman Problem (TSP) with the 3-opt neighborhood.
How to use this library (step-by-step example)
Suppose you have given a combinatorial optimization problem and defined a solution type. To run a local search solver you need to do the following four steps:
- Define the
Objectivefor your problem by definingIndicatorsand build a hierarchical objective ofLinearCombinationsof these indicators. - Define modifications for your solution type. The solution type should not be mutable, instead a modified clone should be returned.
- Implement the
Neighborhoodfor the local search. - Initialize the
LocalSearchSolverand run it.
We demonstrate these steps on a simple (but totally artificial) example, where the solution type consists of a fixed-size vector of integers.
;
1. Define the Objective for your problem.
For the example, we want to find permutation (i.e., 0 to 10 should appear exactly once) where the sum of squared differences between consecutive elements (cyclic) is minimized.
Hence, we define two Indicators, namely PermutationViolation and
SquaredDifference, and build a hierarchical
objective where PermutationViolation is minimized first and only for tie-breaks
SquaredDifference is considered.
use ;
;
;
2. Define modifications for your solution type.
In our example we use two modifications:
- Changing one entry to a number between 0 and 10.
- Swapping two entries.
The solution type should not be mutable, instead a modified clone should be returned.
For larger solution types the immutable data structures crate im might increase
performance.
3. Implement the Neighborhood.
In our example we want to first try to change all entries and then try all swaps.
use Neighborhood;
;
4. Initialize the LocalSearchSolver and run it.
In the example only a local optimum is found, which is worse than the global optimum.
use LocalSearchSolver;
use Arc;
let objective = new;
let neighborhood = new;
let solver = initialize;
let initial_solution = Solution;
let evaluated_local_minimum = solver.solve;
assert_eq!;
assert_eq!;
// one global optimum is [0, 2, 4, 6, 8, 9, 7, 5, 3, 1] with a squared differences of 34.
For a less artificial demonstration, we refer to the tsp-example.