Main.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 [-s] [-m int]\n\t-s Silent mode\n\t-m Max iteration number\n", prog);
  10. exit(1);
  11. }
  12. int main(int argc, char* argv[]) {
  13. extern char * optarg;
  14. int maxIteration = 0;
  15. bool verbose = true;
  16. int opt;
  17. bool optI = false;
  18. char** gsatArg = (char**) malloc(sizeof(char*) * 3);
  19. gsatArg[0] = (char*) malloc(sizeof(char) * strlen(argv[0]) + 1);
  20. memset(gsatArg[0], 0, strlen(argv[0]) + 1);
  21. strncpy(gsatArg[0], argv[0], strlen(argv[0]));
  22. while((opt = getopt(argc, argv, "si:m:")) != -1) {
  23. switch(opt) {
  24. case 'i':
  25. optI = true;
  26. gsatArg[1] = (char*) malloc(sizeof(char) * 3);
  27. memset(gsatArg[1], 0, 3);
  28. strncpy(gsatArg[1], "-i", 2);
  29. gsatArg[2] = (char*) malloc(sizeof(char) * strlen(optarg) + 1);
  30. memset(gsatArg[2], 0, strlen(optarg) + 1);
  31. strncpy(gsatArg[2], optarg, strlen(optarg));
  32. break;
  33. case 's':
  34. verbose = false;
  35. break;
  36. case 'm':
  37. maxIteration = atoi(optarg);
  38. break;
  39. case '?':
  40. help(argv[0]);
  41. }
  42. }
  43. if(!optI) {
  44. help(argv[0]);
  45. }
  46. GSATThread* gsat = new GSATThread(3, gsatArg);
  47. printf("c nbThreads: %d\n", NB_THREAD);
  48. printf("c nbVariables: %d\n", gsat->getNbVariables());
  49. printf("c nbClauses: %d\n", gsat->getNbClauses());
  50. bool result = gsat->solve(maxIteration, verbose);
  51. if(!verbose) {
  52. printf("s %s\n", result?"SATISFIABLE":"NOT FOUND");
  53. }
  54. }