codac
codac_Tube.h
Go to the documentation of this file.
1 
12 #ifndef __CODAC_TUBE_H__
13 #define __CODAC_TUBE_H__
14 
15 #include <map>
16 #include <list>
17 #include <vector>
18 #include "codac_TFnc.h"
19 #include "codac_Slice.h"
20 #include "codac_Trajectory.h"
21 #include "codac_serialize_tubes.h"
22 #include "codac_tube_arithmetic.h"
23 #include "codac_TubeTreeSynthesis.h"
24 #include "codac_TubePolynomialSynthesis.h"
25 #include "codac_TubeSynthesis.h"
26 #include "codac_Polygon.h"
27 #include "codac_BoolInterval.h"
28 
29 // The following define constant is now set in CMake configuration file:
30 //#define AUTO_SYNTHESIS_BY_DEFAULT false
31 
32 namespace codac
33 {
34  class TFnc;
35  class Tube;
36  class Slice;
37  class Trajectory;
38  class TubeTreeSynthesis;
39  class TubePolynomialSynthesis;
40 
47  class Tube : public DynamicalItem
48  {
49  public:
50 
53 
60  explicit Tube(const Interval& tdomain, const Interval& codomain = Interval::ALL_REALS);
61 
69  explicit Tube(const Interval& tdomain, double timestep, const Interval& codomain = Interval::ALL_REALS);
70 
84  explicit Tube(const Interval& tdomain, double timestep, const TFnc& f, int f_image_id = 0);
85 
95  explicit Tube(const std::vector<Interval>& v_tdomains, const std::vector<Interval>& v_codomains);
96 
102  Tube(const Tube& x);
103 
117  explicit Tube(const Tube& x, const TFnc& f, int f_image_id = 0);
118 
130  explicit Tube(const Trajectory& traj, double timestep);
131 
144  explicit Tube(const Trajectory& lb, const Trajectory& ub, double timestep);
145 
153  explicit Tube(const std::string& binary_file_name);
154 
164  explicit Tube(const std::string& binary_file_name, Trajectory *&traj);
165 
169  ~Tube();
170 
176  int size() const;
177 
184  const Tube primitive(const Interval& c = Interval(0.)) const;
185 
192  const Tube& operator=(const Tube& x);
193 
199  const Interval tdomain() const;
200 
206  const Polygon polygon_envelope() const;
207 
216  const Trajectory lb() const;
217 
226  const Trajectory ub() const;
227 
231 
237  int nb_slices() const;
238 
245  Slice* slice(int slice_id);
246 
253  const Slice* slice(int slice_id) const;
254 
264  Slice* slice(double t);
265 
275  const Slice* slice(double t) const;
276 
282  Slice* first_slice();
283 
289  const Slice* first_slice() const;
290 
296  Slice* last_slice();
297 
303  const Slice* last_slice() const;
304 
312  Slice* wider_slice();
313 
321  const Slice* wider_slice() const;
322 
329  Slice* largest_slice();
330 
337  const Slice* largest_slice() const;
338 
347 
355  const Slice* steepest_slice() const;
356 
363  const Interval slice_tdomain(int slice_id) const;
364 
371  int time_to_index(double t) const;
372 
379  int index(const Slice* slice) const;
380 
390  void sample(double t);
391 
404  void sample(double t, Slice *slice_to_be_sampled);
405 
415  void sample(double t, const Interval& gate);
416 
424  void sample(const Tube& x);
425 
432  bool gate_exists(double t) const;
433 
439  void remove_gate(double t);
440 
448  void merge_similar_slices(double distance_threshold);
449 
453 
459  const Interval codomain() const;
460 
469  double volume() const;
470 
477  const Interval operator()(int slice_id) const;
478 
485  const Interval operator()(double t) const;
486 
493  const Interval operator()(const Interval& t) const;
494 
502  const std::pair<Interval,Interval> eval(const Interval& t = Interval::ALL_REALS) const;
503 
514  const Interval interpol(double t, const Tube& v) const;
515 
526  const Interval interpol(const Interval& t, const Tube& v) const;
527 
537  const Interval invert(const Interval& y, const Interval& search_tdomain = Interval::ALL_REALS) const;
538 
547  void invert(const Interval& y, std::vector<Interval> &v_t, const Interval& search_tdomain = Interval::ALL_REALS) const;
548 
560  const Interval invert(const Interval& y, const Tube& v, const Interval& search_tdomain = Interval::ALL_REALS) const;
561 
573  void invert(const Interval& y, std::vector<Interval> &v_t, const Tube& v, const Interval& search_tdomain = Interval::ALL_REALS) const;
574 
580  double max_diam() const;
581 
588  double max_gate_diam(double& t) const;
589 
600  const Trajectory diam(bool gates_thicknesses = false) const;
601 
612  const Trajectory diam(const Tube& v) const;
613 
617 
627  bool operator==(const Tube& x) const;
628 
638  bool operator!=(const Tube& x) const;
639 
649  bool is_subset(const Tube& x) const;
650 
661  bool is_strict_subset(const Tube& x) const;
662 
672  bool is_interior_subset(const Tube& x) const;
673 
684  bool is_strict_interior_subset(const Tube& x) const;
685 
695  bool is_superset(const Tube& x) const;
696 
707  bool is_strict_superset(const Tube& x) const;
708 
717  bool is_empty() const;
718 
731  const BoolInterval contains(const Trajectory& x) const;
732 
742  bool overlaps(const Tube& x, float ratio = 1.) const;
743 
747 
756  const Tube& set(const Interval& y);
757 
765  const Tube& set(const Interval& y, int slice_id);
766 
778  const Tube& set(const Interval& y, double t);
779 
791  const Tube& set(const Interval& y, const Interval& t);
792 
799  const Tube& set_empty();
800 
809  const Tube& inflate(double rad);
810 
821  const Tube& inflate(const Trajectory& rad);
822 
831  Tube& truncate_tdomain(const Interval& tdomain);
832 
838  void shift_tdomain(double a);
839 
843 
855  const std::pair<Tube,Tube> bisect(double t, float ratio = 0.49) const;
856 
860 
867  const Tube& operator+=(const Interval& x);
868 
875  const Tube& operator+=(const Trajectory& x);
876 
883  const Tube& operator+=(const Tube& x);
884 
891  const Tube& operator-=(const Interval& x);
892 
899  const Tube& operator-=(const Trajectory& x);
900 
907  const Tube& operator-=(const Tube& x);
908 
915  const Tube& operator*=(const Interval& x);
916 
923  const Tube& operator*=(const Trajectory& x);
924 
931  const Tube& operator*=(const Tube& x);
932 
939  const Tube& operator/=(const Interval& x);
940 
947  const Tube& operator/=(const Trajectory& x);
948 
955  const Tube& operator/=(const Tube& x);
956 
963  const Tube& operator|=(const Interval& x);
964 
971  const Tube& operator|=(const Trajectory& x);
972 
979  const Tube& operator|=(const Tube& x);
980 
987  const Tube& operator&=(const Interval& x);
988 
995  const Tube& operator&=(const Trajectory& x);
996 
1003  const Tube& operator&=(const Tube& x);
1004 
1008 
1016  const std::string class_name() const { return "Tube"; };
1017 
1025  friend std::ostream& operator<<(std::ostream& str, const Tube& x);
1026 
1027  // Tree synthesis structure
1028 
1037  void enable_synthesis(SynthesisMode mode = SynthesisMode::BINARY_TREE, double eps = 1.e-3) const;
1038 
1042 
1052  const Interval integral(double t) const;
1053 
1063  const Interval integral(const Interval& t) const;
1064 
1075  const Interval integral(const Interval& t1, const Interval& t2) const;
1076 
1088  const std::pair<Interval,Interval> partial_integral(const Interval& t) const;
1089 
1102  const std::pair<Interval,Interval> partial_integral(const Interval& t1, const Interval& t2) const;
1103 
1107 
1116  void serialize(const std::string& binary_file_name = "x.tube", int version_number = SERIALIZATION_VERSION) const;
1117 
1129  void serialize(const std::string& binary_file_name, const Trajectory& traj, int version_number = SERIALIZATION_VERSION) const;
1130 
1132 
1143  static bool same_slicing(const Tube& x1, const Tube& x2);
1144 
1153  static void enable_syntheses(bool enable = true);
1154 
1161  static const Tube hull(const std::list<Tube>& l_tubes);
1162 
1163  protected:
1164 
1170  Tube();
1171 
1179  const IntervalVector codomain_box() const;
1180 
1190  void deserialize(const std::string& binary_file_name, Trajectory *&traj);
1191 
1197  void create_synthesis_tree() const;
1198 
1202  void delete_synthesis_tree() const;
1203 
1211  void create_polynomial_synthesis(double eps) const;
1212 
1216  void delete_polynomial_synthesis() const;
1217 
1218  // Class variables:
1219 
1220  Slice *m_first_slice = nullptr;
1221  mutable TubeTreeSynthesis *m_synthesis_tree = nullptr;
1222  mutable TubePolynomialSynthesis *m_polynomial_synthesis = nullptr;
1223  mutable SynthesisMode m_synthesis_mode = SynthesisMode::NONE;
1224  Interval m_tdomain;
1225 
1226  friend void deserialize_Tube(std::ifstream& bin_file, Tube *&tube);
1227  friend void deserialize_TubeVector(std::ifstream& bin_file, TubeVector *&tube);
1228  friend class TubeVector;
1229  friend class CtcEval;
1230 
1231  static bool s_enable_syntheses;
1232  };
1233 }
1234 
1235 #endif
double volume() const
Returns the volume of this tube.
FixPoint of a separator The fixpoint of a separator is computed by calling the "::"separate function ...
Definition: codac_capd_helpers.h:9
Slice * last_slice()
Returns a pointer to the last Slice object of this tube.
void merge_similar_slices(double distance_threshold)
Merges all adjacent slices whose Hausdorff distance is less than the given threshold.
friend std::ostream & operator<<(std::ostream &str, const Tube &x)
Displays a synthesis of this tube.
const Interval integral(double t) const
Computes the interval integral .
const Tube & operator|=(const Interval &x)
Operates |=.
bool is_subset(const Tube &x) const
Returns true if this tube is a subset of .
Tube & truncate_tdomain(const Interval &tdomain)
Truncates the tdomain of .
bool is_strict_superset(const Tube &x) const
Returns true if this tube is a superset of , and not itself.
const Tube primitive(const Interval &c=Interval(0.)) const
Returns the primitive Tube of this tube.
~Tube()
Tube destructor.
void delete_polynomial_synthesis() const
Deletes the synthesis tree of this tube.
void create_synthesis_tree() const
Creates the synthesis tree associated to the values of this tube.
TubePolynomialSynthesis * m_polynomial_synthesis
pointer to the optional synthesis tree
Definition: codac_Tube.h:1222
int size() const
Returns the dimension of the scalar tube (always 1)
bool is_empty() const
Returns true if this tube is empty.
Slice of a one dimensional tube and made of an envelope and two gates.
Definition: codac_Slice.h:33
const Interval codomain() const
Returns the interval of feasible values.
const std::string class_name() const
Returns the name of this class.
Definition: codac_Tube.h:1016
bool gate_exists(double t) const
Tests if a gate exists at time .
const Trajectory ub() const
Returns a possible upper bound of the tube.
SynthesisMode m_synthesis_mode
enables of the use of a synthesis tree
Definition: codac_Tube.h:1223
One dimensional trajectory , defined as a temporal map of values.
Definition: codac_Trajectory.h:34
void shift_tdomain(double a)
Shifts the tdomain of .
Slice * m_first_slice
pointer to the first Slice object of this tube
Definition: codac_Tube.h:1220
int index(const Slice *slice) const
Returns the Slice index related to the Slice pointer.
TubeTreeSynthesis * m_synthesis_tree
pointer to the optional synthesis tree
Definition: codac_Tube.h:1221
static void enable_syntheses(bool enable=true)
Enables the computation of a synthesis tree for any Tube object.
Tube()
Creates a not-defined scalar tube.
const std::pair< Tube, Tube > bisect(double t, float ratio=0.49) const
Bisects this tube.
Abstract class for common properties of Tube, TubeVector, Slice, Trajectory, TrajectoryVector objects...
Definition: codac_DynamicalItem.h:25
void deserialize(const std::string &binary_file_name, Trajectory *&traj)
Restores a scalar tube from serialization, together with a Trajectory object.
friend void deserialize_Tube(std::ifstream &bin_file, Tube *&tube)
Creates a Tube object from a binary file.
bool is_strict_interior_subset(const Tube &x) const
Returns true if this tube is a subset of the interior of , and not itself.
double max_gate_diam(double &t) const
Returns the diameter of the gate of this tube that is the more uncertain.
const std::pair< Interval, Interval > partial_integral(const Interval &t) const
Computes the partial interval integral .
Interval m_tdomain
redundant information for fast evaluations
Definition: codac_Tube.h:1224
const IntervalVector codomain_box() const
Returns the box .
that contracts a tube with respect to its derivative tube and a measurement according to the cons...
Definition: codac_CtcEval.h:26
n-dimensional tube , defined as an interval of n-dimensional trajectories
Definition: codac_TubeVector.h:38
void enable_synthesis(SynthesisMode mode=SynthesisMode::BINARY_TREE, double eps=1.e-3) const
Enables the computation of a synthesis tree.
friend void deserialize_TubeVector(std::ifstream &bin_file, TubeVector *&tube)
Creates a TubeVector object from a binary file.
Slice * slice(int slice_id)
Returns a pointer to the ith Slice object of this tube.
One dimensional tube , defined as an interval of scalar trajectories.
Definition: codac_Tube.h:47
void create_polynomial_synthesis(double eps) const
Creates the synthesis tree associated to the values of this tube.
const Tube & operator/=(const Interval &x)
Operates /=.
bool is_strict_subset(const Tube &x) const
Returns true if this tube is a subset of , and not itself.
void sample(double t)
Samples this tube at .
const Trajectory diam(bool gates_thicknesses=false) const
Returns the diameters of the tube as a trajectory.
Slice * wider_slice()
Returns a pointer to the Slice defined over the wider temporal domain.
bool operator==(const Tube &x) const
Returns true if this tube is equal to .
bool is_interior_subset(const Tube &x) const
Returns true if this tube is a subset of the interior of .
const Polygon polygon_envelope() const
Returns the polygon envelope of this tube.
const Interval tdomain() const
Returns the temporal definition domain of this tube.
void remove_gate(double t)
Removes the gate at and merges the two related slices.
int time_to_index(double t) const
Returns the Slice index related to the temporal key .
const BoolInterval contains(const Trajectory &x) const
Returns true if this tube contains the trajectory .
static const Tube hull(const std::list< Tube > &l_tubes)
Computes the hull of several tubes.
void delete_synthesis_tree() const
Deletes the synthesis tree of this tube.
const Interval slice_tdomain(int slice_id) const
Returns the temporal definition domain of the ith Slice of this tube.
Slice * first_slice()
Returns a pointer to the first Slice object of this tube.
double max_diam() const
Returns the diameter of the interval value that is the more uncertain.
const Trajectory lb() const
Returns a possible lower bound of the tube.
const Tube & operator &=(const Interval &x)
Operates &=.
Slice * steepest_slice()
Returns a pointer to the Slice object of this tube for which the difference between the mid values of...
const std::pair< Interval, Interval > eval(const Interval &t=Interval::ALL_REALS) const
Returns the interval evaluations of the bounds of the tube and over .
const Interval operator()(int slice_id) const
Returns the value of the ith slice.
bool overlaps(const Tube &x, float ratio=1.) const
Returns true if this tube overlaps the tube .
const Tube & operator*=(const Interval &x)
Operates *=.
static bool same_slicing(const Tube &x1, const Tube &x2)
Tests whether the two Tube objects are sharing the same slicing.
const Tube & inflate(double rad)
Inflates this tube by adding to all its codomain components.
const Interval interpol(double t, const Tube &v) const
Returns the optimal evaluation of this tube at , based on the derivative information ...
bool operator!=(const Tube &x) const
Returns true if this tube is different from .
const Interval invert(const Interval &y, const Interval &search_tdomain=Interval::ALL_REALS) const
Returns the interval inversion .
bool is_superset(const Tube &x) const
Returns true if this tube is a superset of .
const Tube & operator=(const Tube &x)
Returns a copy of a Tube.
Slice * largest_slice()
Returns a pointer to the Slice object of this tube for which the interval value is the most uncertain...
void serialize(const std::string &binary_file_name="x.tube", int version_number=SERIALIZATION_VERSION) const
Serializes this tube.
const Tube & operator+=(const Interval &x)
Operates +=.
const Tube & operator-=(const Interval &x)
Operates -=.
const Tube & set_empty()
Sets this tube to the empty set.
int nb_slices() const
Returns the number of slices of this tube.