Skip to content
Snippets Groups Projects

Expose box constraints as intervals

Merged pipping requested to merge (removed):feature/box-constraints-as-intervals into master
11 files
+ 42
68
Compare changes
  • Side-by-side
  • Inline
Files
11
@@ -8,63 +8,67 @@
@@ -8,63 +8,67 @@
#include <dune/common/fvector.hh>
#include <dune/common/fvector.hh>
 
#include "interval.hh"
 
template <class T, int dim>
template <class T, int dim>
class BoxConstraint {
class BoxConstraint {
public:
public:
 
using Interval = typename Dune::Solvers::Interval<T>;
/** \brief Default constructor, makes the obstacle as large as possible */
/** \brief Default constructor, makes the obstacle as large as possible */
BoxConstraint() {
BoxConstraint() {
for (int i=0; i<dim; i++) {
clear();
val[2*i] = -std::numeric_limits<T>::max();
val[2*i+1] = std::numeric_limits<T>::max();
}
}
}
/** \brief Set obstacle values to +/- std::numeric_limits<T>::max() */
/** \brief Set obstacle values to +/- std::numeric_limits<T>::max() */
void clear() {
void clear() {
for (int i=0; i<dim; i++) {
for (int i=0; i<dim; i++)
val[2*i] = -std::numeric_limits<T>::max();
val[i] = { -std::numeric_limits<T>::max(),
val[2*i+1] = std::numeric_limits<T>::max();
std::numeric_limits<T>::max() };
}
}
}
//! Subtract vector from box
//! Subtract vector from box
BoxConstraint<T,dim>& operator-= (const Dune::FieldVector<T, dim>& v)
BoxConstraint<T,dim>& operator-= (const Dune::FieldVector<T, dim>& v)
{
{
for (int i=0; i<dim; i++) {
for (int i=0; i<dim; i++) {
val[2*i] -= v[i];
val[i][0] -= v[i];
val[2*i+1] -= v[i];
val[i][1] -= v[i];
}
}
return *this;
return *this;
}
}
 
Interval const &operator[](size_t i) const {
 
return val[i];
 
}
 
Interval &operator[](size_t i) {
 
return val[i];
 
}
 
//! Access to the lower obstacles
//! Access to the lower obstacles
T& lower(size_t i) {return val[2*i];}
T& lower(size_t i) {return val[i][0];}
//! Const access to the lower obstacles
//! Const access to the lower obstacles
const T& lower(size_t i) const {return val[2*i];}
const T& lower(size_t i) const {return val[i][0];}
//! Access to the upper obstacles
//! Access to the upper obstacles
T& upper(size_t i) {return val[2*i+1];}
T& upper(size_t i) {return val[i][1];}
//! Const access to the upper obstacles
//! Const access to the upper obstacles
const T& upper(size_t i) const {return val[2*i+1];}
const T& upper(size_t i) const {return val[i][1];}
//! Send box constraint to an output stream
//! Send box constraint to an output stream
friend
friend
std::ostream& operator<< (std::ostream& s, const BoxConstraint<T,dim>& v)
std::ostream& operator<< (std::ostream& s, const BoxConstraint<T,dim>& v)
{
{
for (int i=0; i<dim; i++)
for (int i=0; i<dim; i++)
s << "Direction: " << i <<", val[0] = " << v.val[2*i]
s << "Direction: " << i <<", val[0] = " << v[i][0]
<< ", val[1] = " << v.val[2*i+1] << std::endl;
<< ", val[1] = " << v[i][1] << std::endl;
return s;
return s;
}
}
protected:
protected:
std::array<Interval, dim> val;
std::array<T, 2*dim> val;
};
};
#endif
#endif
Loading