Main.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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] [-m int]\n\t-i CNF file to solve\n\t-t Number of threads to use\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 nbThread = DEFAULT_NB_THREAD;
  15. int maxIteration = 0;
  16. bool verbose = true;
  17. int opt;
  18. bool optI = false;
  19. char** gsatArg = (char**) malloc(sizeof(char*) * 3);
  20. gsatArg[0] = (char*) malloc(sizeof(char) * strlen(argv[0]) + 1);
  21. memset(gsatArg[0], 0, strlen(argv[0]) + 1);
  22. strncpy(gsatArg[0], argv[0], strlen(argv[0]));
  23. while((opt = getopt(argc, argv, "si:t:m:")) != -1) {
  24. switch(opt) {
  25. case 'i':
  26. optI = true;
  27. gsatArg[1] = (char*) malloc(sizeof(char) * 3);
  28. memset(gsatArg[1], 0, 3);
  29. strncpy(gsatArg[1], "-i", 2);
  30. gsatArg[2] = (char*) malloc(sizeof(char) * strlen(optarg) + 1);
  31. memset(gsatArg[2], 0, strlen(optarg) + 1);
  32. strncpy(gsatArg[2], optarg, strlen(optarg));
  33. break;
  34. case 't':
  35. nbThread = atoi(optarg);
  36. break;
  37. case 's':
  38. verbose = false;
  39. break;
  40. case 'm':
  41. maxIteration = atoi(optarg);
  42. break;
  43. case '?':
  44. help(argv[0]);
  45. }
  46. }
  47. if(!optI) {
  48. help(argv[0]);
  49. }
  50. GSATThread* gsat = new GSATThread(nbThread, 3, gsatArg);
  51. printf("c nbThreads: %d\n", nbThread);
  52. printf("c nbVariables: %d\n", gsat->getNbVariables());
  53. printf("c nbClauses: %d\n", gsat->getNbClauses());
  54. bool result = gsat->solve(maxIteration, verbose);
  55. if(!verbose) {
  56. printf("s %s\n", result?"SATISFIABLE":"NOT FOUND");
  57. }
  58. }