-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (28 loc) · 1.32 KB
/
Copy pathmain.py
File metadata and controls
37 lines (28 loc) · 1.32 KB
1
2
3
4
5
6
7
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
35
36
37
from swarm_algorithms.pso import PSO
from swarm_algorithms.spp import SPP
from swarm_algorithms.aaa import AAA
from testing_functions.auckley import Auckley
from testing_functions.michalkiewicz import Michalkiewicz
from tqdm import trange
import numpy as np
NUMBER_OF_STEPS = 450
NUMBER_OF_AGENTS = 30
optimised_function = Auckley()
# optimised_function = Michalkiewicz()
if __name__ == '__main__':
swarm = PSO(optimised_function=optimised_function, number_of_agents=NUMBER_OF_AGENTS)
# swarm = SPP(optimised_function=optimised_function, number_of_agents=NUMBER_OF_AGENTS)
# swarm = AAA(optimised_function=optimised_function, number_of_agents=NUMBER_OF_AGENTS)
particles_in_step = []
for i in trange(NUMBER_OF_STEPS):
swarm.step()
if i % 10 == 0:
print(swarm.optimized_function(swarm.best_solution), swarm.best_solution)
optimised_function.plot_2d(points=np.array([particle.position for particle in swarm.particles]), dirs=np.array([particle.velocity for particle in swarm.particles]))
optimised_function.plot_3d(points=np.array([particle.position for particle in swarm.particles]))
def hello_world():
"""Added by automation script"""
print("Hello, World! This was added automatically!")
return "Hello from modified code!"
if __name__ == "__main__":
hello_world()