Przeglądaj źródła

Add cut and treat.

Jean Fromentin 1 rok temu
rodzic
commit
ce36af2ba9

+ 2 - 1
c++/src/gtask.hpp

@@ -3,6 +3,7 @@
 #include <iostream>
 #include "../dist/task.hpp"
 #include "semigroup.hpp"
+#include "results.hpp"
 
 using namespace std;
 struct GTaskInput{
@@ -10,7 +11,7 @@ struct GTaskInput{
 };
 
 struct GTaskOutput{
-  size_t ng[MAX_GENUS+1];
+  Results res;
 };
 
 Task* generate_gtask();

+ 8 - 14
c++/src/main-server.cpp

@@ -65,27 +65,21 @@ int main(int argc,char** argv){
   cout<<"***************"<<endl;
   cout<<"*    Bilan    *"<<endl;
   cout<<"***************"<<endl;
-  size_t ng[MAX_GENUS+1];
-  for(size_t g=0;g<=MAX_GENUS;++g){
-    ng[g]=1; //Missing left most of each level
-  }  
+  Results res;
+  clear_results(res);
   for(size_t i=0;i<nb_tasks;++i){
     if(tasks[i].get_statut()==Task::Done){
       GTaskOutput& output=*((GTaskOutput*)tasks[i].get_output());
-      for(size_t g=0;g<=MAX_GENUS;++g){
-	ng[g]+=output.ng[g];
+      add_results(res,output.res);
+      if(res.has_counter_example){
+	count<<"A counter example was found : "<<endl;
+	print_Semigroup_gen(res.S_counter_example);
+	break;
       }
-      /*  if(output.number!=0){
-	if(number==0){
-	  cout<<"I found "<<output.sample<<endl;
-	}
-	number+=output.number;
-	}*/
     }
   }
   for(size_t g=0;g<=MAX_GENUS;++g){
-    cout<<g<<" -> "<<ng[g]<<endl;
+    cout<<g<<","<<res.n1[g]<<","<<res.n2[g]<<endl;
   }
-  //cout<<"Among a total of "<<number<<endl;
 			       
 }

+ 20 - 98
c++/src/treewalk.cpp

@@ -10,16 +10,8 @@
 #include "treewalk.hpp"
 
 using namespace std;
-using namespace std::chrono;
 
-
-
-bool stack_correct;
-#define SIGNAL_CHECKPOINT SIGUSR2
-
-
-
-void treat(const Semigroup& m){
+/*void treat(const Semigroup& m){
   int q=ceil(float(m.conductor)/float(m.min));
   unsigned int rho=q*m.min-m.conductor;
   if(m.wilf<=rho){
@@ -27,107 +19,37 @@ void treat(const Semigroup& m){
       //output(m,file_out);
     }
   }
-}
+  }*/
 
 
 
-void walk(Stack& stack,size_t* res){
+void walk(Stack& stack,Results& res){
   Semigroup *current,*son;
   Semigroup temp;
   while(not stack.is_empty()){
     current = stack.pop();
     size_t g=current->genus;
-    if(true or not cut(*current)){
-      if(g < MAX_GENUS - 1){
-	auto it=generator_iter<CHILDREN>(*current);
-	ind_t pos=0;
-	while (it.move_next()){
-	  remove_generator(temp, *current, it.get_gen(),pos++);
-	  if(is_special(temp)){
-	    son=stack.pushed();
-	    *son=temp;
-	    res[g+1]++;
-	  }
-	  //treat(*son);
+    if(g<MAX_GENUS-1){
+      auto it=generator_iter<CHILDREN>(*current);
+      ind_t pos=0;
+      while(it.move_next()){
+	remove_generator(temp, *current, it.get_gen(),pos++);
+	if(not cut(temp)){
+	  treat(temp,res);
+	  son=stack.pushed();
+	  *son=temp;
 	}
       }
-      else{
-	auto it = generator_iter<CHILDREN>(*current);
-	ind_t pos=0;
-	while (it.move_next()){
-	  remove_generator(temp, *current, it.get_gen(),pos++);
-	  if(is_special(temp)){
-	    res[g+1]++;
-	  }
-	  //treat(temp);
+    }
+    else{
+      auto it = generator_iter<CHILDREN>(*current);
+      ind_t pos=0;
+      while(it.move_next()){
+	remove_generator(temp, *current, it.get_gen(),pos++);
+	if(not cut(temp)){
+	  treat(temp,res);
 	}
       }
     }
   }
 }
-
-
-/*int main(int argc, char **argv){
-  if(argc!=2){
-    cerr<<"Usage : "<<argv[0]<<" tasks/task_file"<<endl;
-    exit(-1);
-  }
-  char* task_filename=argv[1];
-  unsigned int ax, bx, cx, dx;
-  if (!__get_cpuid(0x00000001, &ax, &bx, &cx, &dx)){
-    cerr << "Unable to determine the processor type !" << endl;
-    return EXIT_FAILURE;
-  }
-  if (!(cx & bit_SSSE3)){
-    cerr << "This programm require sse3 instructions set !" << endl;
-    return EXIT_FAILURE;
-  }
-  if (!(cx & bit_POPCNT)){
-    cerr << "This programm require popcount instruction !" << endl;
-    return EXIT_FAILURE;
-  }
-  fstream file_in;
-  file_in.open(task_filename,ios::in|ios::binary);
-  string filename=string("tasks/")+task_filename;
-  filename+="-out";
-  file_out.open(filename,ios::out|ios::trunc);
-  Stack stack;
-  char d[3*MAX_GENUS+1];
-  char c,g,m;
-  size_t n;
-  file_in.read((char*)&n,8);
-  cout<<"Stack size = "<<n<<endl;
-  for(size_t i=0;i<n;++i){
-    file_in.read(&c,1);
-    file_in.read(&g,1);
-    file_in.read(&m,1);
-    file_in.read(d,3*MAX_GENUS+1);
-    Semigroup* S=stack.pushed();
-    init(*S,c,g,m,d);
-    treat(*S);
-  }
-  file_in.close();
-  checkpoint=false;
-  signal(SIGNAL_CHECKPOINT, signal_checkpoint_handler);
-  walk(stack);
-
-  file_out.close();
-  if(checkpoint){
-    cout<<"Stoping exploration due to checkpoint signal reception."<<endl;
-    filename=string("tasks/checkpoint/")+task_filename+string("-checkpoint");
-    fstream file_stack;
-    file_stack.open(filename.c_str(),ios::out|ios::binary);
-    size_t size=stack.stack_size;
-    file_stack.write((char*)(&size),8);
-    cout<<"Checkpoint size : "<<size<<endl;
-    for(size_t i=0;i<size;++i){
-      record(*stack.stack[i],file_stack);
-    }
-    file_stack.close();
-    return 1;
-  }
-  else{
-    return 0;
-  }
-}
-*/

+ 6 - 4
c++/src/treewalk.hpp

@@ -2,13 +2,15 @@
 #define TREEWALK_HPP
 #include "semigroup.hpp"
 #include "stack.hpp"
+#include "treat.hpp"
+#include "cuts.hpp"
 
-bool cut(const Semigroup& m);
-void treat(const Semigroup& m);
+//bool cut(const Semigroup& m);
+//void treat(const Semigroup& m);
 void walk(Stack& stack,size_t* res);
 void signal_checkpoint_handler(int signum);
 
-inline bool
+/*inline bool
 cut(const Semigroup& m){
   if(3*m.left_primitive>=m.min) return true;
   return false;
@@ -19,5 +21,5 @@ inline bool is_special(const Semigroup& S){
   ind_t m=S.min;
   ind_t x=c+(m-1)-c%m;
   return S.decs[x]==1;
-}
+}*/
 #endif

+ 4 - 7
c++/src/work.hpp

@@ -6,18 +6,15 @@
 
 using namespace std;
 
-bool work_on(Semigroup& S,size_t* res){
+void work_on(Semigroup& S,Result& res){
   Stack stack;
-  for(size_t g=0;g<=MAX_GENUS;++g){
-    res[g]=0;
-  }
-  if(is_special(S)){
-    res[S.genus]=1;
+  clear_results(res);
+  if(not cut(S)){
+    treat(S,res);
     Semigroup* root=stack.pushed();
     *root=S;
     walk(stack,res);
   }
-  return false;
 }
 
 

BIN
c++/vgcore.2379


+ 0 - 0
old/tasks/checkpoint/.no_erase


+ 0 - 0
old/tasks/done/.no_erase


+ 0 - 0
old/tasks/out/.no_erase