Interior-point-optimisation  1.0-1
Interior-pointoptimisationlibrary
Variable.hpp
Go to the documentation of this file.
1 /*
2  * $Id: Variable.hpp 226 2014-11-17 17:53:01Z jdl3 $
3  * Copyright (C) 2013, 2014 John D Lamb
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef IPO_VARIABLE_HPP
21 #define IPO_VARIABLE_HPP
22 
23 #include<string>
24 #include<memory>
25 #include<sstream>
26 #include<cmath>
27 #include"detail/Var.hpp"
28 #include"detail/Format.hpp"
29 
30 namespace ipo {
36  class Variable : public detail::Var {
37  public:
44  Variable( detail::ModelBase& model, char const* const name = nullptr );
51  Variable( detail::ModelBase& model, std::string const& name );
55  double getValue() const;
60  std::string getName() const;
65  void setName( std::string const& name );
70  void setName( char* const name );
74  double getUpperBound() const;
78  double getLowerBound() const;
84  void setValue( double const value );
91  void setUpperBound( double const upperBound );
98  void setLowerBound( double const lowerBound );
103  Variable( Variable const& variable );
109  Variable& operator=( Variable const& variable );
114  Variable( Variable&& variable ) : Var( variable.model ), data( variable.data ){}
120  Variable& operator=( Variable&& variable );
127  virtual void summary( std::ostream& ostream = std::cout,
128  std::string const& prefix = "" ) const override;
129  private:
133  struct Data {
137  double value;
141  std::string name;
145  double lowerBound;
149  double upperBound;
150  };
154  std::shared_ptr<Data> data;
155  // Friend declarations
156  friend bool ipo::operator==( Variable const&, Variable const& );
157  friend bool ipo::operator<( Variable const&, Variable const& );
158  };
159 
166  bool operator==( Variable const& lhs, Variable const& rhs );
174  bool operator<( Variable const& lhs, Variable const& rhs );
175 
176 }
177 
178 #endif
Var(ModelBase &model)
Constructor needs a model so that variable can only be attached to one model.
Definition: Var.cc:28
void setValue(double const value)
Set value of variable.
Definition: Variable.cc:64
bool operator<(Array const &lhs, Array const &rhs)
Compare two Array objects.
Definition: Array.hpp:704
std::shared_ptr< Data > data
The Variable data as a shared pointer.
Definition: Variable.hpp:154
ModelBase & model
A Model to attach this to.
Definition: Var.hpp:101
double lowerBound
The lower bound of the variable.
Definition: Variable.hpp:145
void setName(std::string const &name)
Set name of variable.
Definition: Variable.cc:82
virtual void summary(std::ostream &ostream=std::cout, std::string const &prefix="") const override
Create a summary of this variable.
Definition: Variable.cc:149
std::string getName() const
Get name of variable.
Definition: Variable.cc:49
Variable & operator=(Variable const &variable)
Copy assignment operator.
Definition: Variable.cc:128
Abstract base class for model.
Definition: Var.hpp:39
void setLowerBound(double const lowerBound)
Set lower bound of variable.
Definition: Variable.cc:105
double value
The value of the variable.
Definition: Variable.hpp:137
double upperBound
The upper bound of the variable.
Definition: Variable.hpp:149
double getUpperBound() const
Get upper bound of variable.
Definition: Variable.cc:54
Variable(detail::ModelBase &model, char const *const name=nullptr)
Default constructor creates a named variable with the given name, initial value 0 and unbounded...
Definition: Variable.cc:28
double getValue() const
Get value of variable.
Definition: Variable.cc:44
This class represents a variable.
Definition: Variable.hpp:36
double getLowerBound() const
Get lower bound of variable.
Definition: Variable.cc:59
std::string name
The name of the variable.
Definition: Variable.hpp:141
data lowerBound
Definition: Variable.cc:39
data name
Definition: Variable.cc:37
Variable(Variable &&variable)
Move constructor.
Definition: Variable.hpp:114
data upperBound
Definition: Variable.cc:38
Struct to contain Variable data.
Definition: Variable.hpp:133
Abstract base class for Variable and Array;.
Definition: Var.hpp:49
void setUpperBound(double const upperBound)
Set upper bound of variable.
Definition: Variable.cc:92
bool operator==(Array const &lhs, Array const &rhs)
Compare two Array objects.
Definition: Array.hpp:688
This namespace holds all the interior-point optimisation classes.
Definition: Array.hpp:28