# NOT RUN {
# If you use the Particle Swarm Object there is no need to manually create the Particle
# But if you want to use the Particle for another project:
# In this example we use the PSO to solve the following equation:
# a * 5 + b * 25 + 10 = 15
fitness_function <- function(values){
a <- values[1]
b <- values[2]
particule_result <- a*5 + b*25 + 10
difference <- 15 - particule_result
fitness <- 1 - abs(difference)
return(fitness)
}
values_ranges <- list(c(-10^3,10^3),c(-10^3,10^3))
particle_example <- Particle$new(values_ranges = values_ranges,
values = c(0,0),
fitness_function = fitness_function,
acceleration_coefficient = c(0.5,0.5),
inertia = 0.4)
print(particle_example)
particle_example$get_fitness()
print(particle_example)
particle_example$update(c(10,25))
print(particle_example)
# }
Run the code above in your browser using DataLab