# Optimizer

Model ElementOptimizer is an object that contains all the elements required for optimization.

## Class Name

Optimizer

## Attribute Summary

Name | Property | Modifiable by Command? | Designable |
---|---|---|---|

label | Str () | ||

objectives | Double () | Yes | |

method | Str () | ||

weights | Double (1.0E-3) | ||

eqConstraints | List () | Yes | |

ineqConstraints | List () | Yes | |

maxit | Int (50) | ||

accuracy | Double (1.0e-3) | No | |

dsa | Str () | ||

fdStep | Double (1.0e-6) | ||

type | Str () | ||

end | Double () | ||

dtout | Double () | ||

simFunction | Function () | ||

plot | Bool () |

## Usage

opt = Optimizer (objective=listOfResponses, optional_attributes)

## Attributes

`objectives`- List of response variable to be optimized.

`label`- Label for optimizer [String].
`type`- Analysis type [String].
`end`- End time for simulation [Double].
`dtout`- Output interval [Double].
`method`- Optimization method [String].
`weights`- List of weights for each response variable [Double].
`eqConstraints`- List of response variables names that form equality constraint. These responses would be equal to zero at the end of a successful optimization.
`ineqConstraints`- List of responses variables names which form inequality constraint. These responses would be greater than zero at the end of a successful optimization.
`simFunction`- A user defined function which can be used in optimization in place of
`type`+`end`+`dtout`. `maxit`- Maximum number of iterations [Int]
`accuracy`- Accuracy for terminating optimization [Double].
`dsa`- DSA type [String]. See Comment 1.
`fdStepType`- Determines how to compute step size for the Finite Difference Method.
Must be one of the following:
- “UNIFORM”
- “PROPORTIONAL”
- “AUTO”
- “AUTOUNIFORM”
- “AUTOPROPORTIONAL”

`fdStep`- The step-size to be used for sensitivity calculation using Finite
Difference Method; applicable only when
`dsa`="FD". This property will be ignored when fdStepType is “AUTO”, “AUTOACTUAL” or “AUTORELATIVE”. See Comment 4 for more details. `updatefdStep`- The number of iterations after which the step size of the Finite
Difference Method is updated. When specified, MotionSolve updates the step size by some method (determined by
`fdStepType`) during the optimization. `plot`- When set to True, plots of response variable values are produced during optimization.

## Example:

```
# Create an optimization object and start an optimization
def optimizationJob (self):
obj = [self.a2x, self.a2y, self.a2psi] # Define the 3 objectives
wt = [1, 1, 1] # Define the weights
opt = Optimizer ( # Define the optimizer
label = "Optimize RMS2", # Label
objective = obj, # Objectives
weights = wt, # Weights
type = "KINEMATICS", # Simulation Type
end = 2, # End Time
dtout = 0.01, # No. of steps
plot = True, # Display plots
dsa = "AUTO", # DSA type)
accuracy=1e-3
)
# Run an optimization
x = self.opt.optimize()
return x
```

## Comments:

- See Properties for an explanation about what properties are, why they are used, and how you can extend these.
- Types of
DSA
`dsa`= "AUTO" will select the best approach based on the problem.- If the number of design variables > number of responses, the Adjoint method is used.
- If the number of design variables < number of responses, the Direct method is used.
- If the analysis is of type Dynamics, the FD method is always used.
`dsa`= "DIRECT" selects the direct differentiation method for computing the design sensitivity matrix.`dsa`= "ADJOINT" selects the adjoint method for computing the design sensitivity matrix.`dsa`= "FD" selects the finite differencing method for computing the design sensitivity matrix. Finite differencing is done in parallel.

- After the completion of optimization run, the optimizer
returns the following values:
- status
- Exit mode for optimizer (see below).
- success
- Flag showing if the optimizer converged successfully or not (True/False).
- njev
- Total number of iterations.
- nfev
- Number of function evaluations.
- fun
- Final cost of the function.
- x
- List of optimized design variable values (array).
- message
- Exit code message (see below).
- jac
- Jacobian of the optimized design variables to each response (array).
- nit
- Number of gradient evaluations.

Exit modes are defined as follows:- -1
- Gradient evaluation required (g & a).
- 0
- Optimization terminated successfully.
- 1
- Function evaluation required (f & c).
- 2
- More equality constraints than independent variables.
- 3
- More than 3*n iterations in LSQ sub-problem.
- 4
- Inequality constraints incompatible.
- 5
- Singular matrix E in LSQ sub-problem.
- 6
- Singular matrix C in LSQ sub-problem.
- 7
- Rank-deficient equality constraint sub-problem HFTI.
- 8
- Positive directional derivative for linesearch.
- 9
- Iteration limit exceeded.
- 10
- Error happened getting objective function value.
- 11
- Error happened getting gradient value of objective function.
- 12
- Approaching close enough to local convergence with current boundary.

See the Multibody Optimization User's Guide in the MotionSolve User's Guide for usage.

- There are five approaches available to compute step size for the Finite
Difference Method:
- UNIFORM
- Uniform step size is used for all Dvs. For each Dv, the perturbation is Δ= fdStep.
- PROPORTIONAL
- The step size for each Dv is proportional to its magnitude. For
Dv
_{i}, the perturbation is Δ= fdStep * max (1.0, Dv_{i}|)|. - AUTO
- Use optimal step size for each Dv. MotionSolve has an internal routine to compute the optimal step size for each Dv based on the local error and an estimation of the second derivative. The sensitivity computed by this approach is the most accurate but it introduces additional computational cost. You might want to consider “AUTOACTUAL” or “AUTORELATIVE” when the additional cost is unacceptable for you.
- AUTOUNIFORM
- MotionSolve computes the optimal step size on the first Dv. Other Dvs use the same step size.
- AUTOPROPORTIONAL
- MotionSolve computes the optimal step size on the first Dv. The step sizes of the other Dvs are proportional to their magnitudes.