Interior-point-optimisation  1.0-1
Interior-pointoptimisationlibrary
ipo::Objective Class Reference

Class for an objective function. More...

#include <Objective.hpp>

Inheritance diagram for ipo::Objective:
Inheritance graph
Collaboration diagram for ipo::Objective:
Collaboration graph

Classes

struct  Data
 Struct to contain Constraint data. More...
 

Public Member Functions

 Objective (detail::ModelBase &model, detail::SharedFunctionPtr function, std::string const &name)
 Use this constructor to construct from a SharedFunctionPtr object. More...
 
 Objective (detail::ModelBase &model, ipo_function::Function *function, std::string const &name)
 Use this constructor to construct from a pointer to a ipo_function::Function object. More...
 
 Objective (detail::ModelBase &model, ipo_function::Function &function, std::string const &name)
 Use this constructor to construct from a ipo_function::Function object by reference. More...
 
 Objective (detail::ModelBase &model, detail::SharedFunctionPtr function, char const *const name=0)
 Use this constructor to construct from a SharedFunctionPtr object. More...
 
 Objective (detail::ModelBase &model, ipo_function::Function *function, char const *const name=0)
 Use this constructor to construct from a pointer to a ipo_function::Function object. More...
 
 Objective (detail::ModelBase &model, ipo_function::Function &function, char const *const name=0)
 Constructor. More...
 
 Objective (Objective const &objective)
 Copy constructor. More...
 
 Objective (Objective &&objective)
 Move constructor. More...
 
Objectiveoperator= (Objective const &objective)
 Assignment operator. More...
 
Objectiveoperator= (Objective &&objective)
 Assignment operator. More...
 
std::string getName () const
 Get name of variable. More...
 
void setName (std::string const &name)
 Set name of Objective. More...
 
void setName (char *const name)
 Set name of Objective. More...
 
ArraygetVariables ()
 Get variables used by Objective function. More...
 
void addVariable (Variable &variable)
 Add a Variable. More...
 
void removeVariable (Variable &variable)
 Remove (first, and usually only occurrence of) a Variable. More...
 
void addArray (Array &array)
 Add an Array. More...
 
void removeArray (Array &array)
 Remove an Array. More...
 
virtual void summary (std::ostream &ostream=std::cout, std::string const &prefix="") const override
 Create a summary of this function. More...
 
- Public Member Functions inherited from ipo::detail::Var
 Var (ModelBase &model)
 Constructor needs a model so that variable can only be attached to one model. More...
 
virtual ~Var ()=0
 Virtual destructor to make class abstract. More...
 
 Var (Var &var)
 Copy constructor. More...
 
Varoperator= (Var &var)
 Copy assignment operator. More...
 
 Var (Var &&var)
 Move constructor. More...
 
Varoperator= (Var &&var)
 Move assignment operator. More...
 
ModelBase const *const getModel () const
 Get pointer to model. More...
 
- Public Member Functions inherited from ipo::detail::ModelFunction
 ModelFunction (SharedFunctionPtr function)
 Use this constructor to construct from a SharedFunctionPtr object. More...
 
 ModelFunction (ipo_function::Function *function)
 Use this constructor to construct from a pointer to a ipo_function::Function object. More...
 
 ModelFunction (ipo_function::Function &function)
 Use this constructor to construct from a ipo_function::Function object by reference. More...
 
bool checkSize () const
 Check size of vector for function arguments matches number of variables supplied. More...
 
std::tuple< size_t, size_t > getSizes () const
 Get size of vector for function arguments and number of variables supplied. More...
 
virtual ::ipo_function::FunctiongetFunction ()
 Get function. More...
 

Protected Member Functions

double value () const noexcept
 Value of the objective function at the current value of the variables. More...
 

Protected Attributes

std::shared_ptr< Datadata
 The objective data. More...
 
- Protected Attributes inherited from ipo::detail::Var
ModelBasemodel
 A Model to attach this to. More...
 
- Protected Attributes inherited from ipo::detail::ModelFunction
SharedFunctionPtr function
 The objective or constraint function. More...
 

Detailed Description

Class for an objective function.

The function should be set from an object of a subclass of ipo_function::Function. Use getVariables() = ... to specify an Array or Variable for the objective function to use. Note that setting getVariables also implicitly determines the size of the vector to be passed to function, but this class does not check the sizes of variables and function arguments match. Note also that if function is destructed before an Objective object that uses it, the behaviour of the Objective object is undefined.

Definition at line 37 of file Objective.hpp.

Constructor & Destructor Documentation

Objective::Objective ( detail::ModelBase model,
detail::SharedFunctionPtr  function,
std::string const &  name 
)

Use this constructor to construct from a SharedFunctionPtr object.

Parameters
modelA Model
functionA SharedFunctionPtr object
nameA name for this object

Definition at line 28 of file Objective.cc.

Objective::Objective ( detail::ModelBase model,
ipo_function::Function function,
std::string const &  name 
)

Use this constructor to construct from a pointer to a ipo_function::Function object.

The Function object should be constructed using new and should not be deleted explicitly.

Parameters
modelA Model
functionA pointer to an object of a subclass of ipo_function::Function
nameA name for this object

Definition at line 39 of file Objective.cc.

References ipo::detail::Var::model.

Objective::Objective ( detail::ModelBase model,
ipo_function::Function function,
std::string const &  name 
)

Use this constructor to construct from a ipo_function::Function object by reference.

The Function object must remain in scope for the Objective object to be useable.

Parameters
modelA Model
functionAn object of a subclass of ipo_function::Function
nameA name for this object

Definition at line 43 of file Objective.cc.

References ipo::detail::Var::model.

Objective::Objective ( detail::ModelBase model,
detail::SharedFunctionPtr  function,
char const *const  name = 0 
)

Use this constructor to construct from a SharedFunctionPtr object.

Parameters
modelA Model
functionA SharedFunctionPtr object
nameA name for this object

Definition at line 47 of file Objective.cc.

References ipo::detail::Var::model.

Objective::Objective ( detail::ModelBase model,
ipo_function::Function function,
char const *const  name = 0 
)

Use this constructor to construct from a pointer to a ipo_function::Function object.

The Function object should be constructed using new and should not be deleted explicitly.

Parameters
modelA Model
functionA pointer to an object of a subclass of ipo_function::Function
nameA name for this object

Definition at line 51 of file Objective.cc.

References ipo::detail::Var::model.

Objective::Objective ( detail::ModelBase model,
ipo_function::Function function,
char const *const  name = 0 
)

Constructor.

Parameters
modelA Model
functionAn object of a subclass of ipo_function::Function
nameA name for this object

Definition at line 55 of file Objective.cc.

References ipo::detail::Var::model.

Objective::Objective ( Objective const &  objective)

Copy constructor.

Parameters
objectiveThe Objective to copy

Definition at line 80 of file Objective.cc.

References ipo::detail::Var::model.

Objective::Objective ( Objective &&  objective)

Move constructor.

Parameters
objectiveThe Objective to move

Definition at line 87 of file Objective.cc.

References ipo::detail::Var::model.

Member Function Documentation

void Objective::addArray ( Array array)

Add an Array.

It should contain no Variable already added.

Parameters
arrayThe Array
Exceptions
IPOExceptionif array is not in Model or any Variable is already added.

Definition at line 146 of file Objective.cc.

References ipo::detail::Var::getModel(), getName(), ipo::Array::getName(), getVariables(), IPOE, ipo::Array::push_back(), and RETHROW.

void Objective::addVariable ( Variable variable)
virtual

Add a Variable.

If you really need to add a Variable more than once, use getVariables().push_back( variable ).

Parameters
variableThe Variable to add
Exceptions
IPOExceptionif Variable is not in Model or variable already added.

Reimplemented from ipo::detail::ModelFunction.

Definition at line 113 of file Objective.cc.

References ipo::Variable::getName(), getName(), getVariables(), IPOE, and RETHROW.

std::string Objective::getName ( ) const

Get name of variable.

Returns
name of variable.

Definition at line 60 of file Objective.cc.

References data.

Referenced by addArray(), addVariable(), removeArray(), removeVariable(), ipo::Constraint::summary(), summary(), and ipo::Model::testSizes().

Objective & Objective::operator= ( Objective const &  objective)

Assignment operator.

Parameters
objectiveThe Objective to copy

Definition at line 94 of file Objective.cc.

References data, ipo::detail::ModelFunction::function, ipo::detail::Var::model, and ipo::detail::ModelBase::notify().

Objective & Objective::operator= ( Objective &&  objective)

Assignment operator.

Parameters
objectiveThe Objective to move

Definition at line 103 of file Objective.cc.

References data, and ipo::detail::Var::model.

void Objective::removeArray ( Array array)

Remove an Array.

It should contain no Variable not already added.

Parameters
arrayThe Array
Exceptions
IPOExceptionif any Variable is not already added.

Definition at line 171 of file Objective.cc.

References ipo::Array::erase(), ipo::detail::Var::getModel(), getName(), ipo::Array::getName(), getVariables(), IPOE, and RETHROW.

void Objective::removeVariable ( Variable variable)

Remove (first, and usually only occurrence of) a Variable.

Parameters
variableThe Variable to remove
Exceptions
IPOExceptionif Variable is not in this

Definition at line 129 of file Objective.cc.

References ipo::Variable::getName(), getName(), getVariables(), IPOE, and RETHROW.

void Objective::setName ( std::string const &  name)

Set name of Objective.

Parameters
nameThe new name.

Definition at line 65 of file Objective.cc.

References data, and name.

void Objective::setName ( char *const  name)

Set name of Objective.

Parameters
nameThe new name.

Definition at line 70 of file Objective.cc.

References data, and name.

void Objective::summary ( std::ostream &  ostream = std::cout,
std::string const &  prefix = "" 
) const
overridevirtual

Create a summary of this function.

This should be a description of the objective function and its variables.

Parameters
ostreamThe stream to print to.
prefixThis is put in front of every row of output, for example for indentation

Implements ipo::detail::Var.

Reimplemented in ipo::Constraint.

Definition at line 198 of file Objective.cc.

References getName(), and value().

Referenced by ipo::Model::summary().

double Objective::value ( ) const
protectednoexcept

Value of the objective function at the current value of the variables.

Returns
An estimate (if available) of objective function at the current value of the variables.

Definition at line 209 of file Objective.cc.

References getVariables(), and ipo::Array::size().

Referenced by ipo::LinearConstraint::setCoefficient(), ipo::LinearConstraint::setValue(), ipo::Constraint::summary(), and summary().

Member Data Documentation


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