2012-10-22 23:01:13 +01:00
|
|
|
#ifndef HORUS_LIFTEDCIRCUIT_H
|
|
|
|
#define HORUS_LIFTEDCIRCUIT_H
|
|
|
|
|
2012-11-01 22:34:28 +00:00
|
|
|
#include <stack>
|
|
|
|
|
2012-10-22 23:01:13 +01:00
|
|
|
#include "LiftedWCNF.h"
|
|
|
|
|
|
|
|
|
2012-10-24 21:22:49 +01:00
|
|
|
enum CircuitNodeType {
|
|
|
|
OR_NODE,
|
|
|
|
AND_NODE,
|
|
|
|
SET_OR_NODE,
|
|
|
|
SET_AND_NODE,
|
|
|
|
INC_EXC_NODE,
|
|
|
|
LEAF_NODE,
|
|
|
|
SMOOTH_NODE,
|
|
|
|
TRUE_NODE,
|
2012-10-30 12:41:00 +00:00
|
|
|
COMPILATION_FAILED_NODE
|
2012-10-24 21:22:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-22 23:01:13 +01:00
|
|
|
class CircuitNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CircuitNode (const Clauses& clauses, string explanation = "")
|
|
|
|
: clauses_(clauses), explanation_(explanation) { }
|
|
|
|
|
2012-10-25 12:22:52 +01:00
|
|
|
const Clauses& clauses (void) const { return clauses_; }
|
|
|
|
|
|
|
|
Clauses clauses (void) { return clauses_; }
|
2012-10-22 23:01:13 +01:00
|
|
|
|
2012-10-30 12:41:00 +00:00
|
|
|
virtual double weight (void) const = 0;
|
2012-10-22 23:01:13 +01:00
|
|
|
|
|
|
|
string explanation (void) const { return explanation_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Clauses clauses_;
|
|
|
|
string explanation_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-24 21:22:49 +01:00
|
|
|
class OrNode : public CircuitNode
|
2012-10-22 23:01:13 +01:00
|
|
|
{
|
|
|
|
public:
|
2012-10-24 21:22:49 +01:00
|
|
|
OrNode (const Clauses& clauses, string explanation = "")
|
2012-10-22 23:01:13 +01:00
|
|
|
: CircuitNode (clauses, explanation),
|
2012-10-24 21:22:49 +01:00
|
|
|
leftBranch_(0), rightBranch_(0) { }
|
2012-10-22 23:01:13 +01:00
|
|
|
|
2012-10-24 21:22:49 +01:00
|
|
|
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
|
|
|
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
2012-11-01 22:34:28 +00:00
|
|
|
|
|
|
|
double weight (void) const;
|
2012-10-22 23:01:13 +01:00
|
|
|
private:
|
2012-10-24 21:22:49 +01:00
|
|
|
CircuitNode* leftBranch_;
|
|
|
|
CircuitNode* rightBranch_;
|
2012-10-22 23:01:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-24 21:22:49 +01:00
|
|
|
class AndNode : public CircuitNode
|
2012-10-22 23:01:13 +01:00
|
|
|
{
|
|
|
|
public:
|
2012-10-24 21:22:49 +01:00
|
|
|
AndNode (const Clauses& clauses, string explanation = "")
|
2012-10-22 23:01:13 +01:00
|
|
|
: CircuitNode (clauses, explanation),
|
2012-10-24 21:22:49 +01:00
|
|
|
leftBranch_(0), rightBranch_(0) { }
|
|
|
|
|
|
|
|
AndNode (
|
|
|
|
const Clauses& clauses,
|
|
|
|
CircuitNode* leftBranch,
|
|
|
|
CircuitNode* rightBranch,
|
|
|
|
string explanation = "")
|
|
|
|
: CircuitNode (clauses, explanation),
|
|
|
|
leftBranch_(leftBranch), rightBranch_(rightBranch) { }
|
|
|
|
|
|
|
|
AndNode (
|
|
|
|
CircuitNode* leftBranch,
|
|
|
|
CircuitNode* rightBranch,
|
|
|
|
string explanation = "")
|
|
|
|
: CircuitNode ({}, explanation),
|
|
|
|
leftBranch_(leftBranch), rightBranch_(rightBranch) { }
|
|
|
|
|
2012-10-31 23:58:07 +00:00
|
|
|
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
2012-10-24 21:22:49 +01:00
|
|
|
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
2012-11-01 22:34:28 +00:00
|
|
|
|
|
|
|
double weight (void) const;
|
|
|
|
|
2012-10-22 23:01:13 +01:00
|
|
|
private:
|
2012-10-24 21:22:49 +01:00
|
|
|
CircuitNode* leftBranch_;
|
|
|
|
CircuitNode* rightBranch_;
|
2012-10-22 23:01:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-27 00:13:11 +01:00
|
|
|
class SetOrNode : public CircuitNode
|
2012-10-22 23:01:13 +01:00
|
|
|
{
|
|
|
|
public:
|
2012-11-01 22:34:28 +00:00
|
|
|
SetOrNode (unsigned nrGroundings, const Clauses& clauses)
|
|
|
|
: CircuitNode (clauses, " AC"), follow_(0),
|
|
|
|
nrGroundings_(nrGroundings) { }
|
|
|
|
|
2012-10-27 00:13:11 +01:00
|
|
|
CircuitNode** follow (void) { return &follow_; }
|
2012-11-01 22:34:28 +00:00
|
|
|
|
|
|
|
static unsigned nrPositives (void) { return nrGrsStack.top().first; }
|
|
|
|
|
|
|
|
static unsigned nrNegatives (void) { return nrGrsStack.top().second; }
|
|
|
|
|
|
|
|
double weight (void) const;
|
|
|
|
|
2012-10-22 23:01:13 +01:00
|
|
|
private:
|
2012-11-01 22:34:28 +00:00
|
|
|
CircuitNode* follow_;
|
|
|
|
unsigned nrGroundings_;
|
|
|
|
|
|
|
|
static stack<pair<unsigned, unsigned>> nrGrsStack;
|
2012-10-22 23:01:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-27 00:13:11 +01:00
|
|
|
class SetAndNode : public CircuitNode
|
2012-10-22 23:01:13 +01:00
|
|
|
{
|
|
|
|
public:
|
2012-10-29 15:39:56 +00:00
|
|
|
SetAndNode (unsigned nrGroundings, const Clauses& clauses)
|
2012-11-01 22:34:28 +00:00
|
|
|
: CircuitNode (clauses, " IPG"), follow_(0),
|
|
|
|
nrGroundings_(nrGroundings) { }
|
|
|
|
|
|
|
|
CircuitNode** follow (void) { return &follow_; }
|
2012-10-27 00:13:11 +01:00
|
|
|
|
|
|
|
double weight (void) const;
|
2012-11-01 22:34:28 +00:00
|
|
|
|
2012-10-22 23:01:13 +01:00
|
|
|
private:
|
2012-10-29 20:49:21 +00:00
|
|
|
CircuitNode* follow_;
|
2012-11-01 22:34:28 +00:00
|
|
|
unsigned nrGroundings_;
|
2012-10-22 23:01:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-30 00:21:10 +00:00
|
|
|
class IncExcNode : public CircuitNode
|
2012-10-22 23:01:13 +01:00
|
|
|
{
|
|
|
|
public:
|
2012-10-30 00:21:10 +00:00
|
|
|
IncExcNode (const Clauses& clauses)
|
|
|
|
: CircuitNode (clauses), plus1Branch_(0),
|
|
|
|
plus2Branch_(0), minusBranch_(0) { }
|
2012-10-31 23:58:07 +00:00
|
|
|
|
2012-10-30 00:21:10 +00:00
|
|
|
CircuitNode** plus1Branch (void) { return &plus1Branch_; }
|
|
|
|
CircuitNode** plus2Branch (void) { return &plus2Branch_; }
|
|
|
|
CircuitNode** minusBranch (void) { return &minusBranch_; }
|
2012-11-01 22:34:28 +00:00
|
|
|
|
|
|
|
double weight (void) const;
|
2012-10-31 23:58:07 +00:00
|
|
|
|
2012-10-22 23:01:13 +01:00
|
|
|
private:
|
2012-10-30 00:21:10 +00:00
|
|
|
CircuitNode* plus1Branch_;
|
|
|
|
CircuitNode* plus2Branch_;
|
|
|
|
CircuitNode* minusBranch_;
|
2012-10-22 23:01:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LeafNode : public CircuitNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LeafNode (const Clause& clause) : CircuitNode ({clause}) { }
|
2012-10-25 12:22:52 +01:00
|
|
|
|
|
|
|
double weight (void) const;
|
2012-10-24 21:22:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SmoothNode : public CircuitNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SmoothNode (const Clauses& clauses) : CircuitNode (clauses) { }
|
2012-10-25 12:22:52 +01:00
|
|
|
|
|
|
|
double weight (void) const;
|
2012-10-22 23:01:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TrueNode : public CircuitNode
|
|
|
|
{
|
|
|
|
public:
|
2012-10-30 00:21:10 +00:00
|
|
|
TrueNode (void) : CircuitNode ({}) { }
|
2012-10-25 12:22:52 +01:00
|
|
|
|
|
|
|
double weight (void) const;
|
2012-10-22 23:01:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-30 12:41:00 +00:00
|
|
|
class CompilationFailedNode : public CircuitNode
|
2012-10-22 23:01:13 +01:00
|
|
|
{
|
|
|
|
public:
|
2012-10-30 12:41:00 +00:00
|
|
|
CompilationFailedNode (const Clauses& clauses) : CircuitNode (clauses) { }
|
|
|
|
|
|
|
|
double weight (void) const;
|
2012-10-22 23:01:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LiftedCircuit
|
|
|
|
{
|
|
|
|
public:
|
2012-10-31 23:43:39 +00:00
|
|
|
LiftedCircuit (const LiftedWCNF* lwcnf);
|
2012-10-22 23:01:13 +01:00
|
|
|
|
2012-10-24 21:22:49 +01:00
|
|
|
void smoothCircuit (void);
|
|
|
|
|
2012-10-25 12:22:52 +01:00
|
|
|
double getWeightedModelCount (void) const;
|
|
|
|
|
2012-10-24 21:22:49 +01:00
|
|
|
void exportToGraphViz (const char*);
|
2012-10-25 12:22:52 +01:00
|
|
|
|
2012-10-22 23:01:13 +01:00
|
|
|
private:
|
|
|
|
|
2012-10-27 00:13:11 +01:00
|
|
|
void compile (CircuitNode** follow, Clauses& clauses);
|
2012-10-22 23:01:13 +01:00
|
|
|
|
2012-10-27 00:13:11 +01:00
|
|
|
bool tryUnitPropagation (CircuitNode** follow, Clauses& clauses);
|
2012-11-01 13:56:12 +00:00
|
|
|
|
2012-10-27 00:13:11 +01:00
|
|
|
bool tryIndependence (CircuitNode** follow, Clauses& clauses);
|
2012-11-01 13:56:12 +00:00
|
|
|
|
2012-10-27 00:13:11 +01:00
|
|
|
bool tryShannonDecomp (CircuitNode** follow, Clauses& clauses);
|
2012-11-01 13:56:12 +00:00
|
|
|
|
2012-10-30 00:21:10 +00:00
|
|
|
bool tryInclusionExclusion (CircuitNode** follow, Clauses& clauses);
|
2012-11-01 13:56:12 +00:00
|
|
|
|
2012-10-27 00:13:11 +01:00
|
|
|
bool tryIndepPartialGrounding (CircuitNode** follow, Clauses& clauses);
|
2012-11-01 13:56:12 +00:00
|
|
|
|
2012-10-29 20:49:21 +00:00
|
|
|
bool tryIndepPartialGroundingAux (Clauses& clauses, ConstraintTree& ct,
|
|
|
|
vector<unsigned>& indices);
|
2012-11-01 13:56:12 +00:00
|
|
|
|
2012-10-31 23:43:39 +00:00
|
|
|
bool tryAtomCounting (CircuitNode** follow, Clauses& clauses);
|
2012-11-01 13:56:12 +00:00
|
|
|
|
|
|
|
bool tryGrounding (CircuitNode** follow, Clauses& clauses);
|
|
|
|
|
|
|
|
void shatterCountedLogVars (Clauses& clauses);
|
|
|
|
|
|
|
|
bool shatterCountedLogVarsAux (Clauses& clauses);
|
2012-10-31 23:43:39 +00:00
|
|
|
|
2012-11-01 13:56:12 +00:00
|
|
|
bool shatterCountedLogVarsAux (Clauses& clauses, size_t idx1, size_t idx2);
|
2012-10-31 23:43:39 +00:00
|
|
|
|
2012-11-04 18:02:40 +00:00
|
|
|
LitLvTypesSet smoothCircuit (CircuitNode* node);
|
2012-10-24 21:22:49 +01:00
|
|
|
|
2012-11-04 18:02:40 +00:00
|
|
|
void createSmoothNode (const LitLvTypesSet& lids,
|
2012-10-30 15:48:19 +00:00
|
|
|
CircuitNode** prev);
|
2012-10-24 21:22:49 +01:00
|
|
|
|
2012-10-30 15:48:19 +00:00
|
|
|
CircuitNodeType getCircuitNodeType (const CircuitNode* node) const;
|
|
|
|
|
2012-10-24 21:22:49 +01:00
|
|
|
void exportToGraphViz (CircuitNode* node, ofstream&);
|
2012-10-30 14:31:52 +00:00
|
|
|
|
|
|
|
void printClauses (const CircuitNode* node, ofstream&,
|
|
|
|
string extraOptions = "");
|
2012-10-30 15:48:19 +00:00
|
|
|
|
|
|
|
string escapeNode (const CircuitNode* node) const;
|
2012-10-22 23:01:13 +01:00
|
|
|
|
|
|
|
CircuitNode* root_;
|
|
|
|
const LiftedWCNF* lwcnf_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HORUS_LIFTEDCIRCUIT_H
|
2012-10-24 21:22:49 +01:00
|
|
|
|