Developer documentation

solver_fatarcs.hpp
Go to the documentation of this file.
1 # include <realroot/fatarcs.hpp>
4 
5 #pragma once
6 
7 using namespace mmx;
8 
9 
11 // solver_fatarcs struct
12 
13 template<class C>
15 {
16 
17  typedef std::vector<C> vec_t;
18  typedef domain<C> box_t;
22  typedef std::stack< box_t > stbox_t;
24 
26  bernstein_t poly1, poly2;
27 
28  //CONSTRUCTOR
29  solver_mv_fatarcs(bernstein_t p1, bernstein_t p2, C eps){poly1=p1; poly2=p2; epsilon=eps; };
30 
31 
32  //FCTS
33 
34  box_t box_gen(box_rep_t m1, box_rep_t m2, int MTH)
35  {
36 
37  arc_rep_t mc1,mc2;
38  Seq<vec_t> l1=m1.event_list();
39  if(l1.size()==4){mc1=median(m1, l1, MTH);}else{mc1=arc_rep_t();};
40  Seq<vec_t> l2=m2.event_list();
41  if(l2.size()==4){mc2=median(m2, l2, MTH);}else{mc2=arc_rep_t();};
42 
43  box_t bbox=m1.box;
44 
45  if(is_arc(mc1) && is_arc(mc2)){
46 
47  C c1=m1.min_grad();//std::cout << c1 <<std::endl;
48  C c2=m2.min_grad();//std::cout << c2 <<std::endl;
49  if(c1>C(0) && c2>C(0) ){
50  C r1=m1.max_eval(mc1)/sqrt(c1);//std::cout << r1 <<std::endl;
51  C r2=m2.max_eval(mc2)/sqrt(c2);//std::cout << r2 <<std::endl;
52  Seq<vec_t> extrema;
53  extrema=extpts(mc1,r1,mc2,r2);
54 
55  bbox=minmax_box(extrema, m1.box);
56  }else{/*std::cout << "no grad "<<std::endl;*/}
57  }else{/*std::cout << "no med "<<std::endl;*/}
58 
59  return(bbox);
60  };/*box around fatarc intersection*/
61 
62 
63 
64 void prepro(bernstein_t & pol1, bernstein_t & pol2, vec_t midpt)
65  {
66  bernstein_t p1=pol1,p2=pol2;
67  C c1x,c1y,c2x,c2y;
68  tensor::eval(c1x, diff(p1,0).rep(),midpt);
69  tensor::eval(c2x, diff(p2,0).rep(),midpt);
70  tensor::eval(c1y, diff(p1,1).rep(),midpt);
71  tensor::eval(c2y, diff(p2,1).rep(),midpt);
72  if(c1x!=c1y && c2x!=c2y){
73  pol1=c1x*p1+c2x*p2;
74  pol2=c1y*p1+c2y*p2; }
75 };
76 
78 
79  seqbox_t solver(int MTH){
80  stbox_t list, mo;
81  seqbox_t moseq;
82 
83  int subdiv=0;
84  int arcgen=0;
85  int it=0;
86 
87  box_t unit(int(2));
88  box_t p[4];
89  list.push(unit);
90 
91  while(!list.empty()){it++;
92 
93  box_t rec=list.top();
94 
95  list.pop();
96 
97  box_rep_t m1(poly1, rec);
98  box_rep_t m2(poly2, rec);
99 
100  if(m1.not_empty() && m2.not_empty()){
101 
102  // prepro( m1.poly, m2.poly, (rec.llc()+rec.urc())/((coeff_t)(2)));
103  // std::cout <<"b"<<std::endl;
104  box_t newrec=box_gen(m1, m2, MTH); arcgen++;
105 
106 
107  if(newrec.dim()==0){ //std::cout <<"no fatarc intersection"<<std::endl;
108  }else{ //std::cout <<"new"<<std::endl;newrec.print(5);
109  if(newrec.diam() <( rec.diam()/ C(2) ) ){;
110 
111  if(newrec.diam()<epsilon){mo.push(newrec);//std::cout <<"small1"<<std::endl; newrec.print(6);
112  }
113  else{list.push(newrec);//std::cout <<"list new"<<std::endl;
114  }
115 
116  }
117  else{
118  if(rec.diam()<epsilon){mo.push(rec);}
119  else{rec.split(p);subdiv++;/*std::cout <<"sub1"<<std::endl;*/
120  for(int i=0; i<4; i++){list.push(p[3-i]);}
121  }
122 
123  };
124 
125  };
126 
127  }else{//std::cout <<"empty"<<std::endl;
128  };
129  }
130 
131 
132 
133 std::cout << " * * * * * "<<std::endl;
134 std::cout << "iteration: "<<it<<std::endl;
135 std::cout << "subdivisoins: "<<subdiv<<std::endl;
136 std::cout << "try fatarc generation: "<<arcgen<<std::endl;
137 //std::cout << "solution: "<<mo.size()<<std::endl;
138 
139 
140  while(!mo.empty()){
141 
142  box_t rb=mo.top();
143  moseq<< rb;
144  mo.pop();
145  };
146 
147  return moseq;
148 
149 
150  }/*solver*/
151 
152 
153 };//end of structure solver_mv_fatarcs
154 
156 // TEST
158 
159 
160 template<class C>
162  polynomial< C, with<Bernstein> > p2, C eps )
163 {
164  int MTH=1;
165  solver_mv_fatarcs<C> sys( p1, p2, eps);
166  return sys.solver(MTH);
167 }
Seq< std::vector< C > > extpts(arc_rep< C > mc1, C r1, arc_rep< C > mc2, C r2)
Definition: fatarcs_fcts.hpp:432
bool not_empty()
Definition: fatarcs.hpp:338
std::vector< C > vec_t
Definition: solver_fatarcs.hpp:17
Sequence of terms with reference counter.
Definition: Seq.hpp:28
Seq< domain< C > > solve_bv_fatarcs(polynomial< C, with< Bernstein > > p1, polynomial< C, with< Bernstein > > p2, C eps)
Definition: solver_fatarcs.hpp:161
TMPL Polynomial diff(const Polynomial &pol, int v)
Multivariate Polynomial Differentiation.
Definition: polynomial_fcts.hpp:99
Seq< box_t > seqbox_t
Definition: solver_fatarcs.hpp:23
coeff_t max_eval(arc_rep_t circ)
Definition: fatarcs.hpp:437
solver_mv_fatarcs(bernstein_t p1, bernstein_t p2, C eps)
Definition: solver_fatarcs.hpp:29
R & rep(R &r)
Definition: shared_object.hpp:180
Definition: fatarcs.hpp:307
Definition: fatarcs.hpp:23
void split(domain< C > *ch)
Definition: fatarcs.hpp:91
bool is_arc(arc_rep< C > c)
Definition: fatarcs_fcts.hpp:415
bernstein_t poly2
Definition: solver_fatarcs.hpp:26
void eval(Result &result, const bernstein< Coeff > &controls, const Parameters &parameters)
Definition: tensor_bernstein_fcts.hpp:195
size_type size() const
Definition: Seq.hpp:166
void prepro(bernstein_t &pol1, bernstein_t &pol2, vec_t midpt)
Definition: solver_fatarcs.hpp:64
box_t box
Definition: fatarcs.hpp:318
box_rep< C > box_rep_t
Definition: solver_fatarcs.hpp:20
Definition: solver_fatarcs.hpp:14
Definition: polynomial.hpp:37
T median(const Interval< T, r > &x)
Definition: Interval_fcts.hpp:91
arc_rep< C > arc_rep_t
Definition: solver_fatarcs.hpp:21
C diam()
Definition: fatarcs.hpp:47
scalar< T > sqrt(const scalar< T > &b)
Definition: scalar.hpp:501
seqbox_t solver(int MTH)
SOLVE ROUTINE.
Definition: solver_fatarcs.hpp:79
std::stack< box_t > stbox_t
Definition: solver_fatarcs.hpp:22
domain< C > minmax_box(Seq< std::vector< C > > ispts, domain< C > box)
Definition: fatarcs_fcts.hpp:476
domain< C > box_t
Definition: solver_fatarcs.hpp:18
box_t box_gen(box_rep_t m1, box_rep_t m2, int MTH)
Definition: solver_fatarcs.hpp:34
Definition: fatarcs.hpp:119
double C
Definition: solver_mv_fatarcs.cpp:16
coeff_t min_grad()
Definition: fatarcs.hpp:420
C dim()
Definition: fatarcs.hpp:40
polynomial< C,with< Bernstein > > bernstein_t
Definition: solver_fatarcs.hpp:19
C epsilon
Definition: solver_fatarcs.hpp:25
Seq< vec_t > event_list()
Definition: fatarcs.hpp:404
Definition: array.hpp:12
Definition: polynomial.hpp:40
Home