dfa(const nfa_node_type& start) { auto initial = new node_type(); std::unordered_set<node_type*> unmarked; std::unordered_set<node_type*, dfa_node_hash, dfa_node_eq> result; std::unordered_set<const nfa_node_type*> moved; std::initializer_list<const nfa_node_type*> start_nodes{ &start }; eclosure(initial->nodes, start_nodes); result.insert(initial); unmarked.insert(initial); while (!unmarked.empty()) { auto it = unmarked.begin(); auto D = *it; unmarked.erase(it); std::set<boost::icl::discrete_interval<CharType>> letters; make_disjoint<CharType>(letters, D->nodes); for (auto&& inter : letters) { auto new_node = new node_type(); moved.clear(); move_s(moved, D->nodes, inter); eclosure(new_node->nodes, moved); bool inserted = false; if (!new_node->nodes.empty()) { auto status = result.emplace(new_node); if (status.second) { unmarked.insert(new_node); inserted = true; } boost::icl::interval_set<CharType> iset; iset.add(inter); D->transitions.emplace_back(iset, *status.first); } if (!inserted) delete new_node; } } _nodes = set_type(result.begin(), result.end()); _initial = initial; aggregate(); }
/*MONTE CARLO*/ void mc1m(int num_photons,double ma, double ms, double g, double *x0,double *x1, double *x2, double *u0, double *u1, double *u2, double *na_fiber, double r_max, double x2_max,double n_tissue, double *n_fiber, double *fiber_radii, int t_grid, double *th, double *ph,double tissue[],double fiber_tissue[], double r[],double depth[],double weight[],double path[], double z[],double num_scatt[]) { int i; double s = 0; /*Fiber NA*/ float na_clad = na_fiber[1]; float na_core = na_fiber[0]; /*Fiber refractive indices*/ float n_clad = n_fiber[1]; float n_core = n_fiber[0]; /*Maximum angle for detection*/ double theta_clad = asin(na_clad/n_tissue); double Ralphi; /*ran1 seed*/ srand ( time(NULL) ); long idum = -(rand() % 1000 +1); /*Image array*/ int t_grid0 = t_grid*r_max; int t_grid2 = t_grid*x2_max; double dim_arr = t_grid0*t_grid2; double *aux_tissue = malloc(dim_arr*sizeof(double)); double r_tissue; /*Fibre geometry*/ double r_dclad = fiber_radii[2]; double r_clad = fiber_radii[1]; double r_core = fiber_radii[0]; /*Tissue and fiber_tissue initialization for each monte carlo run*/ int it,jt, count=0; for (it = 0; it< t_grid2; it++){ for (jt = 0; jt< t_grid0; jt++){ *(tissue+count) = 0; *(fiber_tissue+count) = 0; count++;}} /*Auxiliar arrays initialization*/ int ji,count2=0; for (ji = 0; ji< num_photons; ji++){ *(r+count2) = 0; *(depth+count2) = 0; *(weight+count2) = 0; *(path+count2) = 0; *(z+count2) = 0; *(num_scatt+count2)=0; count2++;} /*LAUNCHING*/ for (i=0;i<num_photons;i++) { int status=1; /*Photon alive*/ double x[]={x0[i],x1[i],x2[i]}; /*Position*/ double u[]={u0[i],u1[i],u2[i]}; /*Direction*/ double path_pp=0; /*Pathlength*/ double weight_pp=1; /*Weigth*/ double num_pp = 0; double depth_pp=0; /*Maximum depth*/ double dw=0; /*Weigth lost*/ double fiber_boundary; double z_na, r_na, cone; /*Specular reflection*/ specular(n_core, n_tissue,&weight_pp); /*aux_ tissue initialization for each photon*/ int count1 = 0,j; for (it = 0; it< t_grid2; it++){ for (jt = 0; jt< t_grid0; jt++){ *(aux_tissue+count1)=0; count1++;}} while (status==1) { /*Propagation distance*/ if (s == 0){s=log(ran1(&idum))/(-(ma+ms));} int tz0=0; int tz2=0; /*HIT FIBER BOUNDARY*/ fiber_boundary = -x[2]*(ma+ms)/u[2]; /*Position before updating*/ z_na = x[2]; r_na = r_tissue; cone = theta_clad*z_na + r_clad; if (u[2] < 0 && fiber_boundary <= s && z_na >0) { move_s(x, u, fiber_boundary, &depth_pp, &path_pp, &s, &r_tissue,&num_pp); /*whether the photon is internally reflected*/ reflection(u, n_core, n_tissue, &Ralphi); if (ran1(&idum)<= Ralphi){u[2]=-u[2];} } else{ move_s(x, u, s, &depth_pp, &path_pp, &s, &r_tissue, &num_pp); absorption(ma, ms,&weight_pp,&dw); spin_thph(u, g, &idum,th,ph); /*Absortion array updating*/ tz0=floor(r_tissue*t_grid); tz2=floor(x[2]*t_grid); if(tz0>t_grid0-1){tz0=t_grid0-1;} if(tz0<0){tz0=0;} if(tz2>t_grid2-1){tz2=t_grid2-1;} if(tz2<0){tz2=0;} *(tissue+(tz0*t_grid2+tz2))+=dw; *(aux_tissue+(tz0*t_grid2+tz2))+=dw; } /*else (the photon didn't reach the boundary)*/ /*PHOTON TERMINATION*/ if(x[2] > x2_max ){status=0;} if(status==1 && weight_pp<0.00001 /*threshold*/ ){roulette(&weight_pp,&idum,&status);} /*The photon reach the sensing area?*/ if(x[2] < 0 && r_tissue <= r_clad && r_tissue >= r_core && z_na >0 && r_na <= cone){ for(j=0;j<dim_arr;j++){fiber_tissue[j]+=aux_tissue[j];} /*Final status of detected photons*/ r[i] = r_tissue; z[i] = x[2]; path[i] = path_pp; weight[i] = weight_pp; depth[i] = depth_pp; num_scatt[i] = num_pp;} } /*while status is alive*/ } /*for i num_photons launched*/ return; } /*mcml2m*/