void SetNodeReg::cleave(const IntervalVector& box, Ctc& Ctcin, Ctc& Ctcout, const double eps) { if(is_leaf() && status == OUT) return; IntervalVector box1(box); IntervalVector box2(box); //try{Ctcin.contract(box1);} //catch(EmptyBoxException&){inter(OUT);return;} Ctcin.contract(box1); if(box1.is_empty()) { inter(OUT); return; } //try{Ctcout.contract(box2);} //catch(EmptyBoxException&){_union(IN);return;} Ctcout.contract(box2); if(box2.is_empty()) { _union(IN);return; } if(is_leaf()) { if(box[var].diam()>eps) { cut(box); left->cleave(left_box(box),Ctcin,Ctcout,eps); right->cleave(right_box(box),Ctcin,Ctcout,eps); } else status = inte(status,UNK); } else { left->cleave(left_box(box),Ctcin,Ctcout,eps); right->cleave(right_box(box),Ctcin,Ctcout,eps); } }
void SetNodeReg::cleave(const IntervalVector& box, Sep& sep, const double eps) { if(is_leaf() && status == OUT) return; IntervalVector box1(box); IntervalVector box2(box); sep.separate(box1,box2); if(box1.is_empty()){ inter(OUT); // cout<<"box: "<<box<<" set to OUT"<<endl; } else if(box2.is_empty()){ _union(IN); cout<<"box: "<<box<<" set to IN"<<endl; } else // continu until box1 and box2 are disjoint { if(is_leaf()) { if(box[var].diam()>eps) { cut(box); left->cleave(left_box(box),sep,eps); right->cleave(right_box(box),sep,eps); } else status = inte(status,UNK); } else { left->cleave(left_box(box),sep,eps); right->cleave(right_box(box),sep,eps); } } }
void SetNodeReg::inter(NodeType x_status) { if(is_leaf()) status = inte(status,x_status); else { left->inter(x_status); right->inter(x_status); } }
void SetNodeReg::oper(SetNodeReg* node,bool op) { if(is_leaf()) { if(node->is_leaf()) // if node is leaf, apply its value to leaves of this { if(op) status = inte(status,node->status); else status = uni(status,node->status); } else { pt = node->pt; left = node->left->copy(this); right = node->right->copy(this); if(op && status != IN) { left->inter(status); right->inter(status); } else if(!op && status!= OUT) { left->_union(status); right->_union(status); } } } else { if(node->is_leaf()) // apply status to leaves of the subtree which have this as root { if(op && node->status != IN) { left->inter(node->status); right->inter(node->status); } else if(!op && node->status!= OUT) { left->_union(node->status); right->_union(node->status); } } else { left->oper(node->left,op); right->oper(node->right,op); } } }
jvec parab_spline(jvec *A,double *x,double xint,const char *path=NULL) { jvec out(nth,njack); ofstream plot; if(path!=NULL) plot.open(path); jvec a(nth,njack),b(nth,njack),c(nth,njack); for(int ith=0;ith<nth;ith++) { for(int ijack=0;ijack<=njack;ijack++) { double y[3]; for(int i=0;i<3;i++) y[i]=A[i][ith][ijack]; parabolic_spline(a[ith].data[ijack],b[ith].data[ijack],c[ith].data[ijack],x,y); out[ith].data[ijack]=a[ith][ijack]*xint*xint+b[ith][ijack]*xint+c[ith][ijack]; } } if(path) { for(int ith=0;ith<nth;ith++) { jvec inte(100,njack); double xin=min(xint,x[0]),xfin=max(xint,x[2]),dx=(xfin-xin)/99; double xn[100]; for(int ix=0;ix<100;ix++) { xn[ix]=xin+dx*ix; inte[ix]=a[ith]*xn[ix]*xn[ix]+b[ith]*xn[ix]+c[ith]; } plot<<write_polygon(xn,inte); plot<<"&"<<endl; plot<<"@type xydy"<<endl; for(int ic=0;ic<3;ic++) plot<<x[ic]<<" "<<A[ic][ith]<<endl; plot<<"&"<<endl; plot<<xint<<" "<<out[ith]<<endl; plot<<"&"<<endl; } } return out; }
void PC::test() { double inegral; double pressis; clock_t time; ofstream arqui; arqui.open("TesteTrapezioPC.csv"); arqui << "Integrais por trapezio PC" << endl; arqui << "Tempo;Resultado;Erro;A;B" << endl; system("cls"); cout << "executando Trapesio" << endl; for (double i = presisMin; i <= presisMax; i += presisPul) { IntegralEuler inte(i); //zera o tempo time = clock(); //integra com i inegral = inte.integrate(this->Start, this->Fim); //compara os resultados pressis = this->Resultado - inegral; //termina a contagem time = clock() - time; //salva no txt arqui <<(double)time/CLOCKS_PER_SEC<< ";" <<inegral<< ";"<<pressis<< ";"<< this->Start << ";"<< this->Fim << endl; } arqui.close(); arqui.open("TesteBarraPC.csv"); arqui << "Integrais por Barra PC" << endl; arqui << "Tempo;Resultado;Erro;A;B" << endl; cout << "executando Barra" << endl; for (double i = presisMin; i <= presisMax; i += presisPul) { IntegralBarra inte(i); //zera o tempo time = clock(); //integra com i double inegral = inte.integrate(this->Start, this->Fim); //compara os resultados pressis = this->Resultado - inegral; //termina a contagem time = clock()-time; //salva no txt arqui <<(double)time/CLOCKS_PER_SEC<< ";" <<inegral<< ";"<<pressis<< ";"<< this->Start << ";"<< this->Fim << endl; } arqui.close(); for (double i = presisMin; i <= presisMax; i += presisPul) { for (double j = presisMin; j <= presisMax; j += presisPul) { IntegralPredicao inte(i, j); //zera o tempo time = clock(); //integra com i //double inegral = inte.integrate(this->Start, this->Fim); //compara os resultados pressis = this->Resultado - inegral; //termina a contagem time = clock()-time; //salva no txt //cout << "A integral de " << a << " ate " << b << " com o intevalo de " << c << "e pulo de" << d << " e de " << inegral << endl; break; } break; } }