OP  0.1
OP is a optimization solver plugin package
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends
Public Member Functions | Protected Attributes | Friends | List of all members
op::NLopt< T > Class Template Reference

A op::optimizer implementation for NLopt. More...

#include <nlopt_op.hpp>

Collaboration diagram for op::NLopt< T >:
Collaboration graph
[legend]

Public Member Functions

 NLopt (op::Vector< std::vector< double >> &variables, NLoptOptions &o, std::optional< MPI_Comm > comm={}, std::optional< op::utility::CommPattern< T >> comm_pattern_info={})
 Constructor for our optimizer.
 
 num_local_owned_variables_ (0)
 
void setObjective (op::Functional &o) override
 Sets the optimization objective. More...
 
void addConstraint (op::Functional &o) override
 Adds a constraint for the optimization problem. More...
 
bool variables_changed (const std::vector< double > &x)
 Method to see if variables changed, if they have set new x. More...
 
bool isAdvanced ()
 returns whether NLopt is in "advanced" mode or not
 
auto generateReducedLocalGradientFunction (std::function< std::vector< double >(const std::vector< double > &)> local_grad_func, std::function< double(const std::vector< double > &)> local_reduce_func)
 generates reduced local gradient using comm_pattern_
 
- Public Member Functions inherited from op::Optimizer
 Optimizer ()
 Ctor has deferred initialization.
 
 iterate ([](){})
 
 save ([](){})
 
 final_obj (std::numeric_limits< double >::max())
 
void Go ()
 Start the optimization.
 
void UpdatedVariableCallback ()
 What to do when the variables are updated.
 
virtual double Solution ()
 What to do when the solution is found. Return the objetive.
 
void Iteration ()
 What to do at the end of an optimization iteration.
 
void SaveState ()
 Saves the state of the optimizer.
 
virtual ~Optimizer ()=default
 Destructor.
 

Protected Attributes

MPI_Comm comm_
 
std::vector< double > global_variables_
 
op::Vector< std::vector
< double > > & 
variables_
 
std::unique_ptr< nlopt::opt > nlopt_
 
NLoptOptionsoptions_
 
std::vector< double > previous_variables_
 
std::vector
< detail::FunctionalInfo< T > > 
obj_info_
 
std::vector
< detail::FunctionalInfo< T > > 
constraints_info_
 
std::vector< int > owned_variables_per_rank_
 
std::vector< int > owned_offsets_
 
std::optional
< utility::CommPattern< T > > 
comm_pattern_
 
std::optional
< std::unordered_map< typename
T::value_type, T > > 
global_reduced_map_to_local_
 
std::size_t num_local_owned_variables_
 
int root_rank_ = 0
 
std::unique_ptr< WaitLoopwaitloop_
 

Friends

double NLoptFunctional (const std::vector< double > &x, std::vector< double > &grad, void *objective_and_optimizer)
 Takes in a op::Functional and computes the objective function and it's gradient as a nlopt function. More...
 

Additional Inherited Members

- Public Attributes inherited from op::Optimizer
op::Go go
 Go function to start optimization.
 
CallbackFn update
 Update callback to compute before function calculations.
 
CallbackFn iterate
 iterate callback to compute before
 
CallbackFn save
 callback for saving current optimizer state
 
double final_obj
 final objective value
 

Detailed Description

template<typename T>
class op::NLopt< T >

A op::optimizer implementation for NLopt.

Definition at line 15 of file nlopt_op.hpp.

Member Function Documentation

template<typename T >
void op::NLopt< T >::addConstraint ( op::Functional )
inlineoverridevirtual

Adds a constraint for the optimization problem.

Parameters
[in]oConstraint Functional

Reimplemented from op::Optimizer.

Definition at line 305 of file nlopt_op.hpp.

template<typename T >
void op::NLopt< T >::setObjective ( op::Functional o)
inlineoverridevirtual

Sets the optimization objective.

Parameters
[in]oObjective Functional

Implements op::Optimizer.

Definition at line 298 of file nlopt_op.hpp.

template<typename T >
bool op::NLopt< T >::variables_changed ( const std::vector< double > &  x)
inline

Method to see if variables changed, if they have set new x.

Parameters
[in]x

Definition at line 331 of file nlopt_op.hpp.

Friends And Related Function Documentation

template<typename T >
double NLoptFunctional ( const std::vector< double > &  x,
std::vector< double > &  grad,
void *  objective_and_optimizer 
)
friend

Takes in a op::Functional and computes the objective function and it's gradient as a nlopt function.

Has the same signature as nlopt::function so we can convert any op::Functional into a nlopt::function

Parameters
[in]xthe optimization variables (on rank = 0 this is the actual global optimization variables, on other ranks it is the local-view of variables.data())
[in]gradthe result of the gradient of the function w.r.t. x (on rank 0, this is the global gradient eval, on other ranks it is the owned-local gradient)
[in]objectiveGet FunctionalInfo into this call

for constraints g >= lower_bound, they need to be rewritten as -(g - lower_bound) <= 0

for constraints g <= upper_bound, they need to be rewritten as g - upper_bound < = 0


The documentation for this class was generated from the following file: