treewalk.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <chrono>
  4. #include <cmath>
  5. #include <cpuid.h>
  6. #include <fstream>
  7. #include <csignal>
  8. #include <unistd.h>
  9. #include "treewalk.hpp"
  10. using namespace std;
  11. using namespace std::chrono;
  12. bool stack_correct;
  13. #define SIGNAL_CHECKPOINT SIGUSR2
  14. void treat(const Semigroup& m){
  15. int q=ceil(float(m.conductor)/float(m.min));
  16. unsigned int rho=q*m.min-m.conductor;
  17. if(m.wilf<=rho){
  18. if((m.wilf<0) or (m.wilf<=rho and m.e>2 and m.left_primitive>1 and q>=4)){
  19. //output(m,file_out);
  20. }
  21. }
  22. }
  23. void walk(Stack& stack,size_t* res){
  24. Semigroup *current,*son;
  25. Semigroup temp;
  26. while(not stack.is_empty()){
  27. current = stack.pop();
  28. size_t g=current->genus;
  29. if(true or not cut(*current)){
  30. if(g < MAX_GENUS - 1){
  31. auto it=generator_iter<CHILDREN>(*current);
  32. ind_t pos=0;
  33. while (it.move_next()){
  34. remove_generator(temp, *current, it.get_gen(),pos++);
  35. if(is_special(temp)){
  36. son=stack.pushed();
  37. *son=temp;
  38. res[g+1]++;
  39. }
  40. //treat(*son);
  41. }
  42. }
  43. else{
  44. auto it = generator_iter<CHILDREN>(*current);
  45. ind_t pos=0;
  46. while (it.move_next()){
  47. remove_generator(temp, *current, it.get_gen(),pos++);
  48. if(is_special(temp)){
  49. res[g+1]++;
  50. }
  51. //treat(temp);
  52. }
  53. }
  54. }
  55. }
  56. }
  57. /*int main(int argc, char **argv){
  58. if(argc!=2){
  59. cerr<<"Usage : "<<argv[0]<<" tasks/task_file"<<endl;
  60. exit(-1);
  61. }
  62. char* task_filename=argv[1];
  63. unsigned int ax, bx, cx, dx;
  64. if (!__get_cpuid(0x00000001, &ax, &bx, &cx, &dx)){
  65. cerr << "Unable to determine the processor type !" << endl;
  66. return EXIT_FAILURE;
  67. }
  68. if (!(cx & bit_SSSE3)){
  69. cerr << "This programm require sse3 instructions set !" << endl;
  70. return EXIT_FAILURE;
  71. }
  72. if (!(cx & bit_POPCNT)){
  73. cerr << "This programm require popcount instruction !" << endl;
  74. return EXIT_FAILURE;
  75. }
  76. fstream file_in;
  77. file_in.open(task_filename,ios::in|ios::binary);
  78. string filename=string("tasks/")+task_filename;
  79. filename+="-out";
  80. file_out.open(filename,ios::out|ios::trunc);
  81. Stack stack;
  82. char d[3*MAX_GENUS+1];
  83. char c,g,m;
  84. size_t n;
  85. file_in.read((char*)&n,8);
  86. cout<<"Stack size = "<<n<<endl;
  87. for(size_t i=0;i<n;++i){
  88. file_in.read(&c,1);
  89. file_in.read(&g,1);
  90. file_in.read(&m,1);
  91. file_in.read(d,3*MAX_GENUS+1);
  92. Semigroup* S=stack.pushed();
  93. init(*S,c,g,m,d);
  94. treat(*S);
  95. }
  96. file_in.close();
  97. checkpoint=false;
  98. signal(SIGNAL_CHECKPOINT, signal_checkpoint_handler);
  99. walk(stack);
  100. file_out.close();
  101. if(checkpoint){
  102. cout<<"Stoping exploration due to checkpoint signal reception."<<endl;
  103. filename=string("tasks/checkpoint/")+task_filename+string("-checkpoint");
  104. fstream file_stack;
  105. file_stack.open(filename.c_str(),ios::out|ios::binary);
  106. size_t size=stack.stack_size;
  107. file_stack.write((char*)(&size),8);
  108. cout<<"Checkpoint size : "<<size<<endl;
  109. for(size_t i=0;i<size;++i){
  110. record(*stack.stack[i],file_stack);
  111. }
  112. file_stack.close();
  113. return 1;
  114. }
  115. else{
  116. return 0;
  117. }
  118. }
  119. */