treewalk.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <chrono>
  4. #include <cmath>
  5. #include <cpuid.h>
  6. #include <fstream>
  7. #include "treewalk.hpp"
  8. using namespace std;
  9. using namespace std::chrono;
  10. fstream file;
  11. void treat(const monoid& m){
  12. // int w=m.e*m.left-m.conductor;
  13. int q=ceil(float(m.conductor)/float(m.min));
  14. unsigned int rho=q*m.min-m.conductor;
  15. if(m.wilf<=rho){
  16. if((m.wilf<0) or (m.wilf<=rho and m.e>2 and m.left_primitive>1 and q>=4)){
  17. output(m,file);
  18. }
  19. }
  20. }
  21. //static const int mcut=ceil(float(3*(MAX_GENUS+2))/5);
  22. bool cut(const monoid& m){
  23. if(3*m.left_primitive>=m.min) return true;
  24. return false;
  25. }
  26. void walk_children(monoid m)
  27. {
  28. monoid data[MAX_GENUS-1], *stack[MAX_GENUS], *current,temp;
  29. monoid **stack_pointer = stack + 1;
  30. for (ind_t i=1; i<MAX_GENUS; i++) stack[i] = &(data[i-1]); // Nathann's trick to avoid copy
  31. stack[0] = &m;
  32. while (stack_pointer != stack)
  33. {
  34. --stack_pointer;
  35. current = *stack_pointer;
  36. if(not cut(*current))
  37. {
  38. if (current->genus < MAX_GENUS - 1)
  39. {
  40. auto it = generator_iter<CHILDREN>(*current);
  41. ind_t pos=0;
  42. while (it.move_next())
  43. {
  44. // exchange top with top+1
  45. stack_pointer[0] = stack_pointer[1];
  46. remove_generator(**stack_pointer, *current, it.get_gen(),pos++);
  47. treat(**stack_pointer);
  48. stack_pointer++;
  49. }
  50. *stack_pointer = current;
  51. }
  52. else
  53. {
  54. auto it = generator_iter<CHILDREN>(*current);
  55. ind_t pos=0;
  56. while (it.move_next())
  57. {
  58. remove_generator(temp, *current, it.get_gen(),pos++);
  59. treat(temp);
  60. }
  61. }
  62. }
  63. }
  64. }
  65. int main(int argc, char **argv)
  66. {
  67. monoid O,S;
  68. string nproc = "0";
  69. if(argc!=3){
  70. cerr<<"Usage : "<<argv[0]<<" [m] [k] with k in [1,m-1]"<<endl;
  71. exit(-1);
  72. }
  73. int m=atoi(argv[1]);
  74. int k=atoi(argv[2]);
  75. if(k<=0 or k>=m){
  76. cerr<<"k must be in [1,m-1]"<<endl;
  77. exit(-2);
  78. }
  79. unsigned int ax, bx, cx, dx;
  80. if (!__get_cpuid(0x00000001, &ax, &bx, &cx, &dx))
  81. {
  82. cerr << "Unable to determine the processor type !" << endl;
  83. return EXIT_FAILURE;
  84. }
  85. if (!(cx & bit_SSSE3))
  86. {
  87. cerr << "This programm require sse3 instructions set !" << endl;
  88. return EXIT_FAILURE;
  89. }
  90. if (!(cx & bit_POPCNT))
  91. {
  92. cerr << "This programm require popcount instruction !" << endl;
  93. return EXIT_FAILURE;
  94. }
  95. cout << "Testing Wilf's conjecture for numerical semigroups of genus <= "
  96. << MAX_GENUS << " which are sons of O_{"<<m<<"}\\{"<<m+k<<"}."<<endl;
  97. auto begin = high_resolution_clock::now();
  98. init_ordinary(O,m);
  99. remove_generator(S,O,m+k,k);
  100. string filename="output3/wilf_"+to_string(m)+"_"+to_string(k);
  101. file.open(filename.c_str(),ios::out|ios::trunc);
  102. walk_children(S);
  103. auto end = high_resolution_clock::now();
  104. duration<double> ticks = end-begin;
  105. cout << " Computation time = " << std::setprecision(4) << ticks.count() << " s." << endl;
  106. file.close();
  107. return EXIT_SUCCESS;
  108. }