Table of Contents

Class AntColonyOptimizer<T, TInput, TOutput>

Namespace
AiDotNet.Optimizers
Assembly
AiDotNet.dll

Implements the Ant Colony Optimization algorithm for solving optimization problems.

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

Type Parameters

T

The numeric type used for calculations (e.g., float, double).

TInput

The type of input data structure.

TOutput

The type of output data structure.

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

Remarks

Ant Colony Optimization is inspired by the behavior of ants in finding paths between their colony and food sources. It uses virtual "ants" to explore the solution space and find optimal solutions.

For Beginners: Think of this algorithm as a group of ants searching for the best path to food. Each ant leaves a trail (pheromone) that other ants can follow. Over time, the best paths get stronger trails, leading to better solutions.

Constructors

AntColonyOptimizer(IFullModel<T, TInput, TOutput>, AntColonyOptimizationOptions<T, TInput, TOutput>?, IEngine?)

Initializes a new instance of the AntColonyOptimizer class.

public AntColonyOptimizer(IFullModel<T, TInput, TOutput> model, AntColonyOptimizationOptions<T, TInput, TOutput>? options = null, IEngine? engine = null)

Parameters

model IFullModel<T, TInput, TOutput>

The model to be optimized.

options AntColonyOptimizationOptions<T, TInput, TOutput>

The options for configuring the Ant Colony Optimization algorithm.

engine IEngine

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

Remarks

For Beginners: This sets up the Ant Colony Optimizer with its initial configuration. You can customize various aspects of how it works, or use default settings.

Methods

Deserialize(byte[])

Restores the state of the optimizer from a byte array.

public override void Deserialize(byte[] data)

Parameters

data byte[]

The byte array containing the serialized state of the optimizer.

Remarks

For Beginners: This method takes a saved state of the ant colony optimizer (in the form of a byte array) and uses it to restore the optimizer to that state. It's like loading a saved game, bringing back all the important settings and progress that were saved earlier.

Exceptions

InvalidOperationException

Thrown when deserialization of optimizer options fails.

GetOptions()

Gets the current options for the Ant Colony Optimization algorithm.

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

Returns

OptimizationAlgorithmOptions<T, TInput, TOutput>

The current optimization options.

Remarks

For Beginners: This method lets you see what settings the ant colony algorithm is currently using.

InitializeAdaptiveParameters()

Initializes the adaptive parameters used in the Ant Colony Optimization algorithm.

protected override void InitializeAdaptiveParameters()

Remarks

For Beginners: This method sets up the initial values for how quickly pheromones evaporate and how strongly new pheromones are deposited. These values will change as the algorithm runs to help find better solutions.

Optimize(OptimizationInputData<T, TInput, TOutput>)

Performs the main optimization process using the Ant Colony Optimization algorithm.

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

Parameters

inputData OptimizationInputData<T, TInput, TOutput>

The input data for the optimization process.

Returns

OptimizationResult<T, TInput, TOutput>

The result of the optimization process.

Remarks

For Beginners: This is the heart of the Ant Colony Optimization algorithm. It simulates ants exploring different paths (solutions) over multiple iterations. Each ant builds a solution, then the best solutions are used to update the pheromone trails. This process repeats until a good solution is found or the maximum number of iterations is reached.

Serialize()

Converts the current state of the optimizer into a byte array for storage or transmission.

public override byte[] Serialize()

Returns

byte[]

A byte array representing the serialized state of the optimizer.

Remarks

For Beginners: This method takes all the important information about the current state of the ant colony optimizer and turns it into a format that can be easily saved or sent to another computer.

UpdateAdaptiveParameters(OptimizationStepData<T, TInput, TOutput>, OptimizationStepData<T, TInput, TOutput>)

Updates the adaptive parameters based on the current and previous optimization steps.

protected override void UpdateAdaptiveParameters(OptimizationStepData<T, TInput, TOutput> currentStepData, OptimizationStepData<T, TInput, TOutput> previousStepData)

Parameters

currentStepData OptimizationStepData<T, TInput, TOutput>

Data from the current optimization step.

previousStepData OptimizationStepData<T, TInput, TOutput>

Data from the previous optimization step.

Remarks

For Beginners: This method adjusts how the algorithm behaves based on whether it's improving or not. It changes how quickly pheromones evaporate and how strongly new ones are deposited.

UpdateOptions(OptimizationAlgorithmOptions<T, TInput, TOutput>)

Updates the options for the Ant Colony Optimization algorithm.

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

Parameters

options OptimizationAlgorithmOptions<T, TInput, TOutput>

The new options to be set.

Remarks

For Beginners: This method allows you to change how the ant colony algorithm behaves by updating its settings. It checks to make sure you're providing the right kind of settings.

Exceptions

ArgumentException

Thrown when the provided options are not of the correct type.