void StructuredGrid::reset_domain(const Vect3d& _low, const Vect3d& _high, const Vect3d& max_grid_size) { high = _high; low = _low; domain_size = _high-_low; Vect3d new_max_grid_size = max_grid_size; for (int i = 0; i < 3; ++i) { if ((new_max_grid_size[i]<=0)||std::isnan(new_max_grid_size[i])) { new_max_grid_size[i] = 1.0; } } num_cells_along_axes = ((high-low).cwiseQuotient(new_max_grid_size) + Vect3d(0.5,0.5,0.5)).cast<int>(); for (int i = 0; i < 3; ++i) { if (num_cells_along_axes[i]==0) { num_cells_along_axes[i] = 1.0; high[i] = low[i] + new_max_grid_size[i]; domain_size[i] = high[i]-low[i]; } } cell_size = (high-low).cwiseQuotient(num_cells_along_axes.cast<double>()); tolerance = cell_size.minCoeff()/100000.0; cell_volume = cell_size.prod(); inv_cell_size = Vect3d(1,1,1).cwiseQuotient(cell_size); num_cells_along_yz = num_cells_along_axes[2]*num_cells_along_axes[1]; num_cells = num_cells_along_axes.prod(); neighbours.resize(num_cells); neighbour_distances.resize(num_cells); calculate_neighbours(); }
int main(int argc, char **argv) { char *file_name; u_int neighbours = 0; u_int repel = 0; u_int cycle = 0; struct tspfile file; struct list all_list; FILE *ofp; char n_file[100]; if((file_name = parse_args(argc, argv, &neighbours, &repel, &cycle)) == NULL){ exit(1); } if ((parse_file(file_name, &file)) != -1) { if(neighbours >= file.dimension){ exit (1); } init_list(&all_list, &file, file.dimension-neighbours, repel); sprintf(n_file, "Neighbours/N-%s.tsp", file.name); if ((ofp = fopen(n_file, "r")) != NULL) { load_N_from_file(ofp, &all_list, file.dimension-neighbours, repel); fclose(ofp); } else { printf("Unable to find pre-process file, continue?"); getchar(); calculate_neighbours(&all_list, neighbours, repel); getchar(); } sprintf(n_file, "results/R-%s.tsp", file.name); if ((ofp = fopen(n_file, "a")) != NULL) { int opt = get_opt(file.name); double result = start_selforg(&all_list, file.dimension-neighbours, repel,cycle ); fprintf(ofp,"N:%d C:%d best:%f%%\n",file.dimension-neighbours,cycle,(result / (double)opt) * 100); fclose(ofp); } } return 0; }