Skip to content

Commit

Permalink
Add example for PSO showing how to set max_iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Mar 31, 2023
1 parent 4c0054f commit 87514c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions examples/example_pso.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from platypus import OMOPSO, DTLZ2

# define the problem
problem = DTLZ2()

# OMOPSO and SMPSO use a non-uniform mutation operator that scales down the magnitude of the mutations
# as the run progresses. Setting max_iterations controls how quickly the non-uniform mutation scales.
swarm_size = 100
max_iterations = 500

algorithm = OMOPSO(problem, epsilons = [0.01], swarm_size = swarm_size, max_iterations = max_iterations)
algorithm.run(swarm_size * max_iterations)

# display the results
for solution in algorithm.result:
print(solution.objectives)
2 changes: 1 addition & 1 deletion platypus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
from .types import *
from .weights import *

__version__ = "1.1.0" # Update setup.py if the version changes!
__version__ = "1.1.0"

0 comments on commit 87514c8

Please sign in to comment.