delete iterator;
}
+void tokenize(string const &str, const char delim, vector<std::string> &out)
+{
+ size_t start;
+ size_t end = 0;
+
+ while ((start = str.find_first_not_of(delim, end)) != string::npos)
+ {
+ end = str.find(delim, start);
+ out.push_back(str.substr(start, end - start));
+ }
+}
+
int AlloyEnc::getResult(){
ifstream input(solutionFile, ios::in);
string line;
if(regex_match(line, regex("Unsatisfiable."))){
return IS_UNSAT;
}
- if(regex_match(line, regex(".*Element\\d+.*value=.*Element\\d+.*->\\d+.*"))){
- int tmp=0, index=0, value=0;
- const char* s = line.c_str();
- uint i1, i2, i3;
- uint64_t i4;
- if (4 == sscanf(s,"%*[^0123456789]%u%*[^0123456789]%d%*[^0123456789]%d%*[^0123456789]%" PRId64 "", &i1, &i2, &i3, &i4)){
- model_print("Element%d = %" PRId64 "\n", i1, i4);
- sigEnc.setValue(i1, i4);
+ if(regex_match(line, regex(".*Element.*value=.*Element\\d+.*->\\d+.*"))){
+ vector<string> values;
+ const char delim = ',';
+ tokenize(line, delim, values);
+ for (uint i=0; i<values.size(); i++){
+ uint i1, i2;
+ uint64_t i3;
+ if (3 == sscanf(values[i].c_str(),"%*[^0123456789]%d%*[^0123456789]%d%*[^0123456789]%" PRId64 "", &i1, &i2, &i3)){
+ model_print("Element%d = %" PRId64 "\n", i1, i3);
+ sigEnc.setValue(i1, i3);
+ }
}
}
}
}
string AlloyEnc::encodeOperatorPredicate(BooleanPredicate *constraint){
- constraint->print();
PredicateOperator *predicate = (PredicateOperator *) constraint->predicate;
ASSERT(constraint->inputs.getSize() == 2);
string str;
#include "signature.h"
#include "set.h"
-bool BooleanSig::encodeAbsSig = true;
+bool BooleanSig::encodeAbs = true;
+bool SetSig::encodeAbs = true;
+bool ElementSig::encodeAbs = true;
BooleanSig::BooleanSig(uint id):
Signature(id),
string BooleanSig::getSignature() const{
string str;
- if(encodeAbsSig){
- encodeAbsSig = false;
- str += "one sig BooleanSet {\n\
- domain: set Int\n\
- }{\n\
- domain = 0 + 1 \n\
+ if(encodeAbs){
+ encodeAbs = false;
+ str += getAbsSignature();
+ }
+ str += "one sig Boolean" + to_string(id) + " extends AbsBool {}";
+ return str;
+}
+
+string BooleanSig::getAbsSignature() const{
+ string str;
+ if(SetSig::encodeAbs){
+ SetSig::encodeAbs = false;
+ str += "abstract sig AbsSet {\
+ domain: set Int\
}\n";
}
- str += "one sig Boolean" + to_string(id) + " {\n\
- value: Int\n\
+ str +="one sig BooleanSet extends AbsSet {}{\n\
+ domain = 0 + 1 \n\
+ }\n\
+ abstract sig AbsBool {\
+ value: Int\
}{\n\
value in BooleanSet.domain\n\
- }";
+ }\n";
return str;
}
}
string ElementSig::getSignature() const{
- return "one sig Element" + to_string(id) + " {\n\
- value: Int\n\
- }{\n\
+ string str;
+ if(encodeAbs){
+ encodeAbs = false;
+ str += getAbsSignature();
+ }
+ str += "one sig Element" + to_string(id) + " extends AbsElement {}{\n\
value in " + *ssig + "\n\
}";
+ return str;
+}
+
+string ElementSig::getAbsSignature() const{
+ return "abstract sig AbsElement {\n\
+ value: Int\n\
+ }\n";
}
}
string SetSig::getSignature() const{
- return "one sig Set" + to_string(id) + " {\n\
- domain: set Int\n\
- }{\n\
+ string str;
+ if(encodeAbs){
+ encodeAbs = false;
+ str += getAbsSignature();
+ }
+ str += "one sig Set" + to_string(id) + " extends AbsSet {}{\n\
domain = " + domain + "\n\
}";
+ return str;
+}
+
+string SetSig::getAbsSignature() const{
+ return "abstract sig AbsSet {\n\
+ domain: set Int\n\
+ }\n";
}
Signature(uint _id):id(_id){}
string operator+(const string& s);
virtual string toString() const = 0;
+ virtual string getAbsSignature() const =0;
virtual string getSignature() const =0;
virtual ~Signature(){}
protected:
void setValue(bool v) {value = v; }
virtual ~BooleanSig(){}
virtual string toString() const;
+ virtual string getAbsSignature() const;
virtual string getSignature() const;
private:
int value;
- static bool encodeAbsSig;
+ static bool encodeAbs;
};
class SetSig: public Signature{
SetSig(uint id, Set *set);
virtual ~SetSig(){}
virtual string toString() const;
+ virtual string getAbsSignature() const;
virtual string getSignature() const;
+ static bool encodeAbs;
private:
string domain;
};
void setValue(uint64_t v){value = v;}
virtual ~ElementSig(){}
virtual string toString() const;
+ virtual string getAbsSignature() const;
virtual string getSignature() const;
private:
SetSig *ssig;
uint64_t value;
+ static bool encodeAbs;
};
string operator+(const string& str, const Signature& sig);