Heuristics API
The Heuristics API provides the optimization strategies for initialization, neighbourhood exploration, and move selection.
Initialization Heuristics
JuLS.SimpleInitialization
— TypeSimpleInitialization <: InitializationHeuristic
A basic initialization strategy that typically assigns default or random values to variables. Must be implemented as (::SimpleInitialization)(e::YourExperiment) and return a vector of values indexed by decision variables.
JuLS.GreedyInitialization
— TypeGreedyInitialization <: InitializationHeuristic
An initialization strategy that uses a greedy approach to assign initial values. Must be implemented as (::GreedyInitialization)(e::YourExperiment) and return a vector of values indexed by decision variables.
JuLS.ChristofidesInitialization
— Typefunction (::ChristofidesInitialization)(e::TSPExperiment)
Initialization strategy using Christofides algorithm for metric TSP. Provides a 1.5-approximation guarantee for metric instances.
Neighbourhood Heuristics
JuLS.RandomNeighbourhood
— TypeRandomNeighbourhood <: NeighbourhoodHeuristic
A neighbourhood generation strategy that randomly samples variables and assigns them random values from their domains.
Fields
variable_sampler::VariableSampler
: Strategy for selecting variablesnumber_of_variables_to_move::Int
: Number of variables to modify in each move
JuLS.BinaryRandomNeighbourhood
— TypeBinaryRandomNeighbourhood <: NeighbourhoodHeuristic
A neighbourhood generation strategy for binary optimization problems that randomly selects and flips variables.
Fields
number_of_moves::Int
: Number of moves to generate in each neighbourhoodnumber_of_variables_to_move::Int
: Number of variables to flip in each move
Description
Generates moves by randomly selecting a specified number of binary variables and flipping their values (0->1 or 1->0) in each move. This creates a neighbourhood of potential solutions around the current solution.
JuLS.BinarySingleNeighbourhood
— TypeBinarySingleNeighbourhood <: NeighbourhoodHeuristic
A neighbourhood generation strategy for binary optimization problems that generates all possible moves where exactly one binary variable is flipped.
JuLS.SwapNeighbourhood
— TypeSwapNeighbourhood <: NeighbourhoodHeuristic
A neighbourhood generation strategy that creates moves by swapping values between selected variables through circular shifting.
Fields
variable_sampler::VariableSampler
: Strategy for selecting variables to swapnumber_of_variables_to_move::Int
: Number of variables involved in each swap (default: 2)
JuLS.KOptNeighbourhood
— TypeKOptNeighbourhood <: NeighbourhoodHeuristic
A neighbourhood generation strategy that creates k-opt moves by permuting values among k selected variables.
Fields
number_of_moves::Int
: Number of different k-opt moves to generatek::Int
: Number of variables involved in each permutation
Description
Implements a k-opt neighbourhood where k variables are selected and their values are permuted to create new potential solutions. This is particularly useful for problems
JuLS.ExhaustiveNeighbourhood
— TypeExhaustiveNeighbourhood <: NeighbourhoodHeuristic
A neighbourhood generation strategy that exhaustively explores all possible value combinations for a selected subset of variables. This is equivalent to relax domains for the variables sampled.
Fields
number_of_variables_to_move::Int
: Number of variables to consider in each movevariable_sampler::VariableSampler
: Strategy for selecting which variables to consider
JuLS.GreedyNeighbourhood
— TypeGreedyNeighbourhood <: NeighbourhoodHeuristic
A neighbourhood generation strategy that greedily explores variables based on their potential improvement at initialization.
Fields
queue::Vector{LazyCartesianMoves}
: Ordered queue of moves to explore_is_init::Bool
: Flag indicating if the neighbourhood has been initialized
Description
This heuristic evaluates each variable's potential contribution to improvement and orders the exploration based on these evaluations. Variables are explored in order of their potential impact on the objective function.
Move Selection Heuristics
JuLS.GreedyMoveSelection
— TypeGreedyMoveSelection <: MoveSelectionHeuristic
Greedy move selection heuristic. Always pick the most impactful move.
JuLS.SimulatedAnnealing
— TypeMetropolis <: MoveSelectionHeuristic
Fields
-T::Float64
: Temperature -α::Float64
: Cooling factor -T_min::Float64
: Minimal temperature
Of all the moves given, take the best delta, return it if negative or return it with probability exp(-δ/T).
JuLS.Metropolis
— TypeMetropolis <: MoveSelectionHeuristic
Fields
T::Float64
: Temperature for metropolis probability
Of all the moves given, take the best delta, return it if negative or return it with probability exp(-δ/T).
Custom Heuristics
To create custom heuristics, implement the appropriate abstract type:
InitializationHeuristic
: For custom initialization strategiesNeighbourhoodHeuristic
: For custom neighbourhood explorationMoveSelectionHeuristic
: For custom move selection criteria
Example Usage
```julia using JuLS
Initialize with different heuristics
model = initmodel( experiment; init = GreedyInitialization(), neigh = KOptNeighbourhood(5, 2), # nmoves, k pick = SimulatedAnnealing(100.0, 0.95) # T0, α )