realroot_doc 0.1.1
|
00001 # include <realroot/fatarcs.hpp> 00002 # include <realroot/polynomial_bernstein.hpp> 00003 # include <realroot/polynomial_tensor.hpp> 00004 00005 #pragma once 00006 00007 using namespace mmx; 00008 00009 00011 // solver_fatarcs struct 00012 00013 template<class C> 00014 struct solver_mv_fatarcs 00015 { 00016 00017 typedef std::vector<C> vec_t; 00018 typedef domain<C> box_t; 00019 typedef polynomial< C ,with<Bernstein> > bernstein_t; 00020 typedef box_rep< C > box_rep_t; 00021 typedef arc_rep< C > arc_rep_t; 00022 typedef std::stack< box_t > stbox_t; 00023 typedef Seq< box_t > seqbox_t; 00024 00025 C epsilon; 00026 bernstein_t poly1, poly2; 00027 00028 //CONSTRUCTOR 00029 solver_mv_fatarcs(bernstein_t p1, bernstein_t p2, C eps){poly1=p1; poly2=p2; epsilon=eps; }; 00030 00031 00032 //FCTS 00033 00034 box_t box_gen(box_rep_t m1, box_rep_t m2, int MTH) 00035 { 00036 00037 arc_rep_t mc1,mc2; 00038 Seq<vec_t> l1=m1.event_list(); 00039 if(l1.size()==4){mc1=median(m1, l1, MTH);}else{mc1=arc_rep_t();}; 00040 Seq<vec_t> l2=m2.event_list(); 00041 if(l2.size()==4){mc2=median(m2, l2, MTH);}else{mc2=arc_rep_t();}; 00042 00043 box_t bbox=m1.box; 00044 00045 if(is_arc(mc1) && is_arc(mc2)){ 00046 00047 C c1=m1.min_grad();//std::cout << c1 <<std::endl; 00048 C c2=m2.min_grad();//std::cout << c2 <<std::endl; 00049 if(c1>C(0) && c2>C(0) ){ 00050 C r1=m1.max_eval(mc1)/sqrt(c1);//std::cout << r1 <<std::endl; 00051 C r2=m2.max_eval(mc2)/sqrt(c2);//std::cout << r2 <<std::endl; 00052 Seq<vec_t> extrema; 00053 extrema=extpts(mc1,r1,mc2,r2); 00054 00055 bbox=minmax_box(extrema, m1.box); 00056 }else{/*std::cout << "no grad "<<std::endl;*/} 00057 }else{/*std::cout << "no med "<<std::endl;*/} 00058 00059 return(bbox); 00060 };/*box around fatarc intersection*/ 00061 00062 00063 00064 void prepro(bernstein_t & pol1, bernstein_t & pol2, vec_t midpt) 00065 { 00066 bernstein_t p1=pol1,p2=pol2; 00067 C c1x,c1y,c2x,c2y; 00068 tensor::eval(c1x, diff(p1,0).rep(),midpt); 00069 tensor::eval(c2x, diff(p2,0).rep(),midpt); 00070 tensor::eval(c1y, diff(p1,1).rep(),midpt); 00071 tensor::eval(c2y, diff(p2,1).rep(),midpt); 00072 if(c1x!=c1y && c2x!=c2y){ 00073 pol1=c1x*p1+c2x*p2; 00074 pol2=c1y*p1+c2y*p2; } 00075 }; 00076 00078 00079 seqbox_t solver(int MTH){ 00080 stbox_t list, mo; 00081 seqbox_t moseq; 00082 00083 int subdiv=0; 00084 int arcgen=0; 00085 int it=0; 00086 00087 box_t unit(int(2)); 00088 box_t p[4]; 00089 list.push(unit); 00090 00091 while(!list.empty()){it++; 00092 00093 box_t rec=list.top(); 00094 00095 list.pop(); 00096 00097 box_rep_t m1(poly1, rec); 00098 box_rep_t m2(poly2, rec); 00099 00100 if(m1.not_empty() && m2.not_empty()){ 00101 00102 // prepro( m1.poly, m2.poly, (rec.llc()+rec.urc())/((coeff_t)(2))); 00103 // std::cout <<"b"<<std::endl; 00104 box_t newrec=box_gen(m1, m2, MTH); arcgen++; 00105 00106 00107 if(newrec.dim()==0){ //std::cout <<"no fatarc intersection"<<std::endl; 00108 }else{ //std::cout <<"new"<<std::endl;newrec.print(5); 00109 if(newrec.diam() <( rec.diam()/ C(2) ) ){; 00110 00111 if(newrec.diam()<epsilon){mo.push(newrec);//std::cout <<"small1"<<std::endl; newrec.print(6); 00112 } 00113 else{list.push(newrec);//std::cout <<"list new"<<std::endl; 00114 } 00115 00116 } 00117 else{ 00118 if(rec.diam()<epsilon){mo.push(rec);} 00119 else{rec.split(p);subdiv++;/*std::cout <<"sub1"<<std::endl;*/ 00120 for(int i=0; i<4; i++){list.push(p[3-i]);} 00121 } 00122 00123 }; 00124 00125 }; 00126 00127 }else{//std::cout <<"empty"<<std::endl; 00128 }; 00129 } 00130 00131 00132 00133 std::cout << " * * * * * "<<std::endl; 00134 std::cout << "iteration: "<<it<<std::endl; 00135 std::cout << "subdivisoins: "<<subdiv<<std::endl; 00136 std::cout << "try fatarc generation: "<<arcgen<<std::endl; 00137 //std::cout << "solution: "<<mo.size()<<std::endl; 00138 00139 00140 while(!mo.empty()){ 00141 00142 box_t rb=mo.top(); 00143 moseq<< rb; 00144 mo.pop(); 00145 }; 00146 00147 return moseq; 00148 00149 00150 }/*solver*/ 00151 00152 00153 };//end of structure solver_mv_fatarcs 00154 00156 // TEST 00158 00159 00160 template<class C> 00161 Seq< domain<C> > solve_bv_fatarcs( polynomial< C, with<Bernstein> > p1, 00162 polynomial< C, with<Bernstein> > p2, C eps ) 00163 { 00164 int MTH=1; 00165 solver_mv_fatarcs<C> sys( p1, p2, eps); 00166 return sys.solver(MTH); 00167 }