main.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <sstream>
  2. #include <fstream>
  3. #include <list>
  4. #include <deque>
  5. #include <cmath>
  6. #include <vector>
  7. #include "walk.hpp"
  8. struct{
  9. bool operator()(const Semigroup& l, const Semigroup& r) const { return l.cost > r.cost; }
  10. } customLess;
  11. void compute_cost(Semigroup& S){
  12. if(S.g>=g_max-10) S.cost=0;
  13. else{
  14. Stack stack;
  15. stack.next()->copy(S);
  16. stack.push();
  17. Results results;
  18. results.clear();
  19. walk(stack,results,min(g_max,S.g+4));
  20. double r=pow((double)results.n,0.25);
  21. S.cost=pow(r,log(double(g_max-S.g)));
  22. }
  23. }
  24. bool must_split(const Semigroup& S){
  25. return (S.g<g_max) and ((S.left<4 and S.cost>=min_cost_to_split and true) or (S.left==1));
  26. }
  27. void split(const Semigroup& S,deque<Semigroup>& to_explore){
  28. list<Semigroup> res;
  29. auto it=SonIterator(&S);
  30. size_t irr_pos=0;
  31. while(it.move_next()){
  32. Semigroup& son=to_explore.emplace_back();
  33. son.son(S,it.get_gen(),irr_pos++);
  34. }
  35. }
  36. void set_tasks(vector<Semigroup>& tasks){
  37. deque<Semigroup> to_explore;
  38. Semigroup& root=to_explore.emplace_back();
  39. root.init_N();
  40. while(not to_explore.empty()){
  41. Semigroup S=to_explore.front();
  42. compute_cost(S);
  43. //cout<<S.cost<<endl;
  44. to_explore.pop_front();
  45. if(must_split(S)){
  46. split(S,to_explore);
  47. }
  48. else{
  49. tasks.push_back(S);
  50. }
  51. }
  52. }
  53. using namespace std;
  54. int main(){
  55. cout<<"g_max = "<<g_max<<endl;
  56. vector<Semigroup> tasks;
  57. set_tasks(tasks);
  58. size_t nb_tasks=tasks.size();
  59. cout<<"Number of tasks : "<<nb_tasks<<endl;
  60. Results results;
  61. results.clear();
  62. Stack stack;
  63. size_t temp=0;
  64. for(size_t i=0;i<nb_tasks;++i){
  65. results.clear();
  66. Semigroup& S=tasks[i];
  67. treat(S,results);
  68. //stack.next()->copy(S);
  69. //stack.push();
  70. //walk(stack,results);
  71. if(S.cost>=10) ++temp;
  72. /*if(S.g < g_max-10 and results.n>=10){
  73. cout<<S.cost<<" "<<results.n<<endl;
  74. }*/
  75. }
  76. cout<<temp<<endl;
  77. /*size_t m_max=0;
  78. for(int m=0;m<=g_max;++m){
  79. cout<<m<<" "<<results.n2[m]<<endl;
  80. }*/
  81. }