abort when compilation failed

This commit is contained in:
Tiago Gomes 2012-11-27 16:54:02 +00:00
parent 610e55a4a2
commit ee1b7dcd21
3 changed files with 31 additions and 8 deletions

View File

@ -156,10 +156,9 @@ TrueNode::weight (void) const
double double
CompilationFailedNode::weight (void) const CompilationFailedNode::weight (void) const
{ {
// we should not perform model counting // weighted model counting in compilation
// in compilation failed nodes // failed nodes should give nan
// abort(); return 0.0 / 0.0;
return 0.0;
} }
@ -168,21 +167,33 @@ LiftedCircuit::LiftedCircuit (const LiftedWCNF* lwcnf)
: lwcnf_(lwcnf) : lwcnf_(lwcnf)
{ {
root_ = 0; root_ = 0;
compilationSucceeded_ = true;
Clauses clauses = lwcnf->clauses(); Clauses clauses = lwcnf->clauses();
compile (&root_, clauses); compile (&root_, clauses);
if (Globals::verbosity > 1) { if (Globals::verbosity > 1) {
smoothCircuit (root_); smoothCircuit (root_);
exportToGraphViz("circuit.smooth.dot"); exportToGraphViz("circuit.smooth.dot");
double wmc = LogAware::exp (getWeightedModelCount()); if (compilationSucceeded_) {
cout << "WEIGHTED MODEL COUNT: " << wmc << endl << endl; double wmc = LogAware::exp (getWeightedModelCount());
cout << "WEIGHTED MODEL COUNT: " << wmc << endl << endl;
}
} }
} }
bool
LiftedCircuit::isCompilationSucceeded (void) const
{
return compilationSucceeded_;
}
double double
LiftedCircuit::getWeightedModelCount (void) const LiftedCircuit::getWeightedModelCount (void) const
{ {
assert (compilationSucceeded_);
return root_->weight(); return root_->weight();
} }
@ -211,6 +222,11 @@ LiftedCircuit::compile (
CircuitNode** follow, CircuitNode** follow,
Clauses& clauses) Clauses& clauses)
{ {
if (compilationSucceeded_ == false
&& Globals::verbosity <= 1) {
return;
}
if (clauses.empty()) { if (clauses.empty()) {
*follow = new TrueNode (); *follow = new TrueNode ();
return; return;
@ -245,8 +261,8 @@ LiftedCircuit::compile (
return; return;
} }
// assert (false);
*follow = new CompilationFailedNode (clauses); *follow = new CompilationFailedNode (clauses);
compilationSucceeded_ = false;
} }

View File

@ -209,7 +209,9 @@ class CompilationFailedNode : public CircuitNode
class LiftedCircuit class LiftedCircuit
{ {
public: public:
LiftedCircuit (const LiftedWCNF* lwcnf); LiftedCircuit (const LiftedWCNF* lwcnf);
bool isCompilationSucceeded (void) const;
double getWeightedModelCount (void) const; double getWeightedModelCount (void) const;
@ -266,6 +268,7 @@ class LiftedCircuit
CircuitNode* root_; CircuitNode* root_;
const LiftedWCNF* lwcnf_; const LiftedWCNF* lwcnf_;
bool compilationSucceeded_;
}; };
#endif // HORUS_LIFTEDCIRCUIT_H #endif // HORUS_LIFTEDCIRCUIT_H

View File

@ -21,6 +21,10 @@ LiftedKc::solveQuery (const Grounds& query)
LiftedOperations::runWeakBayesBall (pfList_, query); LiftedOperations::runWeakBayesBall (pfList_, query);
lwcnf_ = new LiftedWCNF (pfList_); lwcnf_ = new LiftedWCNF (pfList_);
circuit_ = new LiftedCircuit (lwcnf_); circuit_ = new LiftedCircuit (lwcnf_);
if (circuit_->isCompilationSucceeded() == false) {
cerr << "error: compilation failed" << endl;
abort();
}
vector<PrvGroup> groups; vector<PrvGroup> groups;
Ranges ranges; Ranges ranges;
for (size_t i = 0; i < query.size(); i++) { for (size_t i = 0; i < query.size(); i++) {