|
Interior-point-optimisation
1.0-1
Interior-pointoptimisationlibrary
|
Class to represent a linear combination as an Objective or Constraint. More...
#include <LinearConstraint.hpp>


Public Member Functions | |
| LinearConstraint (detail::ModelBase &model, std::string const &name) | |
| The constructor creates a new object with no variables. More... | |
| LinearConstraint (detail::ModelBase &model, char const *const name) | |
| The constructor creates a new object with no variables. More... | |
| void | setCoefficient (Variable const &variable, double const value) |
| Set the coefficient of variable. More... | |
| double | getCoefficient (Variable const &variable) const |
| Get the coefficient of variable. More... | |
| void | setCoefficients (gsl::vector const &vector) |
| Set all the coefficients of this LinearConstraint. More... | |
| gsl::vector const & | getCoefficients () const |
| Get all the coefficients of this LinearConstraint. More... | |
| virtual ::ipo_function::Function * | getFunction () |
| Get function. More... | |
| void | setValue (double const value) |
| Set value of Constraint. More... | |
| virtual void | setUpperBound (double const upperBound) |
| Set upper bound of Constraint. More... | |
| virtual void | setLowerBound (double const lowerBound) |
| Set lower bound of Constraint. More... | |
| bool | isEqualityConstraint () const |
| Find if this is an equality constraint (upperBound = lowerBound). More... | |
Public Member Functions inherited from ipo::Constraint | |
| Constraint (detail::ModelBase &model, detail::SharedFunctionPtr function, std::string const &name) | |
| Use this constructor to construct from a ipo_function::SharedFunctionPtr object. More... | |
| Constraint (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... | |
| Constraint (detail::ModelBase &model, ipo_function::Function &function, std::string const &name) | |
| Constructor. More... | |
| Constraint (detail::ModelBase &model, detail::SharedFunctionPtr function, char const *const name=0) | |
| Use this constructor to construct from a ipo_function::SharedFunctionPtr object. More... | |
| Constraint (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... | |
| Constraint (detail::ModelBase &model, ipo_function::Function &function, char const *const name=0) | |
| Constructor. More... | |
| double | getUpperBound () const |
| Get upper bound of Constraint. More... | |
| double | getLowerBound () const |
| Get lower bound of Constraint. More... | |
| Constraint (Constraint const &constraint) | |
| Copy constructor. More... | |
| Constraint & | operator= (Constraint const &constraint) |
| Assignment operator. More... | |
| Constraint (Constraint &&constraint) | |
| Move constructor. More... | |
| Constraint & | operator= (Constraint &&constraint) |
| Move assignment operator. 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::Objective | |
| 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... | |
| Objective & | operator= (Objective const &objective) |
| Assignment operator. More... | |
| Objective & | operator= (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... | |
| Array & | getVariables () |
| 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... | |
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... | |
| Var & | operator= (Var &var) |
| Copy assignment operator. More... | |
| Var (Var &&var) | |
| Move constructor. More... | |
| Var & | operator= (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::Function * | getFunction () |
| Get function. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from ipo::Objective | |
| double | value () const noexcept |
| Value of the objective function at the current value of the variables. More... | |
Protected Attributes inherited from ipo::Objective | |
| std::shared_ptr< Data > | data |
| The objective data. More... | |
Protected Attributes inherited from ipo::detail::Var | |
| ModelBase & | model |
| A Model to attach this to. More... | |
Protected Attributes inherited from ipo::detail::ModelFunction | |
| SharedFunctionPtr | function |
| The objective or constraint function. More... | |
Class to represent a linear combination as an Objective or Constraint.
Internally the function is represented as an ipo_function::concrete::LinearCombination object. But you should normally use this class directly for linear constraints. It provides the same functions as ipo_function::concrete::LinearCombination or a custom ipo_function::Function class. But it also allows the possibility of setting a constraint with an equality bound and allows you to specify the coefficients by variable, which is less error-prone than specifying them by index.
Use getVariables() to change the variables assigned to this and then use setCoefficient() (or possibly setCoefficients()) to set the coefficients to sensible values.
Adding a variable to the array returned by getVariables() will not affect any existing coefficients. But removing one will. That is, if you erase an element of this array, the last element of the vector of coefficients is removed, not necessarily the element corresponding to the erased variable. Similarly if you insert a variable at any position other than the end, you may wish to use getCoefficients() before and setCoefficients() after to ensure that the coefficients match the variables.
Definition at line 48 of file LinearConstraint.hpp.
| LinearConstraint::LinearConstraint | ( | detail::ModelBase & | model, |
| std::string const & | name | ||
| ) |
The constructor creates a new object with no variables.
But it must be attached to a model.
| model | the Model |
| name | A name for this object |
Definition at line 28 of file LinearConstraint.cc.
References ipo::detail::Var::model.
| LinearConstraint::LinearConstraint | ( | detail::ModelBase & | model, |
| char const *const | name | ||
| ) |
The constructor creates a new object with no variables.
But it must be attached to a model.
| model | the Model |
| name | A name for this object |
Definition at line 33 of file LinearConstraint.cc.
References ipo::detail::Var::model.
| double LinearConstraint::getCoefficient | ( | Variable const & | variable | ) | const |
Get the coefficient of variable.
| variable | A Variable |
| IPOException | if variable is not a variable of this |
Definition at line 60 of file LinearConstraint.cc.
References getFunction(), ipo::Variable::getName(), ipo::Objective::getVariables(), and IPOE.
| gsl::vector const & LinearConstraint::getCoefficients | ( | ) | const |
Get all the coefficients of this LinearConstraint.
| IPOException | if function is not an ipo_function::concrete::LinearCombination |
Definition at line 82 of file LinearConstraint.cc.
References getFunction(), ipo::Objective::getVariables(), IPOE, and RETHROW.
| ipo_function::Function * LinearConstraint::getFunction | ( | ) |
Get function.
This reimplements ModeFunction::getFunction() to make sure number of coefficients matches size of array and then returns the function.
Definition at line 99 of file LinearConstraint.cc.
References ipo::Objective::getVariables(), and IPOE.
Referenced by getCoefficient(), getCoefficients(), setCoefficient(), and setCoefficients().
| bool LinearConstraint::isEqualityConstraint | ( | ) | const |
Find if this is an equality constraint (upperBound = lowerBound).
Definition at line 144 of file LinearConstraint.cc.
References ipo::Constraint::getLowerBound(), and ipo::Constraint::getUpperBound().
| void LinearConstraint::setCoefficient | ( | Variable const & | variable, |
| double const | value | ||
| ) |
Set the coefficient of variable.
| variable | A Variable |
| value | The value to set the coefficient of variable to |
| IPOException | if variable is not a variable of this |
Definition at line 39 of file LinearConstraint.cc.
References getFunction(), ipo::Variable::getName(), ipo::Objective::getVariables(), IPOE, and ipo::Objective::value().
| void LinearConstraint::setCoefficients | ( | gsl::vector const & | vector | ) |
Set all the coefficients of this LinearConstraint.
| vector | The vector of variables |
| IPOException | if number of variables and vector length do not match |
Definition at line 162 of file LinearConstraint.cc.
References getFunction(), ipo::Objective::getVariables(), IPOE, and ipo::Array::size().
|
virtual |
Set lower bound of Constraint.
This may invalidate value set if the value is less than the lower bound.
| lowerBound | The new lower bound |
| IPOException | if new lower bound greater than upper bound |
Reimplemented from ipo::Constraint.
Definition at line 128 of file LinearConstraint.cc.
References ipo::Model::addConstraint(), ipo::Objective::data, ipo::detail::Var::getModel(), IPOE, and lowerBound.
|
virtual |
Set upper bound of Constraint.
This may invalidate value set if the value is not less than the upper bound.
| upperBound | The new upper bound |
| IPOException | if new upper bound less than lower bound |
Reimplemented from ipo::Constraint.
Definition at line 112 of file LinearConstraint.cc.
References ipo::Model::addConstraint(), ipo::Objective::data, ipo::detail::Var::getModel(), IPOE, lowerBound, and upperBound.
| void LinearConstraint::setValue | ( | double const | value | ) |
Set value of Constraint.
This makes this an equality constraint if it is not one already and should be preferred to using setLowerBound() and setUpperBound().
| value | The new value |
Definition at line 149 of file LinearConstraint.cc.
References ipo::Model::addConstraint(), ipo::Objective::data, ipo::detail::Var::getModel(), and ipo::Objective::value().