forked from anyoptimization/pymoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into develop
- Loading branch information
Showing
335 changed files
with
13,646 additions
and
14,398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
**/.vscode | ||
**/.mp4 | ||
**/.npy | ||
**/.gif | ||
|
||
|
||
# Byte-compiled / optimized / DLL files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
Oops, something went wrong.