Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
blankjul committed Jun 18, 2022
2 parents c2a4cbd + cb1a1dd commit 7f538c4
Show file tree
Hide file tree
Showing 335 changed files with 13,646 additions and 14,398 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Python 3
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.10
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install Python 3
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.10
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -36,12 +36,14 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9']
python-version: ['3.7', '3.8', '3.9', '3.10']
exclude:
- os: ubuntu-latest
python-version: '3.7'
- os: ubuntu-latest
python-version: '3.8'
- os: ubuntu-latest
python-version: '3.9'
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand Down Expand Up @@ -70,7 +72,7 @@ jobs:
- uses: actions/checkout@v2
- uses: RalfG/[email protected]_x86_64
with:
python-versions: 'cp37-cp37m cp38-cp38 cp39-cp39'
python-versions: 'cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310'
build-requirements: 'cython numpy'
pip-wheel-args: '-w ./dist --no-deps'
- name: Remove non-compatible packages
Expand All @@ -93,7 +95,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.10'
- name: Publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
**/.vscode
**/.mp4
**/.npy
**/.gif


# Byte-compiled / optimized / DLL files
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ However, for instance, executing NSGA2:
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.factory import get_problem
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter
Expand Down
Binary file added animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added examples/__init__.py
Empty file.
Empty file added examples/algorithms/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions examples/algorithms/ask_and_tell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pymoo.algorithms.soo.nonconvex.pso import PSO
from pymoo.core.problem import Problem
from pymoo.core.termination import NoTermination
from pymoo.problems.static import StaticProblem

problem = Problem(n_var=10, n_obj=1, n_ieq_constr=0, xl=-0, xu=1)

algorithm = PSO().setup(problem, termination=NoTermination(), verbose=False)

for k in range(20):

if not algorithm.has_next():
break

infills = algorithm.ask()

X = infills.get("X")

F = (X ** 2).sum(axis=1)
G = - (X[:, 0] + X[:, 1]) - 0.3

algorithm.evaluator.eval(StaticProblem(problem, F=F, G=G), infills)

algorithm.tell(infills=infills)

print(k + 1, algorithm.opt[0].F[0])

print(algorithm.opt.get("F"))
35 changes: 35 additions & 0 deletions examples/algorithms/callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import matplotlib.pyplot as plt
import numpy as np

from pymoo.algorithms.soo.nonconvex.ga import GA
from pymoo.problems import get_problem
from pymoo.core.callback import Callback
from pymoo.optimize import minimize


class MyCallback(Callback):

def __init__(self) -> None:
super().__init__()
self.data["best"] = []

def update(self, algorithm):
self.data["best"].append(algorithm.pop.get("F").min())


problem = get_problem("sphere")

algorithm = GA(pop_size=100)

res = minimize(problem,
algorithm,
('n_gen', 20),
seed=1,
callback=MyCallback(),
save_history=True,
verbose=True)

val = res.algorithm.callback.data["best"]
plt.plot(np.arange(len(val)), val)
plt.show()

35 changes: 35 additions & 0 deletions examples/algorithms/custom_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np

from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.util.display.column import Column
from pymoo.util.display.output import Output


class MyOutput(Output):

def __init__(self):
super().__init__()
self.columns["x-mean"] = Column(13)
self.columns["x-std"] = Column(13)
self.active += ["x-mean", "x-std"]

def update(self, algorithm):
super().update(algorithm)

X = algorithm.pop.get("X")
self.columns["x-mean"].value = np.mean(X)
self.columns["x-std"].value = np.std(X)


problem = get_problem("zdt2")

algorithm = NSGA2(pop_size=100)

res = minimize(problem,
algorithm,
('n_gen', 10),
seed=1,
output=MyOutput(),
verbose=True)
29 changes: 29 additions & 0 deletions examples/algorithms/custom_output_lambda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import numpy as np

from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.util.display.column import Column
from pymoo.util.display.output import Output


class MyOutput(Output):

def __init__(self):
super().__init__()
self.x_mean = Column("x_mean", width=13, func=lambda algorithm: np.mean(algorithm.pop.get("X")))
self.x_std = Column("x_std", width=13, func=lambda algorithm: np.std(algorithm.pop.get("X")))
self.columns += [self.x_mean, self.x_std]

problem = get_problem("zdt2")

algorithm = NSGA2(pop_size=100)

res = minimize(problem,
algorithm,
('n_gen', 10),
seed=1,
output=MyOutput(),
verbose=True)


17 changes: 17 additions & 0 deletions examples/algorithms/initial_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy as np

from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.problems import get_problem
from pymoo.optimize import minimize

problem = get_problem("zdt2")

X = np.random.random((300, problem.n_var))

algorithm = NSGA2(pop_size=100, sampling=X)

minimize(problem,
algorithm,
('n_gen', 10),
seed=1,
verbose=True)
24 changes: 24 additions & 0 deletions examples/algorithms/initial_evaluated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import numpy as np

from pymoo.algorithms.soo.nonconvex.ga import GA
from pymoo.problems import get_problem
from pymoo.core.evaluator import Evaluator
from pymoo.core.population import Population
from pymoo.optimize import minimize

problem = get_problem("sphere")

X = np.random.random((500, problem.n_var))

pop = Population.empty(len(X))
pop.set("X", X)
Evaluator().eval(problem, pop)

algorithm = GA(sampling=pop)

res = minimize(problem,
algorithm,
seed=1,
verbose=True)

print("Best solution found: \nX = %s\nF = %s" % (res.X, res.F))
22 changes: 22 additions & 0 deletions examples/algorithms/initial_pop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import numpy as np

from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.problems import get_problem
from pymoo.core.evaluator import Evaluator
from pymoo.core.population import Population
from pymoo.optimize import minimize

problem = get_problem("zdt2")

# create initial data and set to the population object
X = np.random.random((300, problem.n_var))
pop = Population.new("X", X)
Evaluator().eval(problem, pop)

algorithm = NSGA2(pop_size=100, sampling=pop)

minimize(problem,
algorithm,
('n_gen', 10),
seed=1,
verbose=True)
20 changes: 20 additions & 0 deletions examples/algorithms/loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.problems import get_problem
from pymoo.termination import get_termination
from pymoo.visualization.scatter import Scatter

problem = get_problem("zdt1")

algorithm = NSGA2(pop_size=100)

algorithm.setup(problem, termination=get_termination('n_gen', 200), verbose=True)

while algorithm.has_next():
algorithm.next()

res = algorithm.result()

plot = Scatter()
plot.add(problem.pareto_front(), plot_type="line", color="black", alpha=0.7)
plot.add(res.opt.get("F"), color="red")
plot.show()
Empty file.
20 changes: 20 additions & 0 deletions examples/algorithms/moo/age.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pymoo.algorithms.moo.age import AGEMOEA
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter

problem = get_problem("tnk")

algorithm = AGEMOEA()

res = minimize(problem,
algorithm,
('n_gen', 200),
seed=1,
verbose=True)

plot = Scatter()
plot.add(problem.pareto_front(), plot_type="line", color="black", alpha=0.7)
plot.add(res.F, color="red")
plot.show()

21 changes: 21 additions & 0 deletions examples/algorithms/moo/age2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pymoo.algorithms.moo.age import AGEMOEA
from pymoo.algorithms.moo.age2 import AGEMOEA2
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter

problem = get_problem("zdt1")

algorithm = AGEMOEA2()

res = minimize(problem,
algorithm,
('n_gen', 200),
seed=1,
verbose=True)

plot = Scatter()
plot.add(problem.pareto_front(), plot_type="line", color="black", alpha=0.7)
plot.add(res.F, color="red")
plot.show()

21 changes: 21 additions & 0 deletions examples/algorithms/moo/ctaea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pymoo.algorithms.moo.ctaea import CTAEA

from pymoo.optimize import minimize
from pymoo.problems.multi import Carside
from pymoo.util.ref_dirs import get_reference_directions
from pymoo.visualization.scatter import Scatter

problem = Carside()

ref_dirs = get_reference_directions("das-dennis", 3, n_partitions=12)

algorithm = CTAEA(ref_dirs=ref_dirs)

res = minimize(problem,
algorithm,
('n_gen', 600),
seed=1,
verbose=True
)

Scatter().add(res.F, facecolor="none", edgecolor="red").show()
21 changes: 21 additions & 0 deletions examples/algorithms/moo/moead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pymoo.algorithms.moo.moead import MOEAD, ParallelMOEAD
from pymoo.optimize import minimize
from pymoo.problems import get_problem
from pymoo.util.ref_dirs import get_reference_directions
from pymoo.visualization.scatter import Scatter

problem = get_problem("dtlz2")

ref_dirs = get_reference_directions("das-dennis", 3, n_partitions=12)

algorithm = MOEAD(
ref_dirs,
n_neighbors=15,
prob_neighbor_mating=0.7,
seed=1,
verbose=False
)

res = minimize(problem, algorithm, termination=('n_gen', 200), verbose=True)

Scatter().add(res.F).show()
Empty file.
19 changes: 19 additions & 0 deletions examples/algorithms/moo/nsga2/nsga2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.problems import get_problem
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter

problem = get_problem("bnh")

algorithm = NSGA2(pop_size=100)

res = minimize(problem,
algorithm,
seed=1,
verbose=True)

plot = Scatter()
plot.add(problem.pareto_front(), plot_type="line", color="black", alpha=0.7)
plot.add(res.F, facecolor="none", edgecolor="red")
plot.show()

Loading

0 comments on commit 7f538c4

Please sign in to comment.