ParticleSwarmSolver

class ParticleSwarmSolver @JvmOverloads constructor(problemDefinition: ProblemDefinition, evaluator: EvaluatorIfc, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = RNStreamProvider(), swarmSize: Int = defaultSwarmSize, inertiaSchedule: InertiaWeightScheduleIfc? = null, cognitiveCoefficient: Double = defaultCognitiveCoefficient, socialCoefficient: Double = defaultSocialCoefficient, boundaryHandler: BoundaryHandlerIfc = ClampToBounds(), velocityInitializer: VelocityInitializerIfc = ZeroVelocity(), maximumIterations: Int = psoDefaultMaxIterations, replicationsPerEvaluation: ReplicationPerEvaluationIfc, solutionEqualityChecker: SolutionEqualityIfc = InputsAndConfidenceIntervalEquality(), name: String? = null) : StochasticSolver(source)

A global-best (gbest) Particle Swarm Optimization (PSO) solver for simulation optimization.

Each call to mainIteration performs one swarm move: every particle's velocity is updated from its inertia, its pull toward its personal best, and its pull toward the single shared global best; the velocity is clamped to a per-coordinate maximum; the particle's continuous position is advanced and brought back within the input ranges by the boundaryHandler; and the whole swarm is then evaluated in a single batch oracle call (via the inherited requestEvaluations), so a parallel evaluator fans the particles across workers with no concurrency code here. Per particle, the personal best is refreshed and the global best (the inherited currentSolution, hence bestSolution) is updated.

Particles move in continuous space; only the evaluated position is snapped to granularity (via ProblemDefinition.toInputMap), avoiding granularity lock-in. All randomness is drawn through the solver's single random number stream (rnStream), so a run is reproducible for a fixed stream number.

Parameters

problemDefinition

the problem being solved

evaluator

the evaluator responsible for assessing the quality of solutions

streamNum

the random number stream number; 0 (the default) means the next available stream

streamProvider

the provider of random number streams; defaults to a fresh RNStreamProvider

swarmSize

the number of particles in the swarm

inertiaSchedule

the inertia-weight schedule; when omitted (null) a LinearDecreasingInertia is created whose horizon matches maximumIterations, so the weight decays across the whole run (raising maximumIterations without also passing a schedule no longer leaves the tail at floor inertia)

cognitiveCoefficient

the cognitive acceleration coefficient c1 (pull toward personal best)

socialCoefficient

the social acceleration coefficient c2 (pull toward global best)

boundaryHandler

how out-of-range positions are handled; defaults to ClampToBounds

velocityInitializer

how initial velocities are set; defaults to ZeroVelocity

maximumIterations

the maximum number of iterations

replicationsPerEvaluation

strategy to determine the number of replications per evaluation

solutionEqualityChecker

used to detect no-improvement convergence. The default is InputsAndConfidenceIntervalEquality.

name

an optional name for the solver

Constructors

Link copied to clipboard
constructor(problemDefinition: ProblemDefinition, evaluator: EvaluatorIfc, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = RNStreamProvider(), swarmSize: Int = defaultSwarmSize, inertiaSchedule: InertiaWeightScheduleIfc? = null, cognitiveCoefficient: Double = defaultCognitiveCoefficient, socialCoefficient: Double = defaultSocialCoefficient, boundaryHandler: BoundaryHandlerIfc = ClampToBounds(), velocityInitializer: VelocityInitializerIfc = ZeroVelocity(), maximumIterations: Int = psoDefaultMaxIterations, replicationsPerEvaluation: ReplicationPerEvaluationIfc, solutionEqualityChecker: SolutionEqualityIfc = InputsAndConfidenceIntervalEquality(), name: String? = null)
constructor(problemDefinition: ProblemDefinition, evaluator: EvaluatorIfc, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = RNStreamProvider(), swarmSize: Int = defaultSwarmSize, inertiaSchedule: InertiaWeightScheduleIfc? = null, cognitiveCoefficient: Double = defaultCognitiveCoefficient, socialCoefficient: Double = defaultSocialCoefficient, boundaryHandler: BoundaryHandlerIfc = ClampToBounds(), velocityInitializer: VelocityInitializerIfc = ZeroVelocity(), maximumIterations: Int = psoDefaultMaxIterations, replicationsPerEvaluation: Int = defaultReplicationsPerEvaluation, solutionEqualityChecker: SolutionEqualityIfc = InputsAndConfidenceIntervalEquality(), name: String? = null)

Constructs a particle swarm solver using a fixed number of replications per evaluation.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The boundary handler for out-of-range positions. Cannot be changed while the solver is running.

Link copied to clipboard

If supplied, this function determines (c1, c2) each iteration, overriding the scalars.

Link copied to clipboard

The cognitive acceleration coefficient c1 (pull toward the personal best). Must be >= 0.

Link copied to clipboard

Structured, ordered snapshot of the solver's configuration — the same fields the toString implementations expose, in a form that downstream consumers can iterate (reporting, machine-readable summary artifacts, "compare two runs" tooling).

Link copied to clipboard

When true, the search stops once the normalized swarm diameter falls to or below diameterThreshold (in addition to the no-improvement criterion). Enabled by default.

Link copied to clipboard

The normalized swarm-diameter threshold for convergence. The normalized diameter is the swarm's bounding-box diagonal divided by the search-space diagonal (in 0,1). Must be > 0.

Link copied to clipboard

The current global best solution (equal to the inherited bestSolution).

Link copied to clipboard

The inertia-weight schedule. Cannot be changed while the solver is running.

Link copied to clipboard

The social acceleration coefficient c2 (pull toward the global best). Must be >= 0.

Link copied to clipboard

Used to check whether the most recent best solutions have converged (no improvement).

Link copied to clipboard

A read-only snapshot of the current swarm.

Link copied to clipboard

The number of particles in the swarm. Must be at least defaultMinSwarmSize.

Link copied to clipboard

If supplied, this function determines the swarm size, overriding swarmSize.

Link copied to clipboard

When true, the whole swarm is evaluated under common random numbers within an iteration (which disables caching for that batch). Default is false.

Link copied to clipboard

The velocity initializer. Cannot be changed while the solver is running.

Link copied to clipboard

The fraction of each input's range used as that coordinate's maximum speed (velocity clamp). Must be in (0,1].

Functions

Link copied to clipboard
protected open override fun extractSolverSpecificState(): Map<String, Double>

A hook for subclasses to inject their specific internal state metrics into the snapshot without having to override the entire makeSolverStateSnapshot method.

Link copied to clipboard
protected open override fun initializeIterations()

Subclasses may implement this function to prepare the solver before running the first iteration. Generally, it is sufficient to just implement the startingPoint() function.

Link copied to clipboard
protected open override fun isStoppingCriteriaSatisfied(): Boolean

Subclasses should implement this function to determine if the solver should continue running iterations. This will likely include some implementation of stopping criteria. This function should implement stopping criteria based on the quality of the solution. The number of iterations, compared to the maximum number of iterations, is automatically checked after each step in the iterative process. Unless overridden, this function returns false by default, which indicates that the solution quality criteria have not been satisfied. This will cause the solver to iterate through all iterations of the solution process up to the maximum number of iterations. Alternatively, the user can specify an instance of the SolutionQualityEvaluatorIfc interface to determine if the solution quality has been reached.

Link copied to clipboard
protected open override fun mainIteration()

This function should contain the logic that iteratively executes until the maximum number of iterations is reached or until the stopping criteria is met. The base implementation calls nextPoint() to determine the next point to evaluate, requests an evaluation of the point, and then updates the current solution if the resulting solution is better than the current solution. Generally, implementing startingPoint() and nextPoint() should be adequate. The property iterationCounter represents the current iteration within the mainIteration() function. That is, the value of iterationCounter is incremented prior to the execution of the mainIteration() function.

Link copied to clipboard

The effective swarm size: swarmSizeFn if supplied, otherwise swarmSize.

Link copied to clipboard
open override fun toString(): String