OptiPy
Loading...
Searching...
No Matches
SolutionBuilder Class Reference

Responsible for creating random solutions and neighborhood samples. More...

#include <SolutionBuilder.h>

Public Member Functions

 SolutionBuilder (int dimensions, int lower, int upper, int seed)
 Constructs a SolutionBuilder with specific space constraints.
std::vector< double > getRand ()
 Generates a single random solution vector within bounds.
std::vector< std::vector< double > > getNeighbors (const std::vector< double > &center, int numNeighbors, double maxDelta)
 Generates a set of neighboring solutions around a central point.
double getDimensions ()
 Returns the dimensionality of the solution space.
std::vector< int > getSubset (int populationSize, int subsetSize, int source)
 Generates a subset of unique solutions from given population.
std::vector< double > getDifference (const std::vector< double > vec1, const std::vector< double > vec2)
double checkBounds (double value)
 Ensures a coordinate stays within the defined [lower, upper] bounds.
double randNum ()
int randNum (int x, int y)
std::vector< double > getInitialVelocity ()
double clampVelocity (double v)

Detailed Description

Responsible for creating random solutions and neighborhood samples.

This class encapsulates the logic for generating initial random positions within the search space and perturbing existing solutions to find neighbors. It utilizes the Mersenne Twister algorithm for high-quality random number generation.

Constructor & Destructor Documentation

◆ SolutionBuilder()

SolutionBuilder::SolutionBuilder ( int dimensions,
int lower,
int upper,
int seed )
inline

Constructs a SolutionBuilder with specific space constraints.

Parameters
dimensionsNumber of variables in the solution vector.
lowerMinimum value for any given dimension.
upperMaximum value for any given dimension.
seedValue used to initialize the Mersenne Twister generator.

Member Function Documentation

◆ checkBounds()

double SolutionBuilder::checkBounds ( double value)

Ensures a coordinate stays within the defined [lower, upper] bounds.

Parameters
valueThe value to check.
Returns
The clamped value.

◆ getNeighbors()

std::vector< std::vector< double > > SolutionBuilder::getNeighbors ( const std::vector< double > & center,
int numNeighbors,
double maxDelta )

Generates a set of neighboring solutions around a central point.

Used primarily by Local Search algorithms to explore the immediate vicinity of the current best candidate.

Parameters
centerThe original solution vector to perturb.
numNeighborsNumber of neighbor vectors to generate.
maxDeltaThe maximum step size allowed for perturbation in any dimension.
Returns
A collection of neighboring solution vectors.

◆ getRand()

std::vector< double > SolutionBuilder::getRand ( )

Generates a single random solution vector within bounds.

Returns
A vector of size dimensions with values in range [lower, upper].

◆ getSubset()

std::vector< int > SolutionBuilder::getSubset ( int populationSize,
int subsetSize,
int source )

Generates a subset of unique solutions from given population.

Parameters
populationSize population from which subset is selected.
subsetSizeNumber of solutions to include in returned subset.
Returns
A collection of unique indices from initial population.

The documentation for this class was generated from the following files:
  • src/opti_py/cpp/include/opti_py/SolutionBuilder.h
  • src/opti_py/cpp/src/SolutionBuilder.cpp