Main.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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]\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", prog);
  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. char** gsatArg = (char**) malloc(sizeof(char*) * 3);
  21. gsatArg[0] = (char*) malloc(sizeof(char) * strlen(argv[0]) + 1);
  22. memset(gsatArg[0], 0, strlen(argv[0]) + 1);
  23. strncpy(gsatArg[0], argv[0], strlen(argv[0]));
  24. while((opt = getopt(argc, argv, "si:t:e:")) != -1) {
  25. switch(opt) {
  26. case 'i':
  27. optI = true;
  28. gsatArg[1] = (char*) malloc(sizeof(char) * 3);
  29. memset(gsatArg[1], 0, 3);
  30. strncpy(gsatArg[1], "-i", 2);
  31. gsatArg[2] = (char*) malloc(sizeof(char) * strlen(optarg) + 1);
  32. memset(gsatArg[2], 0, strlen(optarg) + 1);
  33. strncpy(gsatArg[2], optarg, strlen(optarg));
  34. break;
  35. case 't':
  36. nbThread = atoi(optarg);
  37. if(nbThread < 1) {
  38. nbThread = 1;
  39. }
  40. break;
  41. case 's':
  42. verbose = false;
  43. break;
  44. case 'e':
  45. optE = true;
  46. epsilon = strtod(optarg, NULL);
  47. break;
  48. case '?':
  49. help(argv[0]);
  50. }
  51. }
  52. if(!optI) {
  53. help(argv[0]);
  54. }
  55. GSATThread* gsat = new GSATThread(nbThread, 3, gsatArg);
  56. if(optE) {
  57. gsat->useEpsilonMethod(epsilon);
  58. }
  59. printf("c nbThreads: %d\n", nbThread);
  60. printf("c nbVariables: %d\n", gsat->getNbVariables());
  61. printf("c nbClauses: %d\n", gsat->getNbClauses());
  62. bool result = gsat->solve(verbose);
  63. if(!verbose) {
  64. printf("s %s\n", result?"SATISFIABLE":"NOT FOUND");
  65. }
  66. }