Main.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if(nbThread < 1) {
  37. nbThread = 1;
  38. }
  39. break;
  40. case 's':
  41. verbose = false;
  42. break;
  43. case 'm':
  44. maxIteration = atoi(optarg);
  45. break;
  46. case '?':
  47. help(argv[0]);
  48. }
  49. }
  50. if(!optI) {
  51. help(argv[0]);
  52. }
  53. GSATThread* gsat = new GSATThread(nbThread, 3, gsatArg);
  54. printf("c nbThreads: %d\n", nbThread);
  55. printf("c nbVariables: %d\n", gsat->getNbVariables());
  56. printf("c nbClauses: %d\n", gsat->getNbClauses());
  57. bool result = gsat->solve(maxIteration, verbose);
  58. if(!verbose) {
  59. printf("s %s\n", result?"SATISFIABLE":"NOT FOUND");
  60. }
  61. }