17#ifndef __CODAC2_INTERVALVECTOR_H__
18#define __CODAC2_INTERVALVECTOR_H__
24#include <ibex_LargestFirst.h>
28#include <codac2_eigen.h>
37 template<
int N=Dynamic>
38 class IntervalVector_ :
public IntervalMatrix_<N,1>
43 : IntervalMatrix_<N,1>()
46 explicit IntervalVector_(
size_t n)
47 : IntervalMatrix_<N,1>(n,1)
49 assert(N == Dynamic || N == (
int)n);
52 explicit IntervalVector_(
size_t n,
const Interval& x)
53 : IntervalMatrix_<N,1>(n,1,x)
55 assert(N == Dynamic || N == (
int)n);
58 explicit IntervalVector_(
const Interval& x)
59 : IntervalMatrix_<N,1>(N,1,x)
63 explicit IntervalVector_(
const Matrix_<M,1>& v)
64 : IntervalMatrix_<N,1>(v.size(),1)
66 static_assert(N == M || N == -1 || M == -1);
67 for(
size_t i = 0 ; i < IntervalMatrix_<N,1>::size() ; i++)
68 (*
this)[i] = Interval(v[i]);
71 explicit IntervalVector_(
size_t n,
const double bounds[][2])
72 : IntervalMatrix_<N,1>(n,1,bounds)
75 explicit IntervalVector_(
const double bounds[][2])
76 : IntervalVector_(this->size(), bounds)
79 explicit IntervalVector_(
const Vector_<N>& lb,
const Vector_<N>& ub)
80 : IntervalMatrix_<N,1>(lb, ub)
83 IntervalVector_(std::initializer_list<Interval> l)
84 : IntervalMatrix_<N,1>(l.size(),1)
86 assert(N == Dynamic || (
int)l.size() == N);
88 for(
const auto& li : l)
94 explicit IntervalVector_(
const IntervalMatrix_<M,1>& x)
95 : IntervalMatrix_<M,1>(x)
97 assert(M == Dynamic || M == N);
101 template<
typename OtherDerived>
102 IntervalVector_(
const Eigen::MatrixBase<OtherDerived>& other)
103 : IntervalMatrix_<N,1>(other)
107 template<
typename OtherDerived>
108 IntervalVector_& operator=(
const Eigen::MatrixBase<OtherDerived>& other)
110 this->IntervalMatrix_<N,1>::operator=(other);
114 void resize(
size_t n)
116 this->IntervalMatrix_<N,1>::resize(n,1);
119 template<
size_t N1,
size_t N2>
120 IntervalVector_<N2-N1+1> subvector()
const
122 assert(N1 >= 0 && N1 < N && N2 >= 0 && N2 < N && N1 <= N2);
123 return this->
template block<N2-N1+1,1>(N1,0);
126 IntervalVector_<> subvector(
size_t start_index,
size_t end_index)
const
128 assert(end_index >= 0 && start_index >= 0);
129 assert(end_index < this->size() && start_index <= end_index);
131 IntervalVector_<> s(end_index-start_index+1);
132 for(
size_t i = 0 ; i < s.size() ; i++)
133 s[i] = (*
this)[i+start_index];
137 template<
size_t I,
int M>
138 void put(
const IntervalVector_<M>& x)
140 assert(I >= 0 && I < N && M+I <= N);
141 this->
template block<M,1>(I,0) << x;
144 auto& operator+=(
const IntervalVector_<N>& x)
146 (*this).noalias() += x;
150 auto& operator-=(
const IntervalVector_<N>& x)
152 (*this).noalias() -= x;
156 std::list<IntervalVector_<N>> complementary()
const
158 return IntervalVector_<N>(this->size()).diff(*
this);
161 std::list<IntervalVector_<N>> diff(
const IntervalVector_<N>& y,
bool compactness =
true)
const
168 const size_t n = this->size();
169 assert(y.size() == n);
172 return { IntervalVector_<N>::empty_set(n) };
174 IntervalVector_<N> x = *
this;
175 IntervalVector_<N> z = x & y;
185 for(
size_t i = 0 ; i < n ; i++)
186 if(z[i].is_degenerated() && !x[i].is_degenerated())
190 std::list<IntervalVector_<N>> l;
192 for(
size_t var = 0 ; var < n ; var++)
195 x[var].diff(y[var], c1, c2, compactness);
199 IntervalVector_<N> v(n);
200 for(
size_t i = 0 ; i < var ; i++)
203 for(
size_t i = var+1 ; i < n ; i++)
209 IntervalVector_<N> w(n);
210 for(
size_t i = 0 ; i < var ; i++)
213 for(
size_t i = var+1 ; i<n ; i++)
227 std::ostream& operator<<(std::ostream& os,
const IntervalVector_<N>& x)
229 if(x.is_empty())
return os <<
"empty vector";
231 for(
size_t i = 0 ; i < x.size() ; i++)
232 os << x[i] << (i<x.size()-1 ?
" ; " :
"");
238 codac::IntervalVector to_codac1(
const IntervalVector_<N>& x)
240 ibex::IntervalVector x_(x.size());
241 for(
size_t i = 0 ; i < x.size() ; i++)
247 IntervalVector_<N> to_codac2(
const codac::IntervalVector& x)
249 assert(x.size() == N);
250 IntervalVector_<N> x_(x.size());
251 for(
size_t i = 0 ; i < x.size() ; i++)
256 class IntervalVector :
public IntervalVector_<>
260 explicit IntervalVector(
size_t n)
261 : IntervalVector_<>(n)
264 explicit IntervalVector(
size_t n,
const Interval& x)
265 : IntervalVector_<>(n, x)
268 explicit IntervalVector(
const Interval& x)
269 : IntervalVector_<>({x})
272 explicit IntervalVector(
const IntervalVector_<>& x)
273 : IntervalVector_<>(x)
277 explicit IntervalVector(
const Vector_<N>& v)
278 : IntervalVector_<>(v)
281 explicit IntervalVector(
size_t n,
const double bounds[][2])
282 : IntervalVector_<>(n, bounds)
285 IntervalVector(std::initializer_list<Interval> l)
286 : IntervalVector_<>(l)
290 template<
typename OtherDerived>
291 IntervalVector(
const Eigen::MatrixBase<OtherDerived>& other)
292 : IntervalVector_<>(other)
296 template<
typename OtherDerived>
297 IntervalVector& operator=(
const Eigen::MatrixBase<OtherDerived>& other)
299 this->IntervalVector_<>::operator=(other);
303 void resize(
size_t n)
305 this->IntervalVector_<>::resize(n);
308 static IntervalVector empty_set(
size_t n)
310 return IntervalMatrix_<>::empty_set(n,1);