void cone_focus(void *l, t_token *token) { char *s; if ((s = xml_token(&token, "x", RESOLVE, 0)) == NULL) def_error("x"); if (!O_IN(s + strspn(s, "-+"), "0123456789.")) def_error("x"); ((t_cone*)l)->focus.x = (N_X(atof(s + strspn(s, "-+"))) * M_PI) / 180; free(s); if ((s = xml_token(&token, "z", RESOLVE, 0)) == NULL) def_error("z"); if (!O_IN(s + strspn(s, "-+"), "0123456789.")) def_error("z"); ((t_cone*)l)->focus.z = (N_Y(atof(s + strspn(s, "-+"))) * M_PI) / 180; free(s); if ((s = xml_token(&token, "y", RESOLVE, 0)) == NULL) def_error("y"); if (!O_IN(s + strspn(s, "-+"), "0123456789.")) def_error("y"); ((t_cone*)l)->focus.y = (N_Y(atof(s + strspn(s, "-+"))) * M_PI) / 180; free(s); ((t_cone*)l)->focus = convert_norm(convert_focus(((t_cone*)l)->focus)); ((t_cone*)l)->focus.y = NM(((t_cone*)l)->focus.y); ((t_cone*)l)->focus.x = NM(((t_cone*)l)->focus.x); ((t_cone*)l)->focus.z = NM(((t_cone*)l)->focus.z); }
error step_stop_already_early_typing(struct module *mod, struct node *node, void *user, bool *stop) { DSTEP(mod, node); if (node->typ == NULL || node->typ == TBI__NOT_TYPEABLE) { return 0; } const struct node *par = parent_const(node); switch (node->which) { case BIN: *stop = !!(NM(par->which) & (NM(DEFFUN)|NM(DEFMETHOD))) && subs_first_const(par) == node; break; case WITHIN: *stop = par->which == WITHIN; break; default: *stop = true; break; } return 0; }
int hdu_type_from_name (SEXP name) { const char * name_cstr = NM(name); if (strcmp (name_cstr, IMAGE_HDU_NAME) == 0) return IMAGE_HDU; else if (strcmp (name_cstr, ASCII_TBL_NAME) == 0) return ASCII_TBL; else if (strcmp (name_cstr, BINARY_TBL_NAME) == 0) return BINARY_TBL; else return -1; }
/* Wrapper to fits_movnam_hdu */ SEXP cfitsio_movnam_hdu (SEXP fits_object, SEXP hdu_type, SEXP ext_name, SEXP ext_ver) { fits_file_t * fits = R_ExternalPtrAddr (fits_object); if (NULL != fits && NULL != fits->cfitsio_ptr) { fits_movnam_hdu (fits->cfitsio_ptr, asInteger (hdu_type), (char *) NM(ext_name), hdu_type_from_name (ext_ver), &(fits->status)); return R_NilValue; } else return R_NilValue; }
int main() { /* Set up module test environment */ std::ofstream ofs ("./output/mt_results.txt", std::ofstream::out); /* TC_1: Create an instance of a NelderMead type object*/ ofs<<"**************** MT TC 1 ****************"<<std::endl; ofs<<"testcase 1: Create an instance of a NelderMead type object"<<std::endl; std::vector<Coord> X; X.resize(MT_SIZE_OF_INPUT_VECTOR_INT); X[0][0] = MT_X_0_0_DOUBLE; X[0][1] = MT_X_0_1_DOUBLE; X[1][0] = MT_X_1_0_DOUBLE; X[1][1] = MT_X_1_1_DOUBLE; X[2][0] = MT_X_2_0_DOUBLE; X[2][1] = MT_X_2_1_DOUBLE; NelderMead NM(MT_NUM_OF_MAX_GENERATIONS_INT, MT_MAXIMUM_TOLARABLE_FVAL_DOUBLE, X); ofs<<"testcase 1: DONE"<<std::endl<<std::endl; /* TC_2: Find minimum place of a test function*/ ofs<<"**************** MT TC 2 ****************"<<std::endl; ofs<<"testcase 2: Find minimum place of a test function"<<std::endl; auto test_func = [] (Coord &m) { return (m[0]*m[0]) + (m[1]*m[1]);}; Coord minimum_place = NM.Optimize(test_func); ofs<<"Minimum place of f(x,y) := x^2+y^2"<<std::endl; ofs<<"X: "<<minimum_place[0]<<" Y: "<<minimum_place[1]<<std::endl; ofs<<"testcase 2: DONE"<<std::endl<<std::endl; /* Clear up module test environment */ ofs.close(); return 0; }
#include "passzero.h" #include "passbody.h" static STEP_NM(step_codeloc_for_generated, -1); static ERROR step_codeloc_for_generated(struct module *mod, struct node *node, void *user, bool *stop) { if (node->codeloc.pos == 0) { node->codeloc = parent(node)->codeloc; } return 0; } static STEP_NM(step_export_pre_post_invariant, NM(PRE) | NM(POST) | NM(INVARIANT)); static ERROR step_export_pre_post_invariant(struct module *mod, struct node *node, void *user, bool *stop) { const struct node *par = parent_const(node); if (par->which == DEFTYPE || par->which == DEFINTF) { node_toplevel(node)->flags |= node_toplevel_const(par)->flags & TOP_IS_EXPORT; return 0; } if (par->which == BLOCK) { const struct node *pparent = parent_const(par); if (pparent->which == DEFFUN || pparent->which == DEFMETHOD) { node_toplevel(node)->flags |= node_toplevel_const(pparent)->flags & TOP_IS_EXPORT; } }
/*Main program of the search algorithm*/ int main(int argc, char **argv) { srand(time(NULL)); MT_seed(); //when teste flag is used if(argc > 0 && strcmp(argv[1],"teste") == 0) { //put teste functions her return 0; } /* Control Parameters of the search algorithm*/ int FUNCTION; //Problem definitions int RUN; /*Algorithm can run many times in order to see its robustness*/ int i, j; double lb; //lower bound of the variables double ub; //upper bound of the variables pVNS *vns_run = (pVNS *) malloc (sizeof (pVNS)); //read input file FILE *file = fopen( argv[1], "r" ); if (getParametersVNS(file,vns_run) == -1 ){ //read input file return 0; } fclose(file); showParametersVNS(vns_run); RUN = vns_run->RUN; FUNCTION = vns_run->FUNCTION; prepararObjFunc(&FUNCTION,&lb,&ub);//initialize variables needed by function vns_run->LB = lb; vns_run->UB = ub; int maxr=RUN; pVNS **sol = (pVNS **) malloc (sizeof (pVNS*)*maxr); for(i=0;i<maxr;i++){ sol[i] = (pVNS*) malloc (sizeof (pVNS)); memcpy(sol[i],vns_run,sizeof(pVNS)); sol[i]->RUN=i; sol[i]->best = malloc(sizeof(double) * vns_run->DIM); for (j=0; j<vns_run->DIM;j++) //each dimension { sol[i]->best[j] = randon(vns_run->LB,vns_run->UB); } } //executa o metodo escolhido pelo arquivo de entrada //aloca para graficos if(GRAFICO){ fo_geracoes = (double**) malloc(sizeof(double*) * RUN + 2); bestfo_geracoes = (double**) malloc(sizeof(double*) * RUN + 2); for(i=0;i<RUN;i++){ if(vns_run->METHOD == 6) { //PRVNS fo_geracoes[i] = (double*) malloc(sizeof(double) * vns_run->G_MAX + 2 ); bestfo_geracoes[i] = (double*) malloc(sizeof(double) * vns_run->G_MAX + 2); }else{ fo_geracoes[i] = (double*) malloc(sizeof(double) * vns_run->TMAX + 2 ); bestfo_geracoes[i] = (double*) malloc(sizeof(double) * vns_run->TMAX + 2); } } if(vns_run->METHOD == 6) { //PRVNS fo_mediaGeracoes = (double*) malloc(sizeof(double) * vns_run->G_MAX + 2); bestfo_mediaGeracoes = (double*) malloc(sizeof(double) * vns_run->G_MAX + 2); }else{ fo_mediaGeracoes = (double*) malloc(sizeof(double) * vns_run->TMAX + 2); bestfo_mediaGeracoes = (double*) malloc(sizeof(double) * vns_run->TMAX + 2); } } double *r = (double*)malloc ( (vns_run->KMAX+1) *sizeof(double)); double radii = vns_run->RADII; switch(vns_run->METHOD) { case 3: case 4: case 5: printf("Valores de raio usando PG e razao %f:\n",vns_run->Q); //set wich radii value r[0] = 0.0f; for(j=1;j<=vns_run->KMAX;j++){ r[j] = radii; radii*=vns_run->Q; } for(j=1;j<=vns_run->KMAX;j++){ printf("k_%d => radii=%f \n",j,r[j]); } break; case 6: printf("Valores de raio usando PG e razao %f:\n",vns_run->Q); r[0] = 0.1f; r[1] = 0.3f; r[2] = 0.5f; r[3] = 0.7f; r[4] = 0.9f; for(j=0;j<vns_run->KMAX;j++){ printf("k_%d => radii=%f \n",j+1,r[j]); } break; } for(i=0;i<maxr;i++){ if(GRAFICO){ execucao++; } switch (vns_run->METHOD) { case 2: //HJ sol[i] = HJ((void*)sol[i]); break; case 3: //BVNS sol[i] = BVNS((void*)sol[i]); break; case 4: //RVNS sol[i] = RVNS((void*)sol[i]); break; case 5: //BVNS_NM sol[i] = BVNS_NM((void*)sol[i]); break; case 6: //PRVNS sol[i] = PRVNS((void*)sol[i]); break; case 7: //NM - Only Nelder Mead sol[i] = NM((void*)sol[i]); break; default: printf("Info: Invalid method.\n") ; exit(0); } } //GRAFICOS //INICIO Grafico Convergencia inicializacao #ifdef GRAFICO char *vns_plot_best; char *vns_plot_mean; char file_name[100]; if(GRAFICO == 1){ vns_plot_best = (char *) malloc(sizeof(char) * vns_run->TMAX * 10); vns_plot_mean = (char *) malloc(sizeof(char) * vns_run->TMAX * 10); sprintf(file_name,"Convergencia/VNS_CONVERGENCIA_%d_%d_%d_%d",vns_run->METHOD,vns_run->DIM,vns_run->RUN,vns_run->FUNCTION); } //FIM Grafico Convergencia inicializacao if(GRAFICO == 1 && vns_run->METHOD == 4){//para RVNS for(i=0;i<=geracao;i++){ double med_best = 0.0f; for(j=0;j<RUN;j++){ med_best += bestfo_geracoes[j][i]; } bestfo_mediaGeracoes[i] = med_best/RUN; //salva em string para gerar pelo gnuplot sprintf(vns_plot_best, "%s %d %lf\n ",vns_plot_best,i,bestfo_mediaGeracoes[i]); if(DEBUG){ /* printf("\nMedia melhor execucoes Geracao[%d] =>%f\n",i,bestfo_mediaGeracoes[i]); */ } } //escreve em arquivo grafico_linhas_x_y(vns_plot_best,"FO", "Geracoes", "RVNS", "Melhor",file_name); }else if(GRAFICO == 1 && vns_run->METHOD != 4){ for(i=0;i<=geracao;i++){ double med_med = 0.0f; double med_best = 0.0f; for(j=0;j<RUN;j++){ med_med += fo_geracoes[j][i]; med_best += bestfo_geracoes[j][i]; } fo_mediaGeracoes[i] = med_med/RUN; bestfo_mediaGeracoes[i] = med_best/RUN; //salva em string para gerar pelo gnuplot sprintf(vns_plot_mean, "%s %d %lf\n ",vns_plot_mean,i,fo_mediaGeracoes[i]); sprintf(vns_plot_best, "%s %d %lf\n ",vns_plot_best,i,bestfo_mediaGeracoes[i]); if(DEBUG){ printf("\nMedia execucoes Geracao[%d] =>%f\n",i,fo_mediaGeracoes[i]); printf("\nMedia melhor execucoes Geracao[%d] =>%f\n",i,bestfo_mediaGeracoes[i]); } } //escreve em arquivo grafico_duas_linhas(vns_plot_best,vns_plot_mean,"Geracoes","FO","PRVNS","Melhor","Media",file_name); } #endif //realiza os calculos necessarios calculateStatistic(sol,maxr); //liberar memoria for(i=0;i<maxr;i++){ free(sol[i]); } free(sol); free(vns_run); return 0; }//end MAIN
bool PowerSeriesWP::isTrivial(const Word& w) { // Construct two possible types of monomials: // PM: (1 + x) and NM: ( 1 - x + x^2 - x^3 + ... x^c ) int wLen = w.length(); int numOfGens = F.numberOfGenerators(); VectorOf<int> PM(c), NM(c); for( int i = 0; i < c; ++i ) { PM[i] = 0; if( odd(i+1) ) NM[i] = -1; else NM[i] = 1; } PM[0] = 1; // Construct all monomials VectorOf<int>* M[wLen]; for( int i = 0; i < wLen; ++i ) if( ord(Generator(w[i])) > 0 ) M[i] = &PM; else M[i] = &NM; // Enumerate all possible monomials and compute their coefficients. // They all are equal to 0 iff the word is trivial. VectorOf<int> v(c); for( int i = 0; i < c; ++i ) v[i] = 0; // The main cycle while( true ) { // Construct the current monomial v int i = c-1; while( true ) { if( ++v[i] <= numOfGens ) break; v[i--] = 1; if( i < 0 ) return true; } for( i = 0; i < c; ++i ) if( v[i] > 0 ) break; // Compute the sum of it's coefficients in M int sum = 0; Stack stack(c); State state(1, -1, i); bool checkPower = false; while( true ) { if( checkPower && v[state.vPos] == v[state.vPos + state.power] && (*M[state.wPos])[state.power] != 0 ) { //state.vPos += state.power; ++state.power; } else { ++state.wPos; state.power = 1; for( ; state.wPos < wLen; ++state.wPos ) if( abs(ord(Generator(w[state.wPos]))) == v[state.vPos] ) break; } if( state.wPos == wLen) { if( stack.length() == 0 ) break; stack.get(state); checkPower = true; } else { stack.put(state); if( checkPower ) { state.coef *= (*M[state.wPos])[state.power-1]; state.vPos += state.power; state.power = 1; } else { state.coef *= (*M[state.wPos])[0]; ++state.vPos; } checkPower = false; if( state.vPos >= c ) { sum += state.coef; stack.get(state); } } } #ifdef debug_fnwp cout << "Monomial: " << v << " Sum = " << sum << endl; #endif if( sum != 0 ) return false; } }
static int NM(trie_data_fits)(I32 nodes, size_t dyn_ptrs, size_t odd_arrays) { return NM(trie_data_size)(nodes, dyn_ptrs, odd_arrays) < (PTR) ~((PTR) 0u); }