}
compileRunCommand(buffer, sizeof(buffer));
int status = system(buffer);
- if (status == 0) {
+ if (status == 0 || status == 512 ) { //For some unknown reason, SMTSat returns 512 when the problem successfully gets solved
//Read data in from results file
result = getResult();
+ } else {
+ model_print("Error in running command<returned %d>: %s\n", status, buffer);
+ exit(-1);
}
return result;
}
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/*
+ * File: smtsolvers.cc
+ * Author: hamed
+ *
+ * Created on February 21, 2019, 12:26 PM
+ */
+
+#include "mathsatinterpreter.h"
+#include "solver_interface.h"
+
+MathSATInterpreter::MathSATInterpreter(CSolver *solver):
+ SMTInterpreter(solver)
+{
+}
+
+void MathSATInterpreter::compileRunCommand(char * command , size_t size){
+ snprintf(command, size, "timeout %u ./mathsat -model %s > %s", getTimeout(), SMTFILENAME, SMTSOLUTIONFILE);
+}
+
+MathSATInterpreter::~MathSATInterpreter(){
+}
+
+int MathSATInterpreter::getResult(){
+ ifstream input(SMTSOLUTIONFILE, ios::in);
+ string line;
+ while(getline(input, line)){
+ if(line.find("unsat")!= line.npos){
+ return IS_UNSAT;
+ }
+ if(line.find("(") != line.npos){
+ char cline [line.size()+1];
+ strcpy ( cline, line.c_str() );
+ char valuestr [512];
+ uint id;
+ if (2 == sscanf(cline,"%*[^0123456789]%u%*[^0123456789]%s", &id, valuestr)){
+ uint value;
+ if (strcmp (valuestr, "true)") == 0 ){
+ value =1;
+ }else if (strcmp(valuestr, "false)") == 0){
+ value = 0;
+ }else {
+ ASSERT(2 == sscanf(cline, "%*[^0123456789]%u%*[^0123456789]%u", &id, &value));
+ }
+
+ model_print("Signature%u = %u\n", id, value);
+ sigEnc.setValue(id, value);
+ } else {
+ ASSERT(0);
+ }
+ }
+ }
+ return IS_SAT;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/*
+ * File: mathsatinterpreter.h
+ * Author: hamed
+ *
+ * Created on February 21, 2019, 12:26 PM
+ */
+
+#ifndef MATHSATINTERPRETER_H
+#define MATHSATINTERPRETER_H
+
+#include "smtinterpreter.h"
+
+
+class MathSATInterpreter: public SMTInterpreter{
+public:
+ MathSATInterpreter(CSolver *solver);
+ virtual ~MathSATInterpreter();
+protected:
+ virtual void compileRunCommand(char * command , size_t size);
+ virtual int getResult();
+};
+
+
+#endif /* SMTSOLVERS_H */
+
using namespace std;
-#define SMTFILENAME "satune.smt"
-#define SMTSOLUTIONFILE "solution.sol"
-
SMTInterpreter::SMTInterpreter(CSolver *_solver):
Interpreter(_solver)
{
if(line.find("unsat")!= line.npos){
return IS_UNSAT;
}
- if(line.find("(define-fun") != line.npos){
+ if(line.find("(define-fun") != line.npos || line.find("( (") != line.npos){
string valueline;
ASSERT(getline(input, valueline));
char cline [line.size()+1];
#include <iostream>
#include <fstream>
+#define SMTFILENAME "satune.smt"
+#define SMTSOLUTIONFILE "solution.sol"
+
class SMTInterpreter: public Interpreter{
public:
SMTInterpreter(CSolver *solver);
virtual string negateConstraint(string constr);
virtual string encodeBooleanLogic( BooleanLogic *bl);
virtual string encodeBooleanVar( BooleanVar *bv);
- void extractValue(char *idline, char *valueline);
+ virtual void extractValue(char *idline, char *valueline);
virtual string processElementFunction(ElementFunction *element, ValuedSignature *signature);
virtual string operatorPredicateConstraint(CompOp op, ValuedSignature *elemSig1, ValuedSignature *elemSig2);
};
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/*
+ * File: smtratinterpreter.cc
+ * Author: hamed
+ *
+ * Created on February 21, 2019, 2:33 PM
+ */
+
+#include "smtratinterpreter.h"
+
+SMTRatInterpreter::SMTRatInterpreter(CSolver *solver):
+ SMTInterpreter(solver)
+{
+}
+
+void SMTRatInterpreter::compileRunCommand(char * command , size_t size){
+ snprintf(command, size, "timeout %u ./smtrat %s > %s", getTimeout(), SMTFILENAME, SMTSOLUTIONFILE);
+}
+
+SMTRatInterpreter::~SMTRatInterpreter(){
+}
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/*
+ * File: smtratinterpreter.h
+ * Author: hamed
+ *
+ * Created on February 21, 2019, 2:33 PM
+ */
+
+#ifndef SMTRATINTERPRETER_H
+#define SMTRATINTERPRETER_H
+#include "smtinterpreter.h"
+
+class SMTRatInterpreter: public SMTInterpreter{
+public:
+ SMTRatInterpreter(CSolver *solver);
+ virtual ~SMTRatInterpreter();
+protected:
+ void compileRunCommand(char * command , size_t size);
+};
+
+#endif /* SMTRATINTERPRETER_H */
+
return Z3;
} else if(strcmp (itype,"--smtrat") == 0){
return SMTRAT;
- } else if(strcmp (itype,"--alloy") == 0){
- return ALLOY;
+ } else if(strcmp (itype,"--mathsat") == 0){
+ return MATHSAT;
} else {
printf("Unknown interpreter type: %s\n", itype);
- printf("./run.sh deserializer test.dump [--alloy/--z3/--smtrat/--mathsmt]\n");
+ printf("./run.sh deserializer test.dump [--alloy/--z3/--smtrat/--mathsat]\n");
exit(-1);
}
}
printf("%d\n", argc);
if (argc != 2 && argc != 3) {
printf("You only specify the name of the file ...\n");
- printf("./run.sh deserializer test.dump [--alloy/--z3/--smtrat/--mathsmt]\n");
+ printf("./run.sh deserializer test.dump [--alloy/--z3/--smtrat/--mathsat]\n");
exit(-1);
}
CSolver *solver;
#include <stdarg.h>
#include "alloyinterpreter.h"
#include "smtinterpreter.h"
+#include "mathsatinterpreter.h"
+#include "smtratinterpreter.h"
CSolver::CSolver() :
boolTrue(BooleanEdge(new BooleanConst(true))),
interpreter = new SMTInterpreter(this);
break;
}
- case MATHSAT:
- case SMTRAT:
+ case MATHSAT:{
+ interpreter = new MathSATInterpreter(this);
+ break;
+ }
+ case SMTRAT:{
+ interpreter = new SMTRatInterpreter(this);
+ break;
+ }
default:
ASSERT(0);
}