# Getting Started with Optimization Toolbox

This sections discusses the main aspects on the usage of the tools for optimization in Cossan.

## Preliminary Remarks

The optimization toolbox of Cossan is intended for solving problems of the type:

min fobj(x)

subject to

$g_i(x)\leq0,~~~i=1,\ldots,n_i$

$g_j(x)=0,~~~j=1,\ldots,n_e$

$l_k \leq x_k \leq u_k ~~~j=1,\ldots,k=1,\ldots,n_D$

where:

• x: vector of design (or decision) variables, $x_k,~k=1,\ldots,n_D$. This vector groups those variables of the problem that can be changed in order to improve the value of the objective function.
• fobj(x): objective function. This function represents a certain quantity of interest that must be minimized. Typical examples of objective function are the weight of a structure, the cost of construction, the cost of operation, etc.
• gi(x) : inequality constraint. This function represents a constraint of the optimization problem, i.e. a condition that must be enforced at the optimal solution, in terms of an inequality. A typical example of a inequality constraint is, e.g. that the value of the stress in a structure should be below an admisible threshold level.
• gj(x) = 0: equality constraint. This function represents a constraint of the optimization problem, i.e. a condition that must be enforced at the optimal solution, in terms of an equality.

Note that the formulation of the optimization problem above covers also the case of maximization. That is, whenever there is a function to be maximized, the sought solution can be found by searching the minimum of the negative of the objective function.

## Solving a Problem with the Optimization Toolbox

The solution of a particular optimization problem can be carried out in three basic steps:

1. Definition of optimization problem.
2. Selection of an optimization algorithm.
3. Solution of optimization problem.

Each of these three steps is described in detail below

## Definition of Optimization Problem

The first step for solving a particular optimization problem is the definition of the problem itself. In Cossan-X, this means that the objective function, constraints, bound contraints and an initial guess of the optimal design must be defined. This is performed by creating an specialized object named OptimizationProblem.

In order to clarify the construction of the object OptimizationProblem, consider the following problem.

min $f_ {obj}(x)=x_1^2+x_2^2$

subject to

$g_1(x)=\frac{1}{x_1}-x_2\leq0$

$g_2(x)=-x_1^2+x_2\leq0$

In order to defined such problem, the first step is to create an Input object containing the design variables (x1 and x2 in this case).

Xin     = Input; %create empty Input object
X1      = Parameter('Sdescription','design variable 1','value',0); %define design variable x1 using a Parameter object
X2      = Parameter('Sdescription','design variable 2','value',0); %define design variable x2 using a Parameter object


Then, the objective function is created using a Function object.

Xfun1   = Function('Sdescription','objective function','Sexpression','(<&X1&>)^2+(<&X2&>)^2');


The next step is to create the constraints of the problem, using Function objects.

Xfun2   = Function('Sdescription','inequality constraint','Sexpression','2-<&X1&>-<&X2&>');
Xfun3   = Function('Sdescription','side constraint of X1','Sexpression','-<&X1&>');
Xfun4   = Function('Sdescription','side constraint of X2','Sexpression','-<&X2&>');


The initial guess of the optimal design can be set using a Parameter object.

Xinisol     = Parameter('Sdescription','initial solution','value',[-1 -1]);


Once all the arguments described above have been defined, it is possible to define the OptimizationProblem object.

Xop     = OptimizationProblem;     %create empty object
'Xfunction_inequalityconstraint',Xfun3,'Xfunction_inequalityconstraint',Xfun4,...
'Xparameter_initialsolution',Xinisol);


## Selection of an Optimization Algorithm

optimization algorithm. The selection of an optimization algorithm depends on the specific problem to be solved and the sought results. It should be noted that the selection of a specific optimization algorithm is crucial: is algorithm has its own properties that make it suitable for solving a specific class of problems.

Cossan-X offers 7 different Optimization algorithms. These algorithms and their capabilities are summarized below.

 Optimization Algorithm Gradient-based Efficiency Continuous design variables Discrete design variables Inequality Constraints Equality Constraints Bound constraints Robustness w.r.t. noisy functions Cross Entropy No low Yes No No No No / Genetic Algorithms No low Yes No Yes Yes Yes High No low Yes Yes Yes Yes Yes High COBYLA No medium Yes No Yes No No High Evolution Strategies No low Yes No No No No High Simulated Annealing No low Yes No Yes No No / SequentialQuadraticProgramming Yes high Yes No Yes Yes Yes None

In Cossan-X, a specific optimization algorithm is chosen when creating an object of an optimization class. For example, for solving a optimization problem using Cobyla, the following object must be created:@Optimizer

Xcob    = Cobyla('LKeepFiles',false);


The properties of the optimization algorithm are set by passing arguments in pairs, e.g.

Xoptim = name_of_optimizer('property 1',value of property 1,'property 2',value of property 2);


For an overview of the properties available for each optimization algorithm, it is referred to the Reference Manual

## Solution of Optimization Problem

Once the the optimization problem has been defined and the optimization algorithm has been selected, it is possible to solve the target optimization problem by invoking the command:

Xoutput = apply(Xoptimizer,'OptimizationProblem',Xoptimizationproblem)


where Xoptimizer is an Optimizer object, Xoptimizationproblem is the object containing the optimization problem and where Xoutput is an object containing the solution of the optimization problem.

## Examples on How to Use Optimization

Examples on how to use the optimization capabilities of Cossan-X can be found below.

• Optimization using Cobyla and SequentialQuadraticProgramming [1] [2]
• Optimization using GeneticAlgorithms [3] [4]
• Optimization using GeneticAlgorithmsMixedVariables [5]
• Optimization using CrossEntropy [6]
• Optimization using SimulatedAnnealing [7]
• Optimization using EvolutionStrategies [8]
• Solution of an optimization problem involving a third party FE solver [9]