Table of Contents

Class TabuSearchOptimizer<T, TInput, TOutput>

Namespace
AiDotNet.Optimizers
Assembly
AiDotNet.dll

Represents a Tabu Search optimizer for machine learning models.

public class TabuSearchOptimizer<T, TInput, TOutput> : OptimizerBase<T, TInput, TOutput>, IOptimizer<T, TInput, TOutput>, IModelSerializer

Type Parameters

T

The numeric type used for calculations, typically float or double.

TInput
TOutput
Inheritance
OptimizerBase<T, TInput, TOutput>
TabuSearchOptimizer<T, TInput, TOutput>
Implements
IOptimizer<T, TInput, TOutput>
Inherited Members
Extension Methods

Remarks

The TabuSearchOptimizer implements the Tabu Search algorithm, a metaheuristic search method used in optimization. It explores the solution space by iteratively moving from one solution to the best solution in its neighborhood, while keeping a list of recently visited solutions (the tabu list) to avoid cycling and encourage exploration of new areas.

For Beginners: Think of Tabu Search as a smart explorer:

  • The explorer (optimizer) looks for the best solution in a complex landscape
  • It remembers recently visited places (tabu list) to avoid going in circles
  • It adapts its search strategy over time to balance between exploring new areas and refining good solutions

This method is particularly effective for problems with many local optima.

Constructors

TabuSearchOptimizer(IFullModel<T, TInput, TOutput>, TabuSearchOptions<T, TInput, TOutput>?, GeneticBase<T, TInput, TOutput>?, IFitnessCalculator<T, TInput, TOutput>?, IModelEvaluator<T, TInput, TOutput>?, IEngine?)

Initializes a new instance of the TabuSearchOptimizer class.

public TabuSearchOptimizer(IFullModel<T, TInput, TOutput> model, TabuSearchOptions<T, TInput, TOutput>? options = null, GeneticBase<T, TInput, TOutput>? geneticAlgorithm = null, IFitnessCalculator<T, TInput, TOutput>? fitnessCalculator = null, IModelEvaluator<T, TInput, TOutput>? modelEvaluator = null, IEngine? engine = null)

Parameters

model IFullModel<T, TInput, TOutput>

The model to be optimized.

options TabuSearchOptions<T, TInput, TOutput>

Options specific to the Tabu Search algorithm.

geneticAlgorithm GeneticBase<T, TInput, TOutput>

The genetic algorithm to use for mutations. If null, a StandardGeneticAlgorithm will be used.

fitnessCalculator IFitnessCalculator<T, TInput, TOutput>
modelEvaluator IModelEvaluator<T, TInput, TOutput>
engine IEngine

The computation engine (CPU or GPU) for vectorized operations.

Methods

Deserialize(byte[])

Deserializes the TabuSearchOptimizer from a byte array.

public override void Deserialize(byte[] data)

Parameters

data byte[]

The byte array containing the serialized optimizer data.

Remarks

This method reconstructs the TabuSearchOptimizer from a serialized byte array. It performs the following steps: 1. Deserializes the base class data. 2. Deserializes the Tabu Search-specific options. 3. Reinitializes the adaptive parameters.

For Beginners: Think of this method as "unpacking" the optimizer's saved state:

  • It's like opening a saved file in a game to continue where you left off.
  • The method reads the saved data and sets up the optimizer to match that saved state.
  • It ensures that all the special Tabu Search settings are correctly restored.
  • After unpacking, it prepares the optimizer for use by setting up its internal values.

This allows you to save the optimizer's state and later restore it exactly as it was.

Exceptions

InvalidOperationException

Thrown when deserialization of optimizer options fails.

GetOptions()

Gets the current options for the Tabu Search algorithm.

public override OptimizationAlgorithmOptions<T, TInput, TOutput> GetOptions()

Returns

OptimizationAlgorithmOptions<T, TInput, TOutput>

The current TabuSearchOptions.

Optimize(OptimizationInputData<T, TInput, TOutput>)

Performs the optimization process to find the best solution for the given input data.

public override OptimizationResult<T, TInput, TOutput> Optimize(OptimizationInputData<T, TInput, TOutput> inputData)

Parameters

inputData OptimizationInputData<T, TInput, TOutput>

The input data to optimize against.

Returns

OptimizationResult<T, TInput, TOutput>

An optimization result containing the best solution found and associated metrics.

Remarks

This method implements the main Tabu Search algorithm. It iteratively generates and evaluates neighboring solutions, updates the best solution found, and adapts its search parameters.

For Beginners: This is the main journey of our explorer:

  1. Start at a random point in the landscape (initialize random solution)
  2. For each step (iteration):
    • Look at nearby places (generate neighbors)
    • Choose the best place that hasn't been visited recently (best non-tabu neighbor)
    • Move to that place (update current solution)
    • Remember this place (update tabu list)
    • Adjust the search strategy (update adaptive parameters)
    • Check if this is the best place found so far (update best solution)
    • Decide whether to stop early if no progress is being made
  3. Return the best place found during the entire journey

This process helps find a good solution efficiently, even in complex landscapes.

Serialize()

Serializes the TabuSearchOptimizer to a byte array.

public override byte[] Serialize()

Returns

byte[]

A byte array representing the serialized optimizer.

UpdateOptions(OptimizationAlgorithmOptions<T, TInput, TOutput>)

Updates the options for the Tabu Search algorithm.

protected override void UpdateOptions(OptimizationAlgorithmOptions<T, TInput, TOutput> options)

Parameters

options OptimizationAlgorithmOptions<T, TInput, TOutput>

The new options to set.

Exceptions

ArgumentException

Thrown when the provided options are not of type TabuSearchOptions.