if( output.is_open()){
output.close();
}
- snprintf(buffer, sizeof(buffer), "./run.sh java edu.mit.csail.sdg.alloy4whole.ExampleAlloyCompilerNoViz %s > %s", alloyFileName, solutionFile);
+ snprintf(buffer, sizeof(buffer), "./run.sh java -Xmx10000m edu.mit.csail.sdg.alloy4whole.ExampleAlloyCompilerNoViz %s > %s", alloyFileName, solutionFile);
int status = system(buffer);
if (status == 0) {
//Read data in from results file
res = encodePredicate((BooleanPredicate *) constraint);
break;
}
+ case BOOLEANVAR:{
+ res = encodeBooleanVar( (BooleanVar *) constraint);
+ break;
+ }
default:
ASSERT(0);
}
}
}
+string AlloyEnc::encodeBooleanVar( BooleanVar *bv){
+ BooleanSig * boolSig = sigEnc.getBooleanSignature(bv);
+ return *boolSig + " = 1";
+}
+
string AlloyEnc::encodeOperatorPredicate(BooleanPredicate *constraint){
PredicateOperator *predicate = (PredicateOperator *) constraint->predicate;
ASSERT(constraint->inputs.getSize() == 2);
output << str << endl;
}
+bool AlloyEnc::getBooleanValue(Boolean *b){
+ if (b->boolVal == BV_MUSTBETRUE)
+ return true;
+ else if (b->boolVal == BV_MUSTBEFALSE)
+ return false;
+ return sigEnc.getBooleanSignature(b);
+}
+
uint64_t AlloyEnc::getValue(Element * element){
ElementEncoding *elemEnc = element->getElementEncoding();
if (elemEnc->numVars == 0)//case when the set has only one item
void encode();
int solve();
void writeToFile(string str);
- uint64_t getValue(Element * element);
+ uint64_t getValue(Element *element);
+ bool getBooleanValue(Boolean *element);
~AlloyEnc();
private:
void dumpAlloyIntScope();
string encodeConstraint(BooleanEdge constraint);
int getResult();
string encodeBooleanLogic( BooleanLogic *bl);
+ string encodeBooleanVar( BooleanVar *bv);
string encodePredicate( BooleanPredicate *bp);
string encodeOperatorPredicate(BooleanPredicate *constraint);
CSolver *csolver;
#include "signature.h"
#include "set.h"
+bool BooleanSig::encodeSet = true;
+
+BooleanSig::BooleanSig(uint id):
+ Signature(id),
+ value(-1)
+{
+}
+
+bool BooleanSig::getValue(){
+ ASSERT(value != -1);
+ return (bool) value;
+}
+
+string BooleanSig::toString() const{
+ return "Boolean" + to_string(id) + ".value";
+}
+
+string BooleanSig::getSignature() const{
+ string str;
+ if(encodeSet){
+ encodeSet = false;
+ str += "one sig BooleanSet {\n\
+ domain: set Int\n\
+ }{\n\
+ domain = 0 + 1 \n\
+ }\n";
+ }
+ str += "one sig Boolean" + to_string(id) + " {\n\
+ value: Int\n\
+ }{\n\
+ value in BooleanSet.domain\n\
+ }";
+ return str;
+}
+
ElementSig::ElementSig(uint id, SetSig *_ssig):
Signature(id),
ssig(_ssig),
value(0)
{
-
}
string ElementSig::toString() const{
uint id;
};
+class BooleanSig: public Signature{
+public:
+ BooleanSig(uint id);
+ bool getValue();
+ void setValue(bool v) {value = v; }
+ virtual ~BooleanSig(){}
+ virtual string toString() const;
+ virtual string getSignature() const;
+private:
+ int value;
+ static bool encodeSet;
+};
+
class SetSig: public Signature{
public:
SetSig(uint id, Set *set);
}
}
+BooleanSig *SignatureEnc::getBooleanSignature(Boolean *bvar){
+ BooleanSig *bsig = (BooleanSig *)encoded.get((void *)bvar);
+ if(bsig == NULL){
+ bsig = new BooleanSig(signatures.getSize());
+ encoded.put(bvar, bsig);
+ signatures.push(bsig);
+ alloyEncoder->writeToFile(bsig->getSignature());
+ }
+ return bsig;
+}
+
ElementSig *SignatureEnc::getElementSignature(Element *element){
ElementSig *esig = (ElementSig *)encoded.get((void *)element);
if(esig == NULL){
updateMaxValue(set);
}
esig = new ElementSig(signatures.getSize(), ssig);
- element->print();
- model_print(" = Element%u\n", signatures.getSize());
encoded.put(element, esig);
signatures.push(esig);
alloyEncoder->writeToFile(esig->getSignature());
~SignatureEnc();
void setValue(uint id, uint64_t value);
ElementSig *getElementSignature(Element *element);
+ BooleanSig *getBooleanSignature(Boolean *bvar);
int getAlloyIntScope();
uint64_t getValue(Element *element);
private:
}
CSolver *solver = CSolver::deserialize(argv[1]);
if(argc == 3)
- solver->setAlloyEncode();
+ solver->setAlloyEncoder();
int value = solver->solve();
if (value == 1) {
printf("%s is SAT\n", argv[1]);
CCSOLVER(solver)->mustHaveValue( (Element *) element);
}
-void setAlloyEncode(void *solver){
- CCSOLVER(solver)->setAlloyEncode();
+void setAlloyEncoder(void *solver){
+ CCSOLVER(solver)->setAlloyEncoder();
}
void *clone(void *solver) {
void printConstraints(void *solver);
void serialize(void *solver);
void mustHaveValue(void *solver, void *element);
-void setAlloyEncode(void *solver);
+void setAlloyEncoder(void *solver);
void *clone(void *solver);
#ifdef __cplusplus
}
class Signature;
class ElementSig;
class SetSig;
+class BooleanSig;
struct IncrementalSolver;
typedef struct IncrementalSolver IncrementalSolver;
struct TableEntry;
return result;
}
-void CSolver::setAlloyEncode(){
+void CSolver::setAlloyEncoder(){
alloyEncoder = new AlloyEnc(this);
}
case ELEMSET:
case ELEMCONST:
case ELEMFUNCRETURN:
- return alloyEncoder == NULL? getElementValueSATTranslator(this, element):
- alloyEncoder->getValue(element);
+ return useAlloyCompiler()? alloyEncoder->getValue(element):
+ getElementValueSATTranslator(this, element);
default:
ASSERT(0);
}
Boolean *boolean = bedge.getBoolean();
switch (boolean->type) {
case BOOLEANVAR:
- return getBooleanVariableValueSATTranslator(this, boolean);
+ return useAlloyCompiler()? alloyEncoder->getBooleanValue(boolean):
+ getBooleanVariableValueSATTranslator(this, boolean);
default:
ASSERT(0);
}
void autoTune(uint budget);
void inferFixedOrders();
void inferFixedOrder(Order *order);
- void setAlloyEncode();
-
+ void setAlloyEncoder();
+ bool useAlloyCompiler() {return alloyEncoder != NULL;}
void setTuner(Tuner *_tuner) { tuner = _tuner; }
long long getElapsedTime() { return elapsedTime; }
long long getEncodeTime();
csolverlb.clone.restype = c_void_p
csolverlb.serialize.argtypes = [c_void_p]
csolverlb.serialize.restype = None
- csolverlb.setAlloyEncode.argtypes = [c_void_p]
- csolverlb.setAlloyEncode.restype = None
+ csolverlb.setAlloyEncoder.argtypes = [c_void_p]
+ csolverlb.setAlloyEncoder.restype = None
return csolverlb