Main.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "GSAT/GSAT.hpp"
  2. #include "GSATThread.hpp"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7. using namespace std;
  8. void test() {
  9. /*ControlBandit cb;
  10. fillAndHeuristic fah;
  11. while(!cb.queueIsEmpty()) {
  12. fah = cb.next();
  13. printf("%d %d\n", fah.fill, fah.heuristic);
  14. }*/
  15. srand(getpid());
  16. double ref = 0;
  17. double avg = 0;
  18. int nb = 0;
  19. int rdm;
  20. for(int i = 0; i < 100; i++) {
  21. rdm = rand();
  22. avg = avg + (1 / (nb + 1.0)) * (rdm - avg);
  23. nb++;
  24. ref += rdm;
  25. }
  26. printf("ref : %f, ite : %f\n", ref/100.0, avg);
  27. exit(0);
  28. }
  29. void help(char* prog) {
  30. fprintf(stderr, "usage: %s -i file.cnf [-t int] [-s] [-e double]\n\t-t Number of threads to use\n\t-s Silent mode\n\t-e Use epsilon greedy method with the value (0 <= value <= 1)\n", prog);
  31. exit(1);
  32. }
  33. int main(int argc, char* argv[]) {
  34. //test();
  35. extern char * optarg;
  36. int nbThread = DEFAULT_NB_THREAD;
  37. bool verbose = true;
  38. int opt;
  39. bool optI = false;
  40. bool optE = false;
  41. double epsilon = 0.1;
  42. char** gsatArg = (char**) malloc(sizeof(char*) * 3);
  43. gsatArg[0] = (char*) malloc(sizeof(char) * strlen(argv[0]) + 1);
  44. memset(gsatArg[0], 0, strlen(argv[0]) + 1);
  45. strncpy(gsatArg[0], argv[0], strlen(argv[0]));
  46. while((opt = getopt(argc, argv, "si:t:e:")) != -1) {
  47. switch(opt) {
  48. case 'i':
  49. optI = true;
  50. gsatArg[1] = (char*) malloc(sizeof(char) * 3);
  51. memset(gsatArg[1], 0, 3);
  52. strncpy(gsatArg[1], "-i", 2);
  53. gsatArg[2] = (char*) malloc(sizeof(char) * strlen(optarg) + 1);
  54. memset(gsatArg[2], 0, strlen(optarg) + 1);
  55. strncpy(gsatArg[2], optarg, strlen(optarg));
  56. break;
  57. case 't':
  58. nbThread = atoi(optarg);
  59. break;
  60. case 's':
  61. verbose = false;
  62. break;
  63. case 'e':
  64. optE = true;
  65. epsilon = strtod(optarg, NULL);
  66. break;
  67. case '?':
  68. help(argv[0]);
  69. }
  70. }
  71. if(!optI) {
  72. help(argv[0]);
  73. }
  74. GSATThread* gsat = new GSATThread(nbThread, 3, gsatArg);
  75. if(optE) {
  76. gsat->useEpsilonMethod(epsilon);
  77. }
  78. printf("c nbThreads: %d\n", nbThread);
  79. printf("c nbVariables: %d\n", gsat->getNbVariables());
  80. printf("c nbClauses: %d\n", gsat->getNbClauses());
  81. bool result = gsat->solve(verbose);
  82. if(!verbose) {
  83. printf("s %s\n", result?"SATISFIABLE":"NOT FOUND");
  84. }
  85. }