29 :
Variable {
model,
nullptr == name ? std::string() : std::string { name } }{
34 : Var { model }, data { std::shared_ptr<Data>{
new Data } }
55 return data->upperBound;
60 return data->lowerBound;
66 std::ostringstream error;
67 error <<
"ipo::Variable::set(): value ";
68 error << value <<
" less than lower bound ";
70 throw IPOE( error.str() );
72 std::ostringstream error;
73 error <<
"ipo::Variable::set(): value ";
74 error << value <<
" greater than upper bound ";
76 throw IPOE( error.str() );
88 data->name =
nullptr == name ? std::string {} : std::string { name };
94 std::ostringstream error;
95 error <<
"ipo::Variable::setUpperBound(): upper bound ";
96 error << upperBound <<
" less than lower bound ";
98 throw IPOE( error.str() );
107 std::ostringstream error;
108 error <<
"ipo::Variable::setLowerBound(): lower bound ";
109 error << lowerBound <<
" greater than upper bound ";
111 throw IPOE( error.str() );
124 return lhs.
data.get() < rhs.
data.get();
130 throw IPOE(
"ipo::Variable::operator=(): cannot assign variable to different model." );
136 : Var( variable.model ), data( variable.data ){
142 if( &variable.model != &
model )
143 throw IPOE(
"ipo::Variable::operator=(): cannot assign variable to different model." );
144 data = variable.data;
150 auto f = [](
double x)->std::string {
151 std::ostringstream ost;
152 double a { std::fabs( x ) };
153 if( x < 0 ) ost <<
"−";
void setValue(double const value)
Set value of variable.
bool operator<(Array const &lhs, Array const &rhs)
Compare two Array objects.
std::shared_ptr< Data > data
The Variable data as a shared pointer.
double constexpr infinity
Infinity: use for unbounded variables.
ModelBase & model
A Model to attach this to.
void setName(std::string const &name)
Set name of variable.
virtual void summary(std::ostream &ostream=std::cout, std::string const &prefix="") const override
Create a summary of this variable.
#define IPOE(message)
Macro to allow file and line names in exceptions.
std::string getName() const
Get name of variable.
Variable & operator=(Variable const &variable)
Copy assignment operator.
Abstract base class for model.
void setLowerBound(double const lowerBound)
Set lower bound of variable.
double getUpperBound() const
Get upper bound of variable.
Variable(detail::ModelBase &model, char const *const name=nullptr)
Default constructor creates a named variable with the given name, initial value 0 and unbounded...
double getValue() const
Get value of variable.
This class represents a variable.
double getLowerBound() const
Get lower bound of variable.
double constexpr minusInfinity
Negative infinity: use for unbounded variables.
void setUpperBound(double const upperBound)
Set upper bound of variable.
bool operator==(Array const &lhs, Array const &rhs)
Compare two Array objects.
This namespace holds all the interior-point optimisation classes.