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

Model an interior-point optimisation problem. More...

#include <Model.hpp>

Inheritance diagram for ipo::Model:
Inheritance graph
Collaboration diagram for ipo::Model:
Collaboration graph

Classes

class  DirectSubvector
 This class gives direct access to a subvector of a vector. More...
 
class  IndirectSubvector
 This class gives direct access to a subvector of a vector. More...
 
class  Parameters
 
class  Subvector
 Abstract base class for subvector classes. More...
 

Public Member Functions

 Model ()
 Constructor. More...
 
virtual void notify ()
 Notify function that model must implement. More...
 
void setObjective (Objective &objective)
 Set the objective function. More...
 
Objective getObjective ()
 Get the objective function. More...
 
void addConstraint (Constraint &constraint)
 Add a constraint. More...
 
bool removeConstraint (Constraint &constraint)
 Remove a constraint. More...
 
std::vector< Constraint > const & getConstraints () const
 Get list of constraints. More...
 
std::vector< LinearConstraint >
const & 
getEqualityConstraints () const
 Get list of equality constraints. More...
 
bool isFeasible ()
 Test whether current values of variables give a feasible solution. More...
 
bool isStrictlyFeasible ()
 Test whether current values of variables give a feasible solution. More...
 
bool minimise ()
 Try to minimise the objective function subject to the constraints. More...
 
bool maximise ()
 Try to maximise the objective function subject to the constraints. More...
 
virtual bool findFeasible ()
 Try to find a set of values for the variables that gives a feasible solution. More...
 
ParametersgetParameters ()
 Get parameters by reference. More...
 
detail::NewtonDescent::ParametersgetNewtonDescentParameters ()
 Get Newton descent parameters by reference. More...
 
detail::LineSearch::ParametersgetLineSearchParameters ()
 Get line search parameters by reference. More...
 
bool checkSize () const
 Check objective and constraint functions. More...
 
void testSizes () const
 Check objective and constraint functions. More...
 
void summary (std::ostream &ostream=std::cout) const
 Create a summary of this model. More...
 

Protected Member Functions

gsl::vector getVectorFromVariables () const
 Get a vector from values of variables. More...
 
void setVariablesFromVector (gsl::vector const &vector)
 Set variable values from a vector. More...
 
bool stoppingCriterion (double const t) const
 Check whether or not stopping criterion has been met. More...
 
virtual bool optimise (bool const minimise)
 Try to optimise the objective function subject to the constraints. More...
 
virtual void setIndices ()
 Sets the values of objectiveIndices, constraintIndices and variableIndices from constraints. More...
 
void setObjectiveIndices ()
 Set objectiveIndices. More...
 
void setConstraintIndices ()
 Set constraintIndices. More...
 

Protected Attributes

std::vector< Constraintconstraints
 The set of constraints. More...
 
std::vector
< ipo::LinearConstraint
equalityConstraints
 The set of equality constraints. More...
 
Objective objective
 The objective function. More...
 
std::shared_ptr< SubvectorobjectiveIndices
 Used internally to match the variables in the objective to indices in a vector: objectiveIndices[i] is the index in a gsl::vector of the ith variable in objective.getVariables() after a call to setIndices(). More...
 
std::vector< std::shared_ptr
< Subvector > > 
constraintIndices
 Used internally to match the variables in each constraint to indices in a vector: (*constraintIndices[j])()[i] is the index in a gsl::vector of the ith variable in constraint[j]->getVariables() after a call to setIndices(). More...
 
std::vector< std::shared_ptr
< Subvector > > 
equalityConstraintIndices
 Used internally to match the variables in each equality constraint to indices in a vector: (*constraintIndices[j])()[i] is the index in a gsl::vector of the ith variable in * constraint[j]->getVariables() after a call to setIndices(). More...
 
std::map< Variable, size_t > indexMap
 Used internally to match the variables in each variable to indices in a vector. More...
 
bool variablesChanged = false
 Value that indicates if any variables, objective or constraints have been modified in such a way that we may have to update them. More...
 
detail::NewtonDescent::Parameters newtonDescentParameters
 Parameters used by Newton descent algorithm during optimisation. More...
 
detail::LineSearch::Parameters lineSearchParameters
 Parameters used by backtracking line search algorithm during optimisation. More...
 

Private Attributes

Parameters parameters
 Parameters for interior point optimisation. More...
 

Friends

class detail::BarrierFunction
 
class detail::PhaseIModel
 

Detailed Description

Model an interior-point optimisation problem.

The problem must have an objective function and (usually) some constraints. Initially a new instance of this class will have a null objective function and no constraints.

Definition at line 325 of file Model.hpp.

Constructor & Destructor Documentation

Model::Model ( )

Constructor.

Definition at line 132 of file Model.cc.

Member Function Documentation

void Model::addConstraint ( Constraint constraint)

Add a constraint.

Parameters
constraintThe constraint

Definition at line 48 of file Model.cc.

References constraints, and equalityConstraints.

Referenced by ipo::LinearConstraint::setLowerBound(), ipo::LinearConstraint::setUpperBound(), and ipo::LinearConstraint::setValue().

bool Model::checkSize ( ) const

Check objective and constraint functions.

If any of these differ in the number of Variable objects assigned to them and the declared size of the function return true; otherwise return false.

If the result is false, use the chcekSize() method on the Objective object or Constraint object to identify where the problem lies.

Returns
true or false according as there is some mistmatch between argument size and number of Variable objects assigned to objective or some constraint.

Definition at line 343 of file Model.cc.

References ipo::detail::ModelFunction::checkSize(), constraints, and objective.

bool Model::findFeasible ( )
virtual

Try to find a set of values for the variables that gives a feasible solution.

If the values are not already feasible this function used a Phase I model to seek a feasible solution.

Returns
true or false according as there is a feasible solution to the constraint problem or not

Definition at line 531 of file Model.cc.

References ipo::detail::PhaseIModel::findFeasibleSolution(), and isStrictlyFeasible().

Referenced by optimise().

std::vector< Constraint > const & Model::getConstraints ( ) const

Get list of constraints.

Returns
List of constraints

Definition at line 82 of file Model.cc.

References constraints.

std::vector< LinearConstraint > const & Model::getEqualityConstraints ( ) const

Get list of equality constraints.

Returns
List of equality constraints

Definition at line 87 of file Model.cc.

References equalityConstraints.

detail::LineSearch::Parameters & Model::getLineSearchParameters ( )

Get line search parameters by reference.

These parameters are used by backtracking line search algorithm during optimisation.

Returns
parameters

Definition at line 336 of file Model.cc.

References lineSearchParameters.

Referenced by optimise().

detail::NewtonDescent::Parameters & Model::getNewtonDescentParameters ( )

Get Newton descent parameters by reference.

These parameters are used by Newton descent algorithm during optimisation.

Returns
parameters

Definition at line 331 of file Model.cc.

References newtonDescentParameters.

Referenced by ipo::detail::PhaseIModel::findFeasibleSolution(), and optimise().

Objective Model::getObjective ( )

Get the objective function.

Returns
The objective function

Definition at line 43 of file Model.cc.

References objective.

Referenced by summary().

Model::Parameters & Model::getParameters ( )

Get parameters by reference.

Returns
parameters

Definition at line 341 of file Model.cc.

References parameters.

gsl::vector Model::getVectorFromVariables ( ) const
protected

Get a vector from values of variables.

Returns
a vector from values of variables

Definition at line 214 of file Model.cc.

References indexMap.

Referenced by optimise().

bool Model::isFeasible ( )

Test whether current values of variables give a feasible solution.

Returns
true or false according as current solution is feasible or not

Definition at line 136 of file Model.cc.

References constraintIndices, constraints, equalityConstraints, ipo::Variable::getValue(), indexMap, and setIndices().

bool Model::isStrictlyFeasible ( )

Test whether current values of variables give a feasible solution.

This function differs from isFeasible because it also checks if variables are strictly within their bounds.

Returns
true or false according as current solution is feasible or not

Definition at line 175 of file Model.cc.

References constraintIndices, constraints, equalityConstraintIndices, equalityConstraints, ipo::Variable::getValue(), indexMap, and setIndices().

Referenced by findFeasible(), and ipo::detail::PhaseIModel::findFeasibleSolution().

bool ipo::Model::maximise ( )
inline

Try to maximise the objective function subject to the constraints.

Returns
true or false according as maximisation succeeded or not

Definition at line 763 of file Model.hpp.

References optimise().

bool ipo::Model::minimise ( )
inline

Try to minimise the objective function subject to the constraints.

Returns
true or false according as minimisation succeeded or not

Definition at line 758 of file Model.hpp.

References optimise().

Referenced by ipo::detail::PhaseIModel::findFeasibleSolution().

void Model::notify ( )
virtual

Notify function that model must implement.

This function is called internally whenever a variable is changed.

Implements ipo::detail::ModelBase.

Definition at line 130 of file Model.cc.

References variablesChanged.

bool Model::optimise ( bool const  minimise)
protectedvirtual

Try to optimise the objective function subject to the constraints.

Parameters
minimiseSet to true for minimisation, false for maximisation
Returns
true or false according as optimisation succeeded or not

DEBUG

DEBUG

Definition at line 247 of file Model.cc.

References equalityConstraints, findFeasible(), getLineSearchParameters(), ipo::Model::Parameters::getMu(), getNewtonDescentParameters(), ipo::Model::Parameters::getOutputStream(), ipo::detail::NewtonDescent::getParameters(), getVectorFromVariables(), indexMap, ipo::detail::BarrierFunction::negative, parameters, ipo::detail::BarrierFunction::positive, RETHROW, setVariablesFromVector(), and stoppingCriterion().

Referenced by maximise(), and minimise().

bool Model::removeConstraint ( Constraint constraint)

Remove a constraint.

If the constraint is not in this then it cannot be removed and the function returns false.

Parameters
constraintThe constraint
Returns
true or false according as constraint was removed or not

Definition at line 57 of file Model.cc.

References constraints, and equalityConstraints.

void Model::setConstraintIndices ( )
protected

Set constraintIndices.

This function is called internally in setIndices.

Definition at line 429 of file Model.cc.

References constraintIndices, equalityConstraintIndices, equalityConstraints, ipo::Array::front(), ipo::Objective::getVariables(), indexMap, objective, and ipo::Array::size().

Referenced by ipo::detail::PhaseIModel::setIndices(), and setIndices().

void Model::setIndices ( )
protectedvirtual

Sets the values of objectiveIndices, constraintIndices and variableIndices from constraints.

This function is designed to be used internally to generate indices for subvectors of a gsl::vector for calculating gradients and Hessians during optimisation.

Reimplemented in ipo::detail::PhaseIModel.

Definition at line 92 of file Model.cc.

References constraints, equalityConstraints, ipo::Objective::getVariables(), indexMap, objective, RETHROW, setConstraintIndices(), setObjectiveIndices(), ipo::Array::size(), testSizes(), and variablesChanged.

Referenced by ipo::detail::PhaseIModel::getInitial_s(), isFeasible(), isStrictlyFeasible(), and ipo::detail::PhaseIModel::setIndices().

void Model::setObjective ( Objective objective)

Set the objective function.

Parameters
objectiveThe objective function

Definition at line 38 of file Model.cc.

References objective.

void ipo::Model::setObjectiveIndices ( )
inlineprotected

Set objectiveIndices.

This function is called internally in setIndices.

Definition at line 847 of file Model.hpp.

References ipo::Objective::getVariables(), indexMap, objective, objectiveIndices, and ipo::Array::size().

Referenced by ipo::detail::PhaseIModel::setIndices(), and setIndices().

void Model::setVariablesFromVector ( gsl::vector const &  vector)
protected

Set variable values from a vector.

Parameters
vectora vector of values for variables
Exceptions
IPOExceptionif vector size does not match number of variables

Definition at line 224 of file Model.cc.

References indexMap, and IPOE.

Referenced by ipo::detail::PhaseIModel::findFeasibleSolution(), and optimise().

bool Model::stoppingCriterion ( double const  t) const
protected

Check whether or not stopping criterion has been met.

Parameters
tThe value or t used by the barrier
Returns
true or false according as criterion met or not

Definition at line 238 of file Model.cc.

References constraints, equalityConstraints, ipo::Model::Parameters::getEpsilon(), and parameters.

Referenced by optimise().

void Model::summary ( std::ostream &  ostream = std::cout) const

Create a summary of this model.

Parameters
ostreamThe stream to print to.

Definition at line 391 of file Model.cc.

References getObjective(), ipo::Objective::summary(), and summary().

Referenced by summary().

void Model::testSizes ( ) const

Check objective and constraint functions.

If any of these differ in the number of Variable objects assigned to them and the declared size of the function, throw an exception of class IPOException describing all the failures.

Exceptions
IPOExceptionif any function size don’t match the number of variables supplied

Definition at line 351 of file Model.cc.

References constraints, ipo::Objective::getName(), ipo::detail::ModelFunction::getSizes(), and objective.

Referenced by setIndices().

Friends And Related Function Documentation

friend class detail::BarrierFunction
friend

Definition at line 699 of file Model.hpp.

friend class detail::PhaseIModel
friend

Definition at line 700 of file Model.hpp.

Member Data Documentation

std::vector<std::shared_ptr<Subvector> > ipo::Model::constraintIndices
protected
std::vector<std::shared_ptr<Subvector> > ipo::Model::equalityConstraintIndices
protected

Used internally to match the variables in each equality constraint to indices in a vector: (*constraintIndices[j])()[i] is the index in a gsl::vector of the ith variable in * constraint[j]->getVariables() after a call to setIndices().

Definition at line 898 of file Model.hpp.

Referenced by isStrictlyFeasible(), and setConstraintIndices().

detail::LineSearch::Parameters ipo::Model::lineSearchParameters
protected

Parameters used by backtracking line search algorithm during optimisation.

Definition at line 916 of file Model.hpp.

Referenced by getLineSearchParameters(), and ipo::detail::PhaseIModel::PhaseIModel().

detail::NewtonDescent::Parameters ipo::Model::newtonDescentParameters
protected

Parameters used by Newton descent algorithm during optimisation.

Definition at line 912 of file Model.hpp.

Referenced by getNewtonDescentParameters(), and ipo::detail::PhaseIModel::PhaseIModel().

std::shared_ptr<Subvector> ipo::Model::objectiveIndices
protected

Used internally to match the variables in the objective to indices in a vector: objectiveIndices[i] is the index in a gsl::vector of the ith variable in objective.getVariables() after a call to setIndices().

Definition at line 886 of file Model.hpp.

Referenced by ipo::detail::BarrierFunction::gradient(), ipo::detail::BarrierFunction::hessian(), ipo::detail::BarrierFunction::initialiseGradientFromObjective(), ipo::detail::BarrierFunction::initialiseHessianFromObjective(), ipo::detail::BarrierFunction::operator()(), setObjectiveIndices(), and ipo::detail::BarrierFunction::setVector().

Parameters ipo::Model::parameters
private

Parameters for interior point optimisation.

Definition at line 399 of file Model.hpp.

Referenced by getParameters(), optimise(), ipo::detail::PhaseIModel::PhaseIModel(), and stoppingCriterion().

bool ipo::Model::variablesChanged = false
protected

Value that indicates if any variables, objective or constraints have been modified in such a way that we may have to update them.

Definition at line 908 of file Model.hpp.

Referenced by notify(), ipo::detail::PhaseIModel::PhaseIModel(), ipo::detail::PhaseIModel::setIndices(), and setIndices().


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