299 #ifndef IPO_MODEL_HPP
300 #define IPO_MODEL_HPP
305 #include"../ipo_function/DerivativesEstimates.hpp"
307 #include"../ipo_function/concrete/Null.hpp"
315 class LinearConstraint;
419 virtual gsl::vector
const get( gsl::vector
const& vector )
const = 0;
426 virtual void set( gsl::vector& vector, gsl::vector
const& subvector,
427 double const scale = 1.0 )
const = 0;
434 virtual void add( gsl::vector& vector, gsl::vector
const& subvector,
435 double const scale = 1.0 )
const = 0;
442 virtual void set( gsl::matrix& matrix, gsl::matrix
const& submatrix,
443 double const scale = 1.0 )
const = 0;
451 virtual void add( gsl::matrix& matrix, gsl::matrix
const& submatrix,
452 double const scale = 1.0 )
const = 0;
460 virtual void set( gsl::matrix& matrix, gsl::vector
const& vector,
461 double const scale = 1.0 )
const = 0;
469 virtual void add( gsl::matrix& matrix, gsl::vector
const& vector,
470 double const scale = 1.0 )
const = 0;
489 virtual gsl::vector
const get( gsl::vector
const& vector )
const {
490 return vector.subvector( offset, length ); }
497 virtual void set( gsl::vector& vector, gsl::vector
const& subvector,
498 double const scale = 1.0 )
const {
499 for(
size_t i { 0 }; i <
length; ++i ) vector[i + offset] = scale * subvector[i]; }
506 virtual void add( gsl::vector& vector, gsl::vector
const& subvector,
507 double const scale = 1.0 )
const {
508 for(
size_t i { 0 }; i <
length; ++i ) vector[i + offset] += scale * subvector[i]; }
515 virtual void set( gsl::matrix& matrix, gsl::matrix
const& submatrix,
516 double const scale = 1.0 )
const {
517 for(
size_t i { 0 }; i <
length; ++i )
518 for(
size_t j { i }; j <
length; ++j ){
519 double const d { scale * submatrix.get( i, j ) };
520 matrix.set( i + offset, j + offset, d );
521 if( j > i ) matrix.set( j + offset, i + offset, d );
531 virtual void add( gsl::matrix& matrix, gsl::matrix
const& submatrix,
532 double const scale = 1 )
const {
533 for(
size_t i = 0; i <
length; ++i )
534 for(
size_t j = i; j <
length; ++j ){
535 double const d = scale * submatrix.get( i, j )
536 + matrix.get( i + offset, j + offset );
537 matrix.set( i + offset, j + offset, d );
538 if( j > i ) matrix.set( j + offset, i + offset, d );
548 virtual void set( gsl::matrix& matrix, gsl::vector
const& vector,
549 double const scale = 1 )
const {
550 for(
size_t i = 0; i <
length; ++i )
551 for(
size_t j = i; j <
length; ++j ){
552 double const d = scale * vector[i] * vector[j];
553 matrix.set( i + offset, j + offset, d );
554 if( j > i ) matrix.set( j + offset, i + offset, d );
564 virtual void add( gsl::matrix& matrix, gsl::vector
const& vector,
565 double const scale = 1.0 )
const {
566 for(
size_t i { 0 }; i <
length; ++i )
567 for(
size_t j { i }; j <
length; ++j ){
568 double const d { scale * vector[i] * vector[j]
569 + matrix.get( i + offset, j + offset ) };
570 matrix.set( i + offset, j + offset, d );
571 if( j > i ) matrix.set( j + offset, i + offset, d );
601 virtual gsl::vector
const get( gsl::vector
const& vector )
const {
602 gsl::vector subvector( size() );
603 for(
size_t index { 0 }; index < size(); ++index )
604 subvector[index] = vector[(*
this)[index]];
613 virtual void set( gsl::vector& vector, gsl::vector
const& subvector,
614 double const scale = 1.0 )
const {
615 for(
size_t index { 0 }; index < size(); ++index )
616 vector[(*
this)[index]] = scale * subvector[index]; }
623 virtual void add( gsl::vector& vector, gsl::vector
const& subvector,
624 double const scale = 1.0 )
const {
625 for(
size_t index { 0 }; index < size(); ++index )
626 vector[(*
this)[index]] += scale * subvector[index]; }
633 virtual void set( gsl::matrix& matrix, gsl::matrix
const& submatrix,
634 double const scale = 1.0 )
const {
635 for(
size_t i { 0 }; i < size(); ++i )
636 for(
size_t j = i; j < size(); ++j ){
637 size_t const r { (*this)[i] };
638 size_t const c { (*this)[j] };
639 double const d { scale * submatrix.get( i , j ) };
640 matrix.set( r, c, d );
641 if( j > i ) matrix.set( c, r, d );
651 virtual void add( gsl::matrix& matrix, gsl::matrix
const& submatrix,
652 double const scale = 1 )
const {
653 for(
size_t i = 0; i < size(); ++i )
654 for(
size_t j = i; j < size(); ++j ){
655 size_t const r = (*this)[i];
656 size_t const c = (*this)[j];
657 double const d = scale * submatrix.get( i , j ) + matrix.get( r, c );
658 matrix.set( r, c, d );
659 if( j > i ) matrix.set( c, r, d );
669 virtual void set( gsl::matrix& matrix, gsl::vector
const& vector,
670 double const scale = 1.0 )
const {
671 for(
size_t i { 0 }; i < size(); ++i )
672 for(
size_t j { i }; j < size(); ++j ){
673 size_t const r { (*this)[i] };
674 size_t const c { (*this)[j] };
675 double const d { scale * vector[i] * vector[j] };
676 matrix.set( r, c, d );
677 if( j > i ) matrix.set( c, r, d );
687 virtual void add( gsl::matrix& matrix, gsl::vector
const& vector,
688 double const scale = 1.0 )
const {
689 for(
size_t i { 0 }; i < size(); ++i )
690 for(
size_t j = i; j < size(); ++j ){
691 size_t const r { (*this)[i] };
692 size_t const c { (*this)[j] };
693 double const d { scale * vector[i] * vector[j] + matrix.get( r, c ) };
694 matrix.set( r, c, d );
695 if( j > i ) matrix.set( c, r, d );
812 void summary( std::ostream& ostream = std::cout )
const;
850 bool const DIRECTSUBVECTORFOROBJECTIVEINDICES { OSIZE ==
indexMap.size() };
852 if( DIRECTSUBVECTORFOROBJECTIVEINDICES )
859 (*oIndices)[index] =
indexMap[variable];
std::map< Variable, size_t > indexMap
Used internally to match the variables in each variable to indices in a vector.
Model used for finding an initial feasible solution in phase I of interior-pont optimisation.
double getMu() const
Get value of mu.
std::vector< LinearConstraint > const & getEqualityConstraints() const
Get list of equality constraints.
virtual void setIndices()
Sets the values of objectiveIndices, constraintIndices and variableIndices from constraints.
std::vector< ipo::LinearConstraint > equalityConstraints
The set of equality constraints.
virtual void set(gsl::vector &vector, gsl::vector const &subvector, double const scale=1.0) const =0
Set vector from a subvector.
This class gives direct access to a subvector of a vector.
detail::LineSearch::Parameters & getLineSearchParameters()
Get line search parameters by reference.
bool minimise()
Try to minimise the objective function subject to the constraints.
virtual void set(gsl::vector &vector, gsl::vector const &subvector, double const scale=1.0) const
Set vector from a subvector using indices without checking bounds.
detail::LineSearch::Parameters lineSearchParameters
Parameters used by backtracking line search algorithm during optimisation.
Objective getObjective()
Get the objective function.
virtual void set(gsl::matrix &matrix, gsl::matrix const &submatrix, double const scale=1.0) const
Set matrix from a submatrix without checking bounds.
double mu
A value used for scaling: the default is 10.
bool variablesChanged
Value that indicates if any variables, objective or constraints have been modified in such a way that...
void testSizes() const
Check objective and constraint functions.
std::vector< std::shared_ptr< Subvector > > equalityConstraintIndices
Used internally to match the variables in each equality constraint to indices in a vector: (*constrai...
std::ostream * getOutputStream() const
Get output stream.
This class gives direct access to a subvector of a vector.
detail::NewtonDescent::Parameters newtonDescentParameters
Parameters used by Newton descent algorithm during optimisation.
virtual void set(gsl::matrix &matrix, gsl::vector const &vector, double const scale=1) const
Set matrix from a vector without checking bounds.
detail::NewtonDescent::Parameters & getNewtonDescentParameters()
Get Newton descent parameters by reference.
size_type size() const
Get size of array.
virtual void add(gsl::vector &vector, gsl::vector const &subvector, double const scale=1.0) const
Add to vector from a subvector without checking bounds.
Array & getVariables()
Get variables used by Objective function.
Objective objective
The objective function.
Abstract base class for subvector classes.
std::vector< Constraint > const & getConstraints() const
Get list of constraints.
bool isStrictlyFeasible()
Test whether current values of variables give a feasible solution.
void setVariablesFromVector(gsl::vector const &vector)
Set variable values from a vector.
std::vector< Constraint > constraints
The set of constraints.
Class for a constraint function.
double epsilon
A limit used for convergence.
Model an interior-point optimisation problem.
virtual void notify()
Notify function that model must implement.
std::ostream * outputStream
A stream (default is nullptr) for sending output to.
Abstract base class for model.
DirectSubvector(size_t const offset, size_t const length)
The constructor needs an offset and a length.
bool stoppingCriterion(double const t) const
Check whether or not stopping criterion has been met.
Class for an objective function.
virtual void add(gsl::matrix &matrix, gsl::vector const &vector, double const scale=1.0) const
Add to matrix from a vector without checking bounds.
virtual void set(gsl::matrix &matrix, gsl::vector const &vector, double const scale=1.0) const
Set matrix from a vector without checking bounds.
void summary(std::ostream &ostream=std::cout) const
Create a summary of this model.
virtual void add(gsl::matrix &matrix, gsl::matrix const &submatrix, double const scale=1) const
Add to matrix from a submatrix without checking bounds.
gsl::vector getVectorFromVariables() const
Get a vector from values of variables.
size_t const length
The length.
size_t const offset
The offset.
Parameters & getParameters()
Get parameters by reference.
virtual void add(gsl::matrix &matrix, gsl::vector const &vector, double const scale=1.0) const
Add to matrix from a vector without checking bounds.
void setObjectiveIndices()
Set objectiveIndices.
virtual void set(gsl::vector &vector, gsl::vector const &subvector, double const scale=1.0) const
Set vector from a subvector without checking bounds.
virtual void add(gsl::vector &vector, gsl::vector const &subvector, double const scale=1.0) const
Add to vector from a using indices without checking bounds.
virtual void add(gsl::matrix &matrix, gsl::matrix const &submatrix, double const scale=1) const
Add to matrix from a submatrix without checking bounds.
bool checkSize() const
Check objective and constraint functions.
Function for the logarithmic barrier.
void setConstraintIndices()
Set constraintIndices.
void setObjective(Objective &objective)
Set the objective function.
void setEpsilon(double const epsilon)
Set value of epsilon.
virtual void set(gsl::matrix &matrix, gsl::matrix const &submatrix, double const scale=1.0) const
Set matrix from a submatrix without checking bounds.
virtual void add(gsl::vector &vector, gsl::vector const &subvector, double const scale=1.0) const =0
Add to vector from a subvector.
bool removeConstraint(Constraint &constraint)
Remove a constraint.
Subvector()
Default constructor.
IndirectSubvector(size_t const size)
The constructor needs a vector to translate the indices of subvector to indices of vector: that is su...
Parameters parameters
Parameters for interior point optimisation.
void setOutputStream(std::ostream *outputStream)
Set value of output stream.
double getEpsilon() const
Get value of epsilon.
bool maximise()
Try to maximise the objective function subject to the constraints.
bool isFeasible()
Test whether current values of variables give a feasible solution.
std::vector< std::shared_ptr< Subvector > > constraintIndices
Used internally to match the variables in each constraint to indices in a vector: (*constraintIndices...
virtual bool findFeasible()
Try to find a set of values for the variables that gives a feasible solution.
Parameters()
Constructor: sets default values.
std::shared_ptr< Subvector > objectiveIndices
Used internally to match the variables in the objective to indices in a vector: objectiveIndices[i] i...
void addConstraint(Constraint &constraint)
Add a constraint.
This namespace holds all the interior-point optimisation classes.
void setMu(double const mu)
Set value of mu.
virtual bool optimise(bool const minimise)
Try to optimise the objective function subject to the constraints.