Bug fixes for Java API + Exactly one constraints + Adding support for getting the...
[satune.git] / src / Backend / inc_solver.cc
index c1bebb806ad0e453ebd1e5a7e087ca34ac697551..72d34083dcd4b096b32aee4b51816a361f708600 100644 (file)
@@ -102,6 +102,16 @@ int getSolution(IncrementalSolver *This) {
                }
                readSolver(This, &This->solution[1], numVars * sizeof(int));
                This->solutionsize = numVars;
+       } else { //Reading unsat explanation
+               int numVars = readIntSolver(This);
+               if (numVars > This->solutionsize) {
+                       if (This->solution != NULL)
+                               ourfree(This->solution);
+                       This->solution = (int *) ourmalloc((numVars + 1) * sizeof(int));
+                       This->solution[0] = 0;
+               }
+               readSolver(This, &This->solution[1], numVars * sizeof(int));
+               This->solutionsize = numVars;
        }
        return result;
 }
@@ -117,23 +127,23 @@ int readStatus(IncrementalSolver *This) {
        fd_set rfds;
        FD_ZERO(&rfds);
        FD_SET(This->from_solver_fd, &rfds);
-       fd_set * temp;
-       if(This->timeout == NOTIMEOUT){
-               retval = select(This->from_solver_fd+1, &rfds, NULL, NULL, NULL);
-       }else {
+       fd_set *temp;
+       if (This->timeout == NOTIMEOUT) {
+               retval = select(This->from_solver_fd + 1, &rfds, NULL, NULL, NULL);
+       } else {
                struct timeval tv;
                tv.tv_sec = This->timeout;
                tv.tv_usec = 0;
-               retval = select(This->from_solver_fd+1, &rfds, NULL, NULL, &tv);
+               retval = select(This->from_solver_fd + 1, &rfds, NULL, NULL, &tv);
        }
-       if(retval == -1){
+       if (retval == -1) {
                perror("Error in select()");
                exit(EXIT_FAILURE);
        }
-       else if (retval){
+       else if (retval) {
                printf("Data is available now.\n");
                return readIntSolver(This);
-       }else{
+       } else {
                printf("Timeout for the solver\n");
                return IS_INDETER;
        }