Main.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 help(char* prog) {
  9. fprintf(stderr, "usage: %s -i file.cnf [-t int] [-s] [-e double] [-d]\n\t-i CNF file to solve\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\t-d Use dynamic alpha (default is static alpha = %.1f)\n", prog, ALPHA_STATIC);
  10. exit(1);
  11. }
  12. int main(int argc, char* argv[]) {
  13. extern char * optarg;
  14. int nbThread = DEFAULT_NB_THREAD;
  15. bool verbose = true;
  16. int opt;
  17. bool optI = false;
  18. bool optE = false;
  19. double epsilon = 0.1;
  20. bool optD = false;
  21. char** gsatArg = (char**) malloc(sizeof(char*) * 3);
  22. gsatArg[0] = (char*) malloc(sizeof(char) * strlen(argv[0]) + 1);
  23. memset(gsatArg[0], 0, strlen(argv[0]) + 1);
  24. strncpy(gsatArg[0], argv[0], strlen(argv[0]));
  25. while((opt = getopt(argc, argv, "si:t:e:d")) != -1) {
  26. switch(opt) {
  27. case 'i':
  28. optI = true;
  29. gsatArg[1] = (char*) malloc(sizeof(char) * 3);
  30. memset(gsatArg[1], 0, 3);
  31. strncpy(gsatArg[1], "-i", 2);
  32. gsatArg[2] = (char*) malloc(sizeof(char) * strlen(optarg) + 1);
  33. memset(gsatArg[2], 0, strlen(optarg) + 1);
  34. strncpy(gsatArg[2], optarg, strlen(optarg));
  35. break;
  36. case 't':
  37. nbThread = atoi(optarg);
  38. if(nbThread < 1) {
  39. nbThread = 1;
  40. }
  41. break;
  42. case 's':
  43. verbose = false;
  44. break;
  45. case 'e':
  46. optE = true;
  47. epsilon = strtod(optarg, NULL);
  48. break;
  49. case 'd':
  50. optD = true;
  51. break;
  52. case '?':
  53. help(argv[0]);
  54. }
  55. }
  56. if(!optI) {
  57. help(argv[0]);
  58. }
  59. GSATThread* gsat = new GSATThread(nbThread, 3, gsatArg);
  60. if(optE) {
  61. gsat->useEpsilonMethod(epsilon, !optD);
  62. } else {
  63. gsat->useEmaMethod(!optD);
  64. }
  65. printf("c nbThreads: %d\n", nbThread);
  66. printf("c nbVariables: %d\n", gsat->getNbVariables());
  67. printf("c nbClauses: %d\n", gsat->getNbClauses());
  68. bool result = gsat->solve(verbose);
  69. if(!verbose) {
  70. printf("s %s\n", result?"SATISFIABLE":"NOT FOUND");
  71. }
  72. }