Skip to content

Commit

Permalink
Merge pull request #75 from bluescarni/nlopt_auglag
Browse files Browse the repository at this point in the history
Nlopt auglag + missing serialization
  • Loading branch information
bluescarni authored Apr 12, 2017
2 parents 6906f8e + 48c5010 commit eece215
Show file tree
Hide file tree
Showing 15 changed files with 824 additions and 269 deletions.
3 changes: 3 additions & 0 deletions doc/sphinx/docs/cpp/miscellanea/type_traits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ Type traits and enums used in PaGMO
.. doxygenclass:: pagmo::override_has_set_seed
:members:

.. doxygenclass:: pagmo::has_run_evolve
:members:

.. doxygenclass:: pagmo::is_udi
:members:
Binary file modified doc/sphinx/docs/images/nlopt_basic_lv1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 17 additions & 16 deletions doc/sphinx/docs/python/algorithms/py_algorithms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ Heuristic Optimization
========================================================== ========================================= =============== ===================================================================
Common Name Name in PyGMO Type Comments
========================================================== ========================================= =============== ===================================================================
The null algorithm :class:`pygmo.null_algorithm` SM-CU Exposed from C++, Used for testing purposes, does nothing
The null algorithm :class:`pygmo.null_algorithm` SM-CU Exposed from C++, used for initialization purposes, does nothing
Differential Evolution (DE) :class:`pygmo.de` S-U Exposed from C++
Self-adaptive DE (jDE and iDE) :class:`pygmo.sade` S-U Exposed from C++
Self-adaptive DE (de_1220 aka pDE) :class:`pygmo.de1220` S-U Exposed from C++
Particle Swarm Optimization (PSO) :class:`pygmo.pso` S-U Exposed from C++
(N+1)-ES Simple Evolutionary Algorithm :class:`pygmo.sea` S-U (sto) Exposed from C++
Corana's Simulated Annealing (SA) :class:`pygmo.sa_corana` S-U Exposed from C++
Corana's Simulated Annealing (SA) :class:`pygmo.simulated_annealing` S-U Exposed from C++
Artificial Bee Colony (ABC) :class:`pygmo.bee_colony` S-U Exposed from C++
Covariance Matrix Adaptation Evo. Strategy (CMA-ES) :class:`pygmo.cmaes` S-U Exposed from C++
Non-dominated Sorting GA (NSGA2) :class:`pygmo.nsga_II` M-U Exposed from C++
Non-dominated Sorting GA (NSGA2) :class:`pygmo.nsga2` M-U Exposed from C++
Multi-objective EA vith Decomposition (MOEA/D) :class:`pygmo.moead` M-U Exposed from C++
========================================================== ========================================= =============== ===================================================================

Expand All @@ -43,19 +43,20 @@ Local optimization
====================================================== ========================================= =============== =====================================================================
Common Name Name in PyGMO Type Comments
====================================================== ========================================= =============== =====================================================================
Compass Search (CS) :class:`pygmo.cs` S-CU Exposed from C++
COBYLA (from nlopt) :class:`pygmo.nlopt` S-CU Exposed from C++
BOBYQA (from nlopt) :class:`pygmo.nlopt` S-U Exposed from C++
NEWUOA + bound constraints (from nlopt) :class:`pygmo.nlopt` S-U Exposed from C++
PRAXIS (from nlopt) :class:`pygmo.nlopt` S-U Exposed from C++
Nelder-Mead simplex (from nlopt) :class:`pygmo.nlopt` S-U Exposed from C++
sbplx (from nlopt) :class:`pygmo.nlopt` S-U Exposed from C++
MMA (Method of Moving Asymptotes) (from nlopt) :class:`pygmo.nlopt` S-CU Exposed from C++
CCSA (from nlopt) :class:`pygmo.nlopt` S-CU Exposed from C++
SLSQP (from nlopt) :class:`pygmo.nlopt` S-CU Exposed from C++
low-storage BFGS (from nlopt) :class:`pygmo.nlopt` S-U Exposed from C++
preconditioned truncated Newton (from nlopt) :class:`pygmo.nlopt` S-U Exposed from C++
shifted limited-memory variable-metric (from nlopt) :class:`pygmo.nlopt` S-U Exposed from C++
Compass Search (CS) :class:`pygmo.compass_search` S-CU Exposed from C++
COBYLA (from NLopt) :class:`pygmo.nlopt` S-CU Exposed from C++
BOBYQA (from NLopt) :class:`pygmo.nlopt` S-U Exposed from C++
NEWUOA + bound constraints (from NLopt) :class:`pygmo.nlopt` S-U Exposed from C++
PRAXIS (from NLopt) :class:`pygmo.nlopt` S-U Exposed from C++
Nelder-Mead simplex (from NLopt) :class:`pygmo.nlopt` S-U Exposed from C++
sbplx (from NLopt) :class:`pygmo.nlopt` S-U Exposed from C++
MMA (Method of Moving Asymptotes) (from NLopt) :class:`pygmo.nlopt` S-CU Exposed from C++
CCSA (from NLopt) :class:`pygmo.nlopt` S-CU Exposed from C++
SLSQP (from NLopt) :class:`pygmo.nlopt` S-CU Exposed from C++
low-storage BFGS (from NLopt) :class:`pygmo.nlopt` S-U Exposed from C++
preconditioned truncated Newton (from NLopt) :class:`pygmo.nlopt` S-U Exposed from C++
Shifted limited-memory variable-metric (from NLopt) :class:`pygmo.nlopt` S-U Exposed from C++
Augmented Lagrangian algorithm (from NLopt) :class:`pygmo.nlopt` S-CU Exposed from C++
====================================================== ========================================= =============== =====================================================================

----------------------------------------------------------------------------------------------------------------------
Expand Down
72 changes: 36 additions & 36 deletions doc/sphinx/docs/python/tutorials/nlopt_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A first tutorial on the use of NLopt solvers

In this tutorial we show the basic usage pattern of :class:`pygmo.nlopt`. This user defined
algorithm (UDA) wraps the NLopt library making it easily accessible via the pygmo common
:class:`pygmo.algorithm` interface. Let see how this miracle occur.
:class:`pygmo.algorithm` interface. Let us see how this miracle occurs.

I have the gradient
^^^^^^^^^^^^^^^^^^^
Expand All @@ -15,12 +15,13 @@ I have the gradient
>>> import pygmo as pg
>>> uda = pg.nlopt("slsqp")
>>> algo = pg.algorithm(uda)
>>> print(algo) # doctest: +NORMALIZE_WHITESPACE
>>> print(algo) # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
Algorithm name: NLopt - slsqp [deterministic]
Thread safety: basic
<BLANKLINE>
Extra info:
NLopt version: 2.4.2
NLopt version: ...
Solver: 'slsqp'
Last optimisation return code: NLOPT_SUCCESS (value = 1, Generic success return value)
Verbosity: 0
Individual selection policy: best
Expand All @@ -36,9 +37,9 @@ I have the gradient
<BLANKLINE>


In a few lines we have constructed a :class:`pygmo.algorithm` containing the slsqp solver from
In a few lines we have constructed a :class:`pygmo.algorithm` containing the ``"slsqp"`` solver from
NLopt. For a list of solvers availbale via the NLopt library check the docs of :class:`~pygmo.nlopt`.
In this tutorial we will make use of slsqp, a Sequential Quadratic Programming algorithm suited for
In this tutorial we will make use of ``"slsqp"``, a Sequential Quadratic Programming algorithm suited for
generic Non Linear Programming problems (i.e. non linearly constrained single objective problems).

All the stopping criteria used by the NLopt library are available via dedicated attributes, so that we may, for
Expand All @@ -55,7 +56,7 @@ Let us algo activate some verbosity as to store a log and have a screen output:
>>> algo.set_verbosity(1)

We now need a problem to solve. Let us start with one of the UDPs provided in pygmo. The
:class:`pygmo.luksan_vlcek1` provides a classic, scalable, equally constrained problem. It
:class:`pygmo.luksan_vlcek1` problem is a classic, scalable, equality-constrained problem. It
also has its gradient implemented so that we do not have to worry about that for the moment.

.. doctest::
Expand All @@ -72,40 +73,35 @@ The lines above can be shortened and are equivalent to:
>>> pop = pg.population(pg.luksan_vlcek1(dim = 20), size = 1)
>>> pop.problem.c_tol = [1e-8] * pop.problem.get_nc()

.. image:: ../../images/nlopt_basic_lv1.png
:scale: 80 %
:alt: slsqp performance
:align: right

We now solve this problem by writing:

.. doctest::

>>> pop = algo.evolve(pop) # doctest: +SKIP
fevals: fitness: violated: viol. norm:
1 250153 18 2619.51 i
2 132280 18 931.767 i
3 26355.2 18 357.548 i
4 14509 18 140.055 i
5 77119 18 378.603 i
6 9104.25 18 116.19 i
7 9104.25 18 116.19 i
8 2219.94 18 42.8747 i
9 947.637 18 16.7015 i
10 423.519 18 7.73746 i
11 82.8658 18 1.39111 i
12 34.2733 15 0.227267 i
13 11.9797 11 0.0309227 i
14 42.7256 7 0.27342 i
15 1.66949 11 0.042859 i
16 1.66949 11 0.042859 i
17 0.171358 7 0.00425765 i
18 0.00186583 5 0.000560166 i
19 1.89265e-06 3 4.14711e-06 i
20 1.28773e-09 0 0
21 7.45125e-14 0 0
22 3.61388e-18 0 0
23 1.16145e-23 0 0
objevals: objval: violated: viol. norm:
1 250153 18 2619.51 i
2 132280 18 931.767 i
3 26355.2 18 357.548 i
4 14509 18 140.055 i
5 77119 18 378.603 i
6 9104.25 18 116.19 i
7 9104.25 18 116.19 i
8 2219.94 18 42.8747 i
9 947.637 18 16.7015 i
10 423.519 18 7.73746 i
11 82.8658 18 1.39111 i
12 34.2733 15 0.227267 i
13 11.9797 11 0.0309227 i
14 42.7256 7 0.27342 i
15 1.66949 11 0.042859 i
16 1.66949 11 0.042859 i
17 0.171358 7 0.00425765 i
18 0.00186583 5 0.000560166 i
19 1.89265e-06 3 4.14711e-06 i
20 1.28773e-09 0 0
21 7.45125e-14 0 0
22 3.61388e-18 0 0
23 1.16145e-23 0 0
<BLANKLINE>
Optimisation return status: NLOPT_XTOL_REACHED (value = 4, Optimization stopped because xtol_rel or xtol_abs was reached)

Expand All @@ -118,9 +114,13 @@ shown here.
>>> from matplotlib import pyplot as plt # doctest: +SKIP
>>> plt.semilogy([line[0] for line in log], [line[1] for line in log], label = "obj") # doctest: +SKIP
>>> plt.semilogy([line[0] for line in log], [line[3] for line in log], label = "con") # doctest: +SKIP
>>> plt.xlabel("fevals") # doctest: +SKIP
>>> plt.xlabel("objevals") # doctest: +SKIP
>>> plt.ylabel("value") # doctest: +SKIP
>>> plt.show() # doctest: +SKIP

.. image:: ../../images/nlopt_basic_lv1.png
:scale: 100 %
:alt: slsqp performance

I do not have the gradient
^^^^^^^^^^^^^^^^^^^^^^^^^^
Loading

0 comments on commit eece215

Please sign in to comment.