41 auto p = std::find( variables.begin(), variables.end(), variable );
42 if( variables.end() == p ){
44 std::ostringstream ost(
"ipo::LinearConstraint::setCoefficient(): " );
45 ost <<
"variable " << variable.
getName()
46 <<
" is not a variable of LinearConstraint object.";
47 throw IPOE( ost.str() );
52 throw IPOE(
"ipo::LinearConstraint::setCoefficient(): "
53 "function must be an ipo_function::concrete::LinearCombination." );
56 q->setCoefficient( p - variables.begin(),
value );
62 auto p = std::find( variables.begin(), variables.end(), variable );
63 if( variables.end() == p ){
65 std::ostringstream ost(
"ipo::LinearConstraint::getCoefficient(): " );
66 ost <<
"variable " << variable.
getName()
67 <<
" is not a variable of LinearConstraint object.";
68 throw IPOE( ost.str() );
74 throw IPOE(
"ipo::LinearConstraint::getCoefficient(): "
75 "function must be an ipo_function::concrete::LinearCombination." );
77 q->resize( const_cast<LinearConstraint*>(
this )->
getVariables().size() );
78 return q->getCoefficient( p - variables.begin() );
87 throw IPOE(
"ipo::LinearConstraint::notify(): "
88 "function must be an ipo_function::concrete::LinearCombination." );
90 p->resize( const_cast<LinearConstraint*>(
this )->
getVariables().size() );
92 return p->getCoefficients();
94 RETHROW(
"ipo::getCoefficients()" );
104 throw IPOE(
"ipo::LinearConstraint::notify(): "
105 "function must be an ipo_function::concrete::LinearCombination." );
108 return function.get();
114 throw IPOE(
"ipo::LinearConstraint::setUpperBound(): "
115 "upper bound must be at least lower." );
117 bool const removed { (
data->lowerBound ==
data->upperBound)
118 != (
data->lowerBound == upperBound)
120 removeConstraint( *
this ) };
129 if(
data->upperBound < lowerBound )
130 throw IPOE(
"ipo::LinearConstraint::setLowerBound(): "
131 "upper bound must be at least lower." );
133 bool const removed { (
data->lowerBound ==
data->upperBound)
134 != (lowerBound ==
data->upperBound)
136 removeConstraint( *
this ) };
151 bool const removed { (
data->lowerBound !=
data->upperBound)
152 and const_cast<Model*>( dynamic_cast<Model const*>(
getModel() ) )->
153 removeConstraint( *
this ) };
164 if( SIZE != vector.size() ){
166 std::ostringstream ost(
"ipo::LinearConstraint::setCoefficients(): " );
167 ost <<
"constraint has " << SIZE <<
" variables"
168 <<
" but vector of " << vector.size() <<
"coefficients supplied.";
169 throw IPOE( ost.str() );
174 throw IPOE(
"ipo::LinearConstraint::setCoefficient(): "
175 "function must be an ipo_function::concrete::LinearCombination." );
178 for(
size_t i { 0 }; i < SIZE; ++i ) q->setCoefficient( i, vector.get( i ) );
void setValue(double const value)
Set value of Constraint.
virtual void setUpperBound(double const upperBound)
Set upper bound of Constraint.
Shared pointer to ipo::Function object.
double getCoefficient(Variable const &variable) const
Get the coefficient of variable.
ModelBase & model
A Model to attach this to.
This class provides function objects representing linear combinations of the elements of their vector...
size_type size() const
Get size of array.
bool isEqualityConstraint() const
Find if this is an equality constraint (upperBound = lowerBound).
Array & getVariables()
Get variables used by Objective function.
void setCoefficients(gsl::vector const &vector)
Set all the coefficients of this LinearConstraint.
std::shared_ptr< Data > data
The objective data.
Namespace to hold concrete functions.
Class to represent a linear combination as an Objective or Constraint.
#define IPOE(message)
Macro to allow file and line names in exceptions.
virtual void setLowerBound(double const lowerBound)
Set lower bound of Constraint.
std::string getName() const
Get name of variable.
Class for a constraint function.
Model an interior-point optimisation problem.
LinearConstraint(detail::ModelBase &model, std::string const &name)
The constructor creates a new object with no variables.
Abstract base class for model.
#define RETHROW(function)
Macro to allow file and line names in exceptions.
double getLowerBound() const
Get lower bound of Constraint.
double value() const noexcept
Value of the objective function at the current value of the variables.
This class computes a function at a vector.
This class represents a variable.
Objects of this class are used to store information about an exception generated by ipo objects and f...
void setCoefficient(Variable const &variable, double const value)
Set the coefficient of variable.
double getUpperBound() const
Get upper bound of Constraint.
ModelBase const *const getModel() const
Get pointer to model.
virtual ::ipo_function::Function * getFunction()
Get function.
void addConstraint(Constraint &constraint)
Add a constraint.
gsl::vector const & getCoefficients() const
Get all the coefficients of this LinearConstraint.
This namespace holds all the interior-point optimisation classes.