bool process_conf(CavConfig &cfg) { Wpi_container points; Voids_result res(cfg.atoms.size(), cfg.out_inf); // reserve space for atoms surf, pass main log stream build_input(cfg.atoms, cfg.radii, cfg.r_scale, cfg.r_probe, points); if (!regular_triangulation_voids(points, res)) { cfg.out_inf << "algorithm fatal error!" << std::endl; return false; } Surf::write_header(cfg.out_stl); cfg.out_inf << std::setprecision(12); cfg.out_inf << "Void num : Volume Surface " << std::endl; for (std::size_t i = 0; i < res.voids.size(); i++) { cfg.out_inf << std::setw(8) << i+1 << " : " << std::left << std::setw(17) << res.voids[i].volume << " "; cfg.out_inf << res.voids[i].surface << std::right << std::endl; if (cfg.out_vol.is_open()) cfg.out_vol << res.voids[i].volume << std::endl; if (cfg.out_stl.is_open()) { // draw surface of void std::vector<Weighted_point> wp; scale_cavity_atoms(res.voids[i].atoms, cfg.atoms, cfg.radii, cfg.box, cfg.r_scale, cfg.r_probe, cfg.stl_scale, wp); Surf::write_cavity_surface(cfg.out_stl, wp.begin(), wp.end(), cfg.nSubdiv); } } Surf::write_footer(cfg.out_stl); cfg.out_inf << "Voids count : " << res.voids.size() << std::endl; long double total_void_volume = 0.0L; long double total_void_surface = 0.0L; long double total_void_surface_from_atoms = std::accumulate(res.atom_surf.begin(), res.atom_surf.end(), 0.0L); // for check for (const auto &v: res.voids) { total_void_volume += v.volume; total_void_surface += v.surface; } // accumulate per atom surfaces std::transform(res.atom_surf.begin(), res.atom_surf.end(), cfg.atom_confs_surf.begin(), cfg.atom_confs_surf.begin(), std::plus<long double>()); cfg.out_inf << std::setprecision(std::numeric_limits<double>::digits10); cfg.out_inf << "voids total surface : " << total_void_surface << std::endl; cfg.out_inf << "voids surf atom sum : " << total_void_surface_from_atoms << std::endl; cfg.out_inf << "voids total volume : " << total_void_volume << std::endl; cfg.out_inf << std::endl; return true; }
int main(int argc, char *argv[]) { /* -h flag for help */ /* -o flag for output file */ int oflag = 0; char *ovalue = NULL; /* -i flag for input file */ int iflag = 0; char *ivalue = NULL; /* -q flag for questions file */ int qflag = 0; char *qvalue = NULL; int opt = 0; /* process options */ while ((opt = getopt(argc, argv, "hioq:")) != -1) { switch (opt) { /* input file */ case 'i': iflag = 1; ivalue = optarg; break; /* output file */ case 'o': oflag = 1; ovalue = optarg; break; /* questions file */ case 'q': qflag = 1; qvalue = optarg; //printf("\nqvalue is: %s\n", qvalue); break; /* h flag or error then print usage */ case '?': case 'h': print_usage(); return 1; default: print_usage(); return 1; } } /* Set values based in arguments. */ if ( !oflag ) ovalue = "myoutput"; if ( !qflag ) { qvalue = "../share/pass_gen/questions"; if (!file_exists(qvalue)) { printf("\nDefault questions file: %s\n", qvalue); printf("\nFile not found! Try using -q flag.\n\n"); return -1; } } if ( !iflag ) ivalue = "custom_input"; /* Build an input file of words if not specified. */ build_input(qvalue, ivalue); replace_chars(ivalue, ovalue); append_numbers(ovalue, "output_numbers1"); prepend_numbers(ovalue, "output_numbers2"); concat_with_numbers(ivalue, "output_numbers3"); append_symbols(ivalue, "output_symbols1"); prepend_symbols(ivalue, "output_symbols2"); concat_with_symbols(ivalue, "output_symbols3"); return 0; }
//MAIN LOGIC BEGINS int main() { //first unsigned int=total length of the actual representation, char = first 8 digits of the actual representation, //each KeyObject has these properties: //unsigned int unencodedLength; the total length of the unencoded number //unsigned int firstNDigits; the first 32 digits of the unencoded number //unsigned int primeRepresentation; the encoded representation of the number/key std::vector<KeyObject> keys; for(unsigned int i=0; i < 10000; i++){ keys.push_back(KeyObject()); } //unsigned int initialLowerBoundIndex = 0; //recursiveFillKeys(lowerBounds,upperBounds,initialLowerBoundIndex,keys,primes); //simple examle of generating the keys structure. (these are the numbers we will reduce the file to, //we store them in our ultra compact representation with some identifying info) //for (unsigned int i=6; i<10; i++){ // for (unsigned int j=6; j<10; j++){ // keys[(h-6)*16 + (i-6)*4 + (j-6)] = unsigned integerExponent(prime[0],i)*unsigned integerExponent(prime[1],j).... // } //} Vvi input(build_input()); std::cout << input << "\n"; Vvi output; cart_product(input, output); std::cout << output << "\n"; //sample input/output //input // ( // (0, 1, 2, ) // (10, 11, 12, ) // (20, 21, 22, ) // ) // output // ( // (0, 10, 20, ) // (1, 10, 20, ) // (2, 10, 20, ) // (0, 11, 20, ) // (1, 11, 20, ) // (2, 11, 20, ) // (0, 12, 20, ) // (1, 12, 20, ) // (2, 12, 20, ) // (0, 10, 21, ) // (1, 10, 21, ) // (2, 10, 21, ) // (0, 11, 21, ) // (1, 11, 21, ) // (2, 11, 21, ) // (0, 12, 21, ) // (1, 12, 21, ) // (2, 12, 21, ) // (0, 10, 22, ) // (1, 10, 22, ) // (2, 10, 22, ) // (0, 11, 22, ) // (1, 11, 22, ) // (2, 11, 22, ) // (0, 12, 22, ) // (1, 12, 22, ) // (2, 12, 22, )) unsigned int counter = 0; for(Vvi::iterator it = output.begin(); ; ) { //keyExponentValues gives us a vector with all the exponents we need to use //to create a key //here we calculate the number represented by the exponents mpz_t n; mpz_init(n); mpz_set(n,1); for (Vi::iterator keyExponentValues = it->begin(); ; ){ mpz_t k; mpz_init(k); mpz_set(k,globals.primes[counter]); mpz_mul(n,n,k); n *= k; mpz_clear (k); //mpz_sizeinbase (mpz_t op, int base) //mpz_sizeinbase (mpz_t op, int base) //base can only be up to size 62 max! //here we store the length of the number represented by the exponents keys[counter].unencodedLength = 0; //here we store the first n digits of the number represented by the exponents keys[counter].firstNDigits = 0; mpz_clear (n); //this simulates log base 2 unsigned int bitsToStoreExponent= 0; unsigned int exponentRange = globals.exponentMax - globals.exponentMin; while (exponentRange >>= 1) ++bitsToStoreExponent; //IMPORTANT ENCODING LOCATED RIGHT HERE IN THIS COMMENT!!! //00 = 6th power, 01=7th, 10=8th, 11=9th, //first 2 bits are for 2, next 2 are for 3, next 2 are for 5, etc. etc. unsigned int exponentCounter = 0; for(Vi::iterator keyExponentValues = it->begin(); ; ) { for (int j=globals.exponentMin; j<globals.exponentMax; j++){ for (int k=0;k<bitsToStoreExponent;k++){ //set i'th prime number bits to appropiate value between 0 and 2^k for exponent value j //globals.exponentMin - j want to turn this into binary representation, get appropriate number for ith place if (k==j){ //keys[counter].primeRepresentation(); //(globals.exponentMin - j) might be useful if (*keyExponentValues % intPow(2,k)==0){//base 10 number convert to base two, get ith digit. keys[counter].primeRepresentation.set(globals.howManyOfFirstNBitsStoredInKey - exponentCounter*bitsToStoreExponent,1); } else{ keys[counter].primeRepresentation.set(globals.howManyOfFirstNBitsStoredInKey - exponentCounter*bitsToStoreExponent,0); } } } } //illustrative but less general example //switch(keyExponentValues->me[i]){ // case 6: // keys[counter].primeRepresentation(); // keys[counter].primeRepresentation.set[32-i*2,0]; // keys[counter].primeRepresentation.set[31-i*2,0]; // break; // case 7: // keys[counter].primeRepresentation(); // keys[counter].primeRepresentation.set[32,0]; // keys[counter].primeRepresentation.set[31,1]; // break; // case 8: // keys[counter].primeRepresentation(); // keys[counter].primeRepresentation.set[32,1]; // keys[counter].primeRepresentation.set[31,0]; // break; // case 9: // keys[counter].primeRepresentation(); // keys[counter].primeRepresentation.set[32,1]; // keys[counter].primeRepresentation.set[31,1]; // break; //} exponentCounter++; keyExponentValues++; } } counter++; it++; } //HERE IS WHERE WE READ THE FILE IN THAT WE WILL ENCODE //TODO move this to a different section //char* input = getInputFromFile(); //unsigned int i = 0; //while (input[i] != '\0'){ //} return 0; }