Skip to content

Commit

Permalink
current
Browse files Browse the repository at this point in the history
  • Loading branch information
blankjul committed Nov 9, 2018
1 parent b950e12 commit f5efda5
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 170 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
recursive-include pymoo *.py *.pyx *.pxd
recursive-exclude pymoo *.so
recursive-include usage *.py *.pyx *.pxd
include LICENSE
82 changes: 19 additions & 63 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
pymoo - Multi-Objective Optimization
pymoo - Multi-Objective Optimization Framework
====================================================================

.. image:: https://gitlab.msu.edu/blankjul/pymoo/badges/master/pipeline.svg
:alt: pipeline status
:target: https://gitlab.msu.edu/blankjul/pymoo/commits/master


| You can find the detailed documentation `here <http://www.research-blank.de/pymoo>`_.
You can find the detailed documentation here:
https://www.egr.msu.edu/coinlab/blankjul/pymoo/


Requirements
Expand Down Expand Up @@ -104,47 +101,22 @@ Usage
.. code:: python
import time
import numpy as np
from pymoo.util.plotting import plot, animate
from pymop.problems.zdt import ZDT1
def run():
# create the optimization problem
problem = ZDT1()
start_time = time.time()
# solve the given problem using an optimization algorithm (here: nsga2)
from pymoo.optimize import minimize
res = minimize(problem,
method='nsga2',
method_args={'pop_size': 100},
termination=('n_gen', 200),
seed=1,
save_history=True,
disp=True)
F = res['F']
print("--- %s seconds ---" % (time.time() - start_time))
scatter_plot = True
save_animation = False
if scatter_plot:
plot(F, problem)
if save_animation:
H = np.concatenate([e['pop'].F[None, :, :] for e in res['history']], axis=0)
animate('%s.mp4' % problem.name(), H, problem)
if __name__ == '__main__':
run()
from pymoo.optimize import minimize
from pymoo.util import plotting
from pymop.factory import get_problem
# create the optimization problem
problem = get_problem("zdt1")
# solve the given problem using an optimization algorithm (here: nsga2)
res = minimize(problem,
method='nsga2',
method_args={'pop_size': 100},
termination=('n_gen', 200),
pf=problem.pareto_front(100),
save_history=False,
disp=True)
plotting.plot(res.F)
Contact
====================================================================
Expand All @@ -155,19 +127,3 @@ Feel free to contact me if you have any question:
| Computational Optimization and Innovation Laboratory (COIN)
| East Lansing, MI 48824, USA


Contributors
====================================================================
Julian Blank





Changelog
====================================================================
`0.2.1`
-------------------------

* First official release providing NSGA2, NSGA3 and RNSGA3
8 changes: 2 additions & 6 deletions pymoo/___experimental/experiment.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import time

import numpy as np

from pymoo.algorithms.nsga3 import NSGA3
from pymoo.emo.propose import ProposeReferenceLineSurvival
from pymoo.indicators.igd import IGD
from pymoo.model.termination import MaximumGenerationTermination
from pymoo.util.plotting import plot, animate
from pymoo.util.reference_direction import UniformReferenceDirectionFactory, MultiLayerReferenceDirectionFactory
from pymop import ScaledProblem, DTLZ3
from pymop.problems.dtlz import DTLZ1, DTLZ2, DTLZ4
from pymop import DTLZ3
from pymop.problems.dtlz import DTLZ1


def run():
Expand Down
2 changes: 2 additions & 0 deletions pymoo/___experimental/so_DE.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def __init__(self,
**kwargs):
set_default_if_none("real", kwargs)
super().__init__(**kwargs)


self.crossover = DifferentialEvolutionCrossover(prob=0.5, weight=0.75, variant="DE/best/1", method="binomial")
self.func_display_attrs = disp_single_objective

Expand Down
91 changes: 0 additions & 91 deletions pymoo/___experimental/yash_dtl1_5obj

This file was deleted.

21 changes: 18 additions & 3 deletions pymoo/algorithms/so_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,33 @@

class DifferentialEvolution(GeneticAlgorithm):
def __init__(self,
variant="DE/rand/1/exp",
CR=0.1,
F=0.75,
**kwargs):
set_default_if_none("real", kwargs)
super().__init__(**kwargs)
self.selection = RandomSelection()
self.crossover = DifferentialEvolutionCrossover(weight=0.75)
self.mutation = DifferentialEvolutionMutation("binomial", 0.1)

self.crossover = DifferentialEvolutionCrossover(weight=F)

_, self.var_selection, self.var_n, self.var_mutation, = variant.split("/")

self.mutation = DifferentialEvolutionMutation(self.var_mutation, CR)
self.func_display_attrs = disp_single_objective

def _next(self, pop):

# create offsprings and add it to the data of the algorithm
P = self.selection.do(pop, self.pop_size, self.crossover.n_parents)
if self.var_selection == "rand":
P = self.selection.do(pop, self.pop_size, self.crossover.n_parents)
elif self.var_selection == "best":
P = self.selection.do(pop, self.pop_size, self.crossover.n_parents - 1)
best = np.argmin(pop.get("F")[:, 0])
P = np.hstack([np.full(len(pop), best)[:, None], P])
else:
raise Exception("Unknown selection: %s" % self.var_selection)

off = self.crossover.do(self.problem, pop, P)
self.data = {**self.data, "off": off}

Expand Down
32 changes: 29 additions & 3 deletions pymoo/operators/mutation/real_differential_evoluation_mutation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pymoo.model.mutation import Mutation
from pymoo.rand import random

import numpy as np


class DifferentialEvolutionMutation(Mutation):
def __init__(self, variant, CR):
Expand All @@ -16,13 +18,37 @@ def _do(self, problem, pop, D=None, **kwargs):
_X = off.get("X")

# do the crossover
if self.variant == "binomial":
if self.variant == "bin":
# uniformly for each individual and each entry
r = random.random(size=(len(off), problem.n_var)) < self.CR

X[r] = _X[r]
return pop.new("X", X)
elif self.variant == "exp":

# start point of crossover
r = np.full((len(off), problem.n_var), False)

# start point of crossover
n = random.randint(0, problem.n_var, size=len(off))
# length of chromosome to do the crossover
L = random.random((len(off), problem.n_var)) < self.CR

# create for each individual the crossover range
for i in range(len(off)):
# the actual index where we start
start = n[i]
for j in range(problem.n_var):

# the current position where we are pointing to
current = (start + j) % problem.n_var

# replace only if random value keeps being smaller than CR
if L[i, current]:
r[i, current] = True
else:
break

else:
raise Exception("Unknown crossover type. Either binomial or exponential.")

X[r] = _X[r]
return pop.new("X", X)
2 changes: 2 additions & 0 deletions pymoo/util/experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def readme():

__name__ = "pymoo"
__author__ = "Julian Blank"
__version__ = '0.2.2.dev'
__version__ = '0.2.2'
__url__ = "https://github.com/msu-coinlab/pymoo"


Expand Down
8 changes: 5 additions & 3 deletions usage/de.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from pymoo.optimize import minimize
from pymop.factory import get_problem

problem = get_problem("rastrigin")
problem = get_problem("rastrigin", n_var=10)

res = minimize(problem,
method='de',
method_args={
'variant': "DE/best/1/bin",
'CR': 0.2,
'F': 1,
'pop_size': 100
},
termination=('n_gen', 200),
termination=('n_gen', 1000),
disp=True)

print("Best solution found: %s" % res.X)
print("Function value: %s" % res.F)

0 comments on commit f5efda5

Please sign in to comment.