46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/pso/solver.rb', line 46
def solve(precision: 200000, threads: 1)
Array.new(threads).map do
Thread.new do
((precision / @swarm.size) / threads).times do |interation_number|
for index in 0...@density
perfect = perfect_particle
puts @f.f perfect
new_vector = normalize(interate(@swarm[index], @swarm_best[index].last, perfect, @swarm_speed[index]))
@swarm_best[index] = [@f.f(new_vector), new_vector] if is_best(@swarm_best[index].first, @f.f(new_vector))
@swarm_speed[index] = (new_vector - @swarm[index]).normalize
@swarm[index] = new_vector
end
end
end
end.each do |thread|
thread.join
end
perfect = perfect_particle
[@f.f(perfect), perfect]
end
|