A framework for optimization.
Project description
Optimization Framework
This is a framework for linear and nonlinear optimization developed by ENACOM Group.
It solves a problem in the form:
min f(x)
s.t. g(x) <= 0
h(x) = 0
x_min <= x <= x_max
where x
is an ndimensional vector, f(x)
maps the ndimensional space to the odimensional space,
with o
being the number of objectives.
Prerequisites
What you need to be able to run:
 Python 3.6 +
All requirements are in the file requirements.txt
.
To install all packages at once:
$ pip install r requirements.txt
Installing scienceoptimization
Building scienceoptimization requires the following software installed:
 Python 3
 Make sure that distutils is installed before continuing. For example in Debian GNU/Linux, disutils is included in the python3dev package.
 PyBind11
 Note that this is PyBind11, not PyBind.
 GNU C Compiler version >= 5.0
To install the package in any environment:
 clone this repo
$ pip install ./scienceoptimization
Conventions
Development

In Python programming, it is a common practice to initialize "private" methods/attributes with an underscore (e.g. _private_method(), _private_attribute). This framework follows this convention

Attributes sets and gets are implemented using the native
@property
decorator 
An abstract base class inherits from
abc.ABCMeta

Google is the default Docstring format

A package must contain an
__init__.py
file with the package initialization 
PyCharm 2017+ is highly recommended
A detailed explanation of code development can be found here and here.
Tutorials on Python programming can be found here.
Optimization
Given that n
is the problem dimension and m
is the number of points:

A single point is a
nx1
matrix 
Multiple points are a
nxm
matrix 
Gradient is a
nxm
matrix 
Hessian is a
nxnxm
matrix
Packages
Builder
This package is responsible for building an optimization problem. It was built based on the Builder Design Pattern and it has the following classes.

OptimizationProblem()
: the base class of every optimization problem.
Attributes:

objective
:Objective()
instance 
constraints
:Contraints()
instance 
variables
:Variables()
instance


Methods:

_build_problem(builder)
: receives aBuilderOptimizationProblem()
instance, checks problem consistency and sets attributes 
_check_consistency(variables, objectives, constraints)
: receives attributes and check problem consistency 
info()
: prints to user the assembled problem 
__call__()
: overloaded method that turns anOptimizationProblem
instance a callable function, that evaluatesf, g, h, df, dg, dh, hf, hg, hh
for a given pointx



BuilderOptimizationProblem()
: abstract class responsible for defining the builder's methods of the optimization problem.
Abstract methods:

build_objectives()
: abstract method responsible for building the problem's objectives 
build_constraints()
: abstract method responsible for building the problem's constraints 
build_variables()
: abstract method responsible for building the problem's variables



Objective()
: container class of objectives functions.
Attributes:
objective_functions
: a list with all functions of the problem. Each function is aFunctionComposite()
instance.

Methods:

C()
: return the matrix C of linear objectives coefficients 
d()
: return the vector d of linear objectives constants



Contraints()
: container class of constraints functions.
Attributes:

equality_contraints
: a list with equality constraints functions. Each function is aFunctionComposite()
instance. 
inequality_contraints
: a list with inequality constraints functions. Each function is aFunctionComposite()
instance.


Methods:

equality_contraints_feasibility(x)
: evaluates the feasibility ofx
on these constraints 
inequality_contraints_feasibility(x)
: evaluates the feasibility ofx
on these constraints 
A()
: returns the matrixA
of linear inequality constraints coefficients 
b()
: returns the vectorb
of linear inequality constraints bounds 
Aeq()
: returns the matrixAeq
of linear equality constraints coefficients 
beq()
: returns the vectorbeq
of linear equality constraints bounds



Variables()
: container class of the problem variables.
Attributes:

x_min
: variables' lower bounds 
x_max
: variables' upper bounds 
x_type
: list with variables' type ('c': continuous or 'd': discrete)


Function
This package has the definitions of a function. Is was base on the Composite design pattern and contains the following classes:

BaseFunction()
: base class of every other class inside this package.
Attributes:

parameters
: abstract attribute for functions parameters (e.g. coefficients) 
eps
: precision for numerical calculations


Methods:

eval(x)
: abstract method for the evaluation ofx

gradient(x)
: numerical calculation of the Gradient ofx

hessian(x)
: numerical calculation of the Hessian ofx

dimension()
: function dimensionn



FunctionsComposite()
: container class ofBaseFunction()
's children.
Attributes:
functions
: a list of functions

Methods:

eval(x)
: abstract method for the evaluation ofx
infunctions

gradient(x)
: numerical calculation of the Gradient ofx
infunctions

hessian(x)
: numerical calculation of the Hessian ofx
infunctions

add(f)
: adds functionf
tofunctions

remove(idx)
: removes elementfunctions[idx]

clear()
: removes all functions from list



LinearFunction()
: implements a function in the formf(x) = c'x + d

Attributes:
parameters
: dictionary withc
andd
keys

Methods:

eval(x)
: method for the evaluation ofx

gradient(x)
: analytical calculation of the Gradient ofx

hessian(x)
: analytical calculation of the Hessian ofx



QuadraticFunction()
: implements a function in the formf(x) = x'Qx + c'x + d

Attributes:
parameters
: dictionary withQ
,c
andd
keys

Methods:

eval(x)
: method for the evaluation ofx

gradient(x)
: analytical calculation of the Gradient ofx

hessian(x)
: analytical calculation of the Hessian ofx



PolynomialFunction()
: implements a polynomial function
Attributes:
parameters
: dictionary with exponentse
andc
coefficients

Methods:

eval(x)
: method for the evaluation ofx

gradient(x)
: analytical calculation of the Gradient ofx

hessian(x)
: analytical calculation of the Hessian ofx


Problems
This package is responsible for creating the interface of BuilderOptimizationProblem()
for each optimization problem
instance. The classes must follow the format:

Problem(BuilderOptimizationProblem)
: inherits from BuilderOptimizationProblem
Attributes: necessary problem attributes

Methods:

build_objectives()
: concrete method responsible for building the problem's objectives 
build_constraints()
: concrete method responsible for building the problem's constraints 
build_variables()
: concrete method responsible for building the problem's variables


The class Generic(BuilderOptimizationProblem)
builds a generic optimization problem in the canonical
format defined at the beginning of this document. However, it also possible to implement customized
optimization problems inheriting from BuilderOptimizationProblem
class, such as Diet
and KleeMinty
.
For linear programming, the problem MIP
is a straightforward abstraction of a problem in the format:
min c' @ x
s.t. A @ x <= b
Aeq @ x == beq
x_min <= x <= x_max
Algorithms
This package contains the implementations of the optimization algorithms. It is organized in subpackages according
to algorithm's families. Each subpackage contains one abstract implementation of the algorithm's family, it is named
BaseAlgorithmFamily()

BaseAlgorithms()
: base class for everyBaseAlgorithmFamily()

Attributes:
eps
: algorithms' numerical precision

Methods:
optimize()
: abstract method for the implementation core

This framework currently supports the following optimization algorithms:

Cuttingplane family:
 Ellipsoidal (Multiobjective)

Decomposition :
 Nonlinear dual decomposition

Derivativefree :
 NelderMead simplex (constrained)

Lagrange (constrained):
 Augmented lagrangian method (using Quasi Newton)

Linear programming:
 Scipy simplex and interiorpoint
 GLOP for LP
 CBC for MIP

Unidimensional search:
 Enhanced golden section
 Multimodal golden section

Search direction family (unconstrained):
 Gradient method
 Modified Newton method
 Quasi Newton method
Solvers
This package contains the interface to optimization solvers implemented in the framework.

Optimizer()
: optimization for builtin methods, i.e.algorithms
.
Attributes

optimization_problem
:OptimizationProblem()
instance 
algorithm
: a concrete algorithm implementation instance (e.g.GradientAlgorithm()
)


Methods
solve
: implementsalgorithm.optimize()


OptimizationResults()
: container for optimization results
Attributes

x
: the solution of the optimization 
fx
: function value at solution point 
sucess
: whether or not the solvers exited successfully 
message
: description of the cause of termination 
n_iterations
: number of iterations 
n_function_evaluations
: number of function evaluations


Methods
info()
: displays optimization results info.


pareto_samplers package
: used to find the pareto border of a multiobjective problem, the implemented sampling strategies are: Lambda sampler
 Epsilon sampler
 Nondominated sampler
 Mu sampler
Examples
This package contains modules implementing examples of building and solving an optimization problem. It can also
be used for profiling via @profiling
decorator.
Profiling
Implementation of the @profiling
decorator.
Project details
Release history Release notifications  RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for science_optimization8.0.1.tar.gz
Algorithm  Hash digest  

SHA256  499069e600fc282901cb00ff6e15b485045069def59e6ac4a47f7d3f534b30e0 

MD5  81ebd76e2ad866620009f85814a9e140 

BLAKE2b256  f7ed7908601cfa0cd9885ce9f716dd99a2491d74646f1bf53baaced712aa8186 
Hashes for science_optimization8.0.1cp38cp38manylinux_2_31_x86_64.whl
Algorithm  Hash digest  

SHA256  b1a5cc34fb59abc7bc72499ba85ae6468a579bc67ff84182774b7d3d10f09172 

MD5  fa575857f3836c2319b08dc3857ee4ea 

BLAKE2b256  78054848168918824dd130da130e3f1394e56c063da937812f992db5ff83ac2b 