Method: MHL::PSOSwarm#initialize

Defined in:
lib/mhl/pso_swarm.rb

#initialize(size:, initial_positions:, initial_velocities:, c1: nil, c2: nil, chi: nil, constraints: nil, logger: nil) ⇒ PSOSwarm

Returns a new instance of PSOSwarm.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mhl/pso_swarm.rb', line 8

def initialize(size:, initial_positions:, initial_velocities:, 
               c1: nil, c2: nil, chi: nil, constraints: nil, logger: nil)
  @size      = size
  @particles = Array.new(@size) do |index|
    Particle.new(initial_positions[index], initial_velocities[index])
  end

  @iteration = 1

  # get values for parameters C1 and C2
  @c1 = (c1 || DEFAULT_C1).to_f
  @c2 = (c2 || DEFAULT_C2).to_f

  # define procedure to get dynamic value for chi
  @get_chi = if chi and chi.respond_to? :call
    chi
  else
    ->(iter) { (chi || DEFAULT_CHI).to_f }
  end

  @constraints = constraints
  @logger = logger

  if @constraints and @logger
    @logger.info "PSOSwarm called w/ constraints: #{@constraints}"
  end
end