codac  1.5.7
codac_ContractorNetwork.h
Go to the documentation of this file.
1 
12 #ifndef __CODAC_CONTRACTORNETWORK_H__
13 #define __CODAC_CONTRACTORNETWORK_H__
14 
15 #include <deque>
16 #include <initializer_list>
17 #include <unordered_map>
18 #include "codac_Ctc.h"
19 #include "codac_DynCtc.h"
20 #include "codac_Domain.h"
21 #include "codac_CtcDeriv.h"
22 #include "codac_Hashcode.h"
23 #include "codac_Contractor.h"
24 #include "codac_Variable.h"
25 
26 namespace ibex
27 {
28  class Ctc;
29 }
30 
31 namespace codac
32 {
33  class Variable;
34  class Domain;
35  class DynCtc;
36  class CtcDeriv;
37  class DomainHashcode;
38  class ContractorHashcode;
39 
49  {
50  public:
51 
54 
59 
64 
70  int nb_ctc() const;
71 
77  int nb_dom() const;
78 
84  bool emptiness() const;
85 
89 
101  Interval& create_interm_var(const Interval& i);
102  Interval& create_dom(const Interval& i); // deprecated
103 
115  IntervalVector& create_interm_var(const IntervalVector& iv);
116  IntervalVector& create_dom(const IntervalVector& iv); // deprecated
117 
130  Tube& create_dom(const Tube& t); // deprecated
131 
144  TubeVector& create_dom(const TubeVector& tv); // deprecated
145 
157  IntervalVector& subvector(Vector& v, int start_index, int end_index);
158 
167  IntervalVector& subvector(IntervalVector& iv, int start_index, int end_index);
168 
169  // not yet suported: /**
170  // not yet suported: * \brief Creates a subvector of a TubeVector domain
171  // not yet suported: *
172  // not yet suported: * \param tv TubeVector domain
173  // not yet suported: * \param start_index first component index of the subvector to be returned
174  // not yet suported: * \param end_index last component index of the subvector to be returned
175  // not yet suported: * \return a reference to the created TubeVector extracted from the TubeVector domain
176  // not yet suported: */
177  // not yet suported: TubeVector& subvector(TubeVector& tv, int start_index, int end_index);
178 
188  void add(Ctc& static_ctc, const std::vector<Domain>& v_domains);
189 
200  void add(DynCtc& dyn_ctc, const std::vector<Domain>& v_domains);
201 
202 
203  void add(ContractorNetwork& cn);
204 
218  void add_data(Tube& x, double t, const Interval& y);
219 
233  void add_data(TubeVector& x, double t, const IntervalVector& y);
234 
238 
247  double contract(bool verbose = false);
248 
258  double contract(const std::unordered_map<Domain,Domain>& var_dom, bool verbose = false);
259 
260  double contract_ordered_mode(bool verbose = false);
261 
274  double contract_during(double dt, bool verbose = false);
275 
290  void set_fixedpoint_ratio(float r);
291 
299 
304 
312  int nb_ctc_in_stack() const;
313 
314  int iteration_nb() const;
315 
316 
320 
327  void set_name(Domain dom, const std::string& name);
328 
335  void set_name(Ctc& ctc, const std::string& name);
336 
343  void set_name(DynCtc& ctc, const std::string& name);
344 
358  int print_dot_graph(const std::string& cn_name = "cn", const std::string& layer_model = "fdp") const;
359 
367  friend std::ostream& operator<<(std::ostream& str, const ContractorNetwork& cn);
368 
370 
371  protected:
372 
383  Domain* add_dom(const Domain& ad);
384 
395  Contractor* add_ctc(const Contractor& ac);
396 
403  void add_ctc_to_queue(Contractor *ac, std::deque<Contractor*>& ctc_deque);
404 
405  void reset_value(Domain *dom);
406 
413  void trigger_ctc_related_to_dom(Domain *dom, Contractor *ctc_to_avoid = nullptr);
414 
415  void replace_var_by_dom(Domain var, Domain dom);
416 
417  protected:
418 
419  std::map<DomainHashcode,Domain*> m_map_domains;
420  std::map<ContractorHashcode,Contractor*> m_map_ctc;
421  std::deque<Contractor*> m_deque;
422 
423  int m_iteration_nb = 0;
424  float m_fixedpoint_ratio = 0.0001;
425  double m_contraction_duration_max = std::numeric_limits<double>::infinity();
426 
427  CtcDeriv *m_ctc_deriv = nullptr;
428  std::list<std::pair<Domain*,Domain*> > m_domains_related_to_ctcderiv;
429 
430  friend class Domain;
431  friend class Contractor;
432  };
433 }
434 
435 #endif
Graph of contractors and domains that model a problem in the constraint programming framework....
Definition: codac_ContractorNetwork.h:49
Domain * add_dom(const Domain &ad)
Adds an abstract Domain to the graph.
void set_fixedpoint_ratio(float r)
Sets the fixed point ratio defining the end of the propagation process.
int nb_dom() const
Returns the number of domains the graph is made of.
float m_fixedpoint_ratio
fixed point ratio for propagation limit
Definition: codac_ContractorNetwork.h:424
TubeVector & create_interm_var(const TubeVector &tv)
Creates a TubeVector intermediate variable with a reference kept in the ContractorNetwork....
Tube & create_interm_var(const Tube &t)
Creates a Tube intermediate variable with a reference kept in the ContractorNetwork....
double contract(const std::unordered_map< Domain, Domain > &var_dom, bool verbose=false)
Launch the contraction process with specified domains in place of Variables objects.
std::map< DomainHashcode, Domain * > m_map_domains
pointers to the abstract Domain objects the graph is made of
Definition: codac_ContractorNetwork.h:419
IntervalVector & subvector(IntervalVector &iv, int start_index, int end_index)
Creates a subvector of an IntervalVector domain.
IntervalVector & subvector(Vector &v, int start_index, int end_index)
Creates a subvector of a Vector domain.
int nb_ctc() const
Returns the number of contractors the graph is made of.
bool emptiness() const
Returns true if one of the domains is empty, false otherwise.
ContractorNetwork()
Creates an empty Contractor Network (CN)
double contract_during(double dt, bool verbose=false)
Launch the contraction process and stops after seconds.
std::map< ContractorHashcode, Contractor * > m_map_ctc
pointers to the abstract Contractor objects the graph is made of
Definition: codac_ContractorNetwork.h:420
int print_dot_graph(const std::string &cn_name="cn", const std::string &layer_model="fdp") const
Generates a dot graph for visualization in PDF file format, by using dot2tex.
int nb_ctc_in_stack() const
Returns the number of contractors that are waiting for process.
void set_name(Domain dom, const std::string &name)
Sets a string name for a given Domain.
void trigger_ctc_related_to_dom(Domain *dom, Contractor *ctc_to_avoid=nullptr)
Triggers on the contractors related to the given Domain.
~ContractorNetwork()
ContractorNetwork destructor.
Interval & create_interm_var(const Interval &i)
Creates an Interval intermediate variable with a reference kept in the ContractorNetwork....
double m_contraction_duration_max
computation time limit
Definition: codac_ContractorNetwork.h:425
void add(DynCtc &dyn_ctc, const std::vector< Domain > &v_domains)
Adds to the graph a dynamic contractor (inherited from DynCtc class) with related Domains.
void reset_interm_vars()
Resets the initial value of the domains declared as intermediate variables.
CtcDeriv * m_ctc_deriv
optional pointer to a CtcDeriv object that can be automatically added in the graph
Definition: codac_ContractorNetwork.h:427
void add_data(Tube &x, double t, const Interval &y)
Adds continuous data to a tube at (used for realtime applications).
Contractor * add_ctc(const Contractor &ac)
Adds an abstract Contractor to the graph.
void add(Ctc &static_ctc, const std::vector< Domain > &v_domains)
Adds to the graph a static contractor (inherited from Ctc class) with related Domains.
IntervalVector & create_interm_var(const IntervalVector &iv)
Creates an IntervalVector intermediate variable with a reference kept in the ContractorNetwork....
void add_data(TubeVector &x, double t, const IntervalVector &y)
Adds continuous data to a tube at (used for realtime applications).
double contract(bool verbose=false)
Launch the contraction process.
std::deque< Contractor * > m_deque
queue of active contractors
Definition: codac_ContractorNetwork.h:421
void trigger_all_contractors()
Triggers on all contractors involved in the graph.
void set_name(Ctc &ctc, const std::string &name)
Sets a string name for a given static contractor.
void set_name(DynCtc &ctc, const std::string &name)
Sets a string name for a given dynamic contractor.
friend std::ostream & operator<<(std::ostream &str, const ContractorNetwork &cn)
Displays a synthesis of this ContractorNetwork.
void add_ctc_to_queue(Contractor *ac, std::deque< Contractor * > &ctc_deque)
Adds a Contractor object in the queue of active contractors.
that contracts a tube with respect to its derivative tube according to the constraint
Definition: codac_CtcDeriv.h:31
Contractor interface.
Definition: codac_DynCtc.h:61
One dimensional tube , defined as an interval of scalar trajectories.
Definition: codac_Tube.h:48
n-dimensional tube , defined as an interval of n-dimensional trajectories
Definition: codac_TubeVector.h:39
FixPoint of a separator The fixpoint of a separator is computed by calling the "::"separate function ...
Definition: codac_capd_helpers.h:9