29 std::string
const&
name )
30 : name { name }, array { alloc }
32 if( not testModelMatch(
model ) )
33 throw IPOE(
"ipo::Array::Data::Data: at least one variable discarded because it is "
34 "not owned by model that owns array." );
41 for(
size_t i { 0 }; i <
size; ++i ){
49 std::vector<Variable>::value_type
const& val,
50 std::vector<Variable>::allocator_type alloc, std::string
const&
name )
51 : name { name }, array {
size, val, alloc }
53 if( not testModelMatch(
model ) )
54 throw IPOE(
"ipo::Array::Data::Data: at least one variable discarded because it is "
55 "not owned by model that owns array." );
61 if( not testModelMatch(
model ) )
62 throw IPOE(
"ipo::Array::Data::Data: at least one variable discarded because it is "
63 "not owned by model that owns array." );
67 std::vector<Variable>::allocator_type
const& alloc )
70 if( not testModelMatch(
model ) )
71 throw IPOE(
"ipo::Array::Data::Data: at least one variable discarded because it is "
72 "not owned by model that owns array." );
76 std::vector<Variable>::allocator_type
const& alloc,
77 char const*
const name )
78 : name {
nullptr == name ? std::string() : std::string { name } }, array { init, alloc }
80 if( not testModelMatch(
model ) )
81 throw IPOE(
"ipo::Array::Data::Data: at least one variable discarded because it is "
82 "not owned by model that owns array." );
86 std::vector<Variable>::allocator_type
const& alloc,
87 std::string
const name )
88 : name { name }, array { init, alloc }
90 if( not testModelMatch(
model ) )
91 throw IPOE(
"ipo::Array::Data::Data: at least one variable discarded because it is "
92 "not owned by model that owns array." );
96 char const*
const name )
97 : name {
nullptr == name ? std::string() : std::string { name } }, array { init }
99 if( not testModelMatch(
model ) )
100 throw IPOE(
"ipo::Array::Data::Data: at least one variable discarded because it is "
101 "not owned by model that owns array." );
105 std::string
const&
name )
106 : name { name }, array { init }
108 if( not testModelMatch(
model ) )
109 throw IPOE(
"ipo::Array::Data::Data: at least one variable discarded because it is "
110 "not owned by model that owns array." );
114 :
Array {
model, 0,
nullptr == name ? std::string {} : std::string { name } }
121 dataArray { std::shared_ptr<Data> {
new Data { model,
static_cast<size_t>( 0 ),
name } } }
127 :
Array {
model,
size,
nullptr == name ? std::string {} : std::string { name } }
133 : Var { model }, dataArray { std::shared_ptr<Data> {
new Data { model, size,
name } } }
141 dataArray { std::shared_ptr<Data> {
new Data { model, size, val, alloc,
name } } }
149 dataArray { std::shared_ptr<Data> {
new Data { model, size, val, alloc,
name } } }
155 std::string
const&
name )
157 dataArray { std::shared_ptr<Data> {
new Data { model, size, val, allocator_type{},
name } } }
163 char const *
const name )
165 dataArray { std::shared_ptr<Data> {
new Data { model, size, val, allocator_type{},
name } } }
171 : Var { array.
model },
172 dataArray { std::shared_ptr<Data> {
new Data { model, *array.dataArray } } }
178 : Var { array.
model },
179 dataArray { std::shared_ptr<Data> {
new Data { model, *array.dataArray, alloc } } }
185 std::vector<Variable>::allocator_type
const& alloc,
186 char const*
const name )
188 dataArray { std::shared_ptr<Data> {
new Data { model, init, alloc,
name } } }
194 std::vector<Variable>::allocator_type
const& alloc,
195 std::string
const&
name )
197 dataArray { std::shared_ptr<Data> {
new Data { model, init, alloc,
name } } }
203 char const*
const name )
204 : Var { model }, dataArray { std::shared_ptr<Data> {
new Data { model, init,
name } } }
210 std::string
const&
name )
211 : Var { model }, dataArray { std::shared_ptr<Data> {
new Data { model, init,
name } } }
234 throw IPOE(
"ipo::Array::swap: arrays not swapped because they are "
235 "owned by different models." );
242 if( &array.model != &
model )
243 throw IPOE(
"ipo::Array::operator=(): cannot assign array to different model." );
251 throw IPOE(
"ipo::Array::operator=(): cannot assign array to different model." );
258 bool result {
true };
259 auto p =
array.begin();
260 while( p !=
array.end() )
261 if( p->getModel() != &
model ){
262 p =
array.erase( p );
270 if( value.getModel() !=
getModel() )
271 throw IPOE(
"ipo::Array::assign: variable not assigned because it is "
272 "not owned by model that owns array." );
281 throw IPOE(
"ipo::Array::assign: at least one variable discarded because it is "
282 "not owned by model that owns array." );
288 if( value.getModel() !=
getModel() )
289 throw IPOE(
"ipo::Array::insert: variable not inserted because it is "
290 "not owned by model that owns array." );
292 return dataArray->array.insert( pos, value );
297 if( value.getModel() !=
getModel() )
298 throw IPOE(
"ipo::Array::insert: variable not inserted because it is "
299 "not owned by model that owns array." );
301 return dataArray->array.insert( pos, value );
306 if( value.getModel() !=
getModel() )
307 throw IPOE(
"ipo::Array::insert: variable not inserted because it is "
308 "not owned by model that owns array." );
309 dataArray->array.insert( pos, count, value );
317 throw IPOE(
"ipo::Array::insert: at least one variable discarded because it is "
318 "not owned by model that owns array." );
324 if( value.getModel() !=
getModel() )
325 throw IPOE(
"ipo::Array::push_back: variable not inserted because it is "
326 "not owned by model that owns array." );
333 if( value.getModel() !=
getModel() )
334 throw IPOE(
"ipo::Array::push_back: variable not inserted because it is "
335 "not owned by model that owns array." );
343 throw IPOE(
"ipo::Array::resize: array not resized because new values would"
344 "not be owned by model that owns array." );
351 return std::find(
begin(),
end(), variable ) !=
end();
356 size_t const sizeV { vector.size() };
357 if( sizeV !=
size() )
358 throw IPOE(
"ipo::Array::setValue(): "
359 "sizes of vector and array do not match." );
360 for(
size_t i { 0 }; i < sizeV; ++i ) (*
this)[i].setValue( vector[i] );
365 size_t const sizeA {
size() };
366 gsl::vector vector( sizeA );
367 for(
size_t i { 0 }; i < sizeA; ++i ) vector[i] = (*
this)[i].getValue();
373 ostream << prefix <<
getName() <<
":" << std::endl;
374 for(
auto const& e : *
this ){
376 e.summary( ostream, prefix );
void setName(std::string const &name)
Set name of variable.
std::string name
The name of the array.
std::vector< Variable >::iterator iterator
Iterator type.
void swap(Array &array)
Swap contents of container with those of another.
void push_back(value_type const &value)
Insert value at end of array.
void setValue(gsl::vector const &vector)
Set the value of this from a gsl::vector.
ModelBase & model
A Model to attach this to.
std::vector< Variable > array
The array.
iterator end()
Get iterator to end of range.
Data(detail::ModelBase &model, std::vector< Variable >::allocator_type alloc, std::string const &name)
Constructor.
bool contains(Variable const &variable) const
Check whether or not array contains variable.
size_type size() const
Get size of array.
void assign(size_type count, value_type const &value)
Assign values.
std::shared_ptr< Data > dataArray
The Variable dataArray as a shared pointer.
#define IPOE(message)
Macro to allow file and line names in exceptions.
Abstract base class for model.
Array & operator=(Array &&array)
Move assignment operator.
void swap(Array &first, Array &second)
Swap contents of container with those of another.
Array(detail::ModelBase &model, allocator_type const &alloc=allocator_type(), char const *const name=nullptr)
Default constructor.
gsl::vector getValue() const
Create a gsl::vector containing the values of this in order.
virtual void summary(std::ostream &ostream=std::cout, std::string const &prefix="") const override
Create a summary of this Array object.
This class represents a variable.
std::string getName() const
Get name of variable.
std::vector< Variable >::value_type value_type
Value type.
This class represents an array of Variable objects.
virtual void notify()=0
Notify function that model must implement.
Struct to contain Array dataArray.
void resize(size_type count)
Resize array.
iterator insert(iterator pos, value_type const &value)
Insert value before position given by iterator pos.
ModelBase const *const getModel() const
Get pointer to model.
std::vector< Variable >::size_type size_type
Size type.
iterator begin()
Get iterator to beginning of range.
std::vector< Variable >::allocator_type allocator_type
Allocator type.
bool testModelMatch(detail::ModelBase const &model)
Test model match and remove any Vraiable objects that fail.
This namespace holds all the interior-point optimisation classes.