Lkc: fix some memory leaks
This commit is contained in:
parent
2d1f5edc91
commit
48254ba7d7
@ -3,6 +3,14 @@
|
|||||||
#include "LiftedCircuit.h"
|
#include "LiftedCircuit.h"
|
||||||
|
|
||||||
|
|
||||||
|
OrNode::~OrNode (void)
|
||||||
|
{
|
||||||
|
delete leftBranch_;
|
||||||
|
delete rightBranch_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
OrNode::weight (void) const
|
OrNode::weight (void) const
|
||||||
{
|
{
|
||||||
@ -13,6 +21,14 @@ OrNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AndNode::~AndNode (void)
|
||||||
|
{
|
||||||
|
delete leftBranch_;
|
||||||
|
delete rightBranch_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
AndNode::weight (void) const
|
AndNode::weight (void) const
|
||||||
{
|
{
|
||||||
@ -28,6 +44,13 @@ int SetOrNode::nrNeg_ = -1;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SetOrNode::~SetOrNode (void)
|
||||||
|
{
|
||||||
|
delete follow_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
SetOrNode::weight (void) const
|
SetOrNode::weight (void) const
|
||||||
{
|
{
|
||||||
@ -51,6 +74,13 @@ SetOrNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SetAndNode::~SetAndNode (void)
|
||||||
|
{
|
||||||
|
delete follow_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
SetAndNode::weight (void) const
|
SetAndNode::weight (void) const
|
||||||
{
|
{
|
||||||
@ -59,6 +89,15 @@ SetAndNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
IncExcNode::~IncExcNode (void)
|
||||||
|
{
|
||||||
|
delete plus1Branch_;
|
||||||
|
delete plus2Branch_;
|
||||||
|
delete minusBranch_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
IncExcNode::weight (void) const
|
IncExcNode::weight (void) const
|
||||||
{
|
{
|
||||||
@ -75,6 +114,13 @@ IncExcNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LeafNode::~LeafNode (void)
|
||||||
|
{
|
||||||
|
delete clause_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
LeafNode::weight (void) const
|
LeafNode::weight (void) const
|
||||||
{
|
{
|
||||||
@ -113,6 +159,13 @@ LeafNode::weight (void) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SmoothNode::~SmoothNode (void)
|
||||||
|
{
|
||||||
|
Clause::deleteClauses (clauses_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
SmoothNode::weight (void) const
|
SmoothNode::weight (void) const
|
||||||
{
|
{
|
||||||
@ -189,6 +242,19 @@ LiftedCircuit::LiftedCircuit (const LiftedWCNF* lwcnf)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LiftedCircuit::~LiftedCircuit (void)
|
||||||
|
{
|
||||||
|
delete root_;
|
||||||
|
unordered_map<CircuitNode*, Clauses>::iterator it;
|
||||||
|
it = originClausesMap_.begin();
|
||||||
|
while (it != originClausesMap_.end()) {
|
||||||
|
Clause::deleteClauses (it->second);
|
||||||
|
++ it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
LiftedCircuit::isCompilationSucceeded (void) const
|
LiftedCircuit::isCompilationSucceeded (void) const
|
||||||
{
|
{
|
||||||
@ -334,6 +400,9 @@ LiftedCircuit::tryUnitPropagation (
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Globals::verbosity > 1) {
|
||||||
|
Clause::deleteClauses (backupClauses_);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,6 +444,9 @@ LiftedCircuit::tryIndependence (
|
|||||||
(*follow) = andNode;
|
(*follow) = andNode;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (Globals::verbosity > 1) {
|
||||||
|
Clause::deleteClauses (backupClauses_);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,6 +489,9 @@ LiftedCircuit::tryShannonDecomp (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Globals::verbosity > 1) {
|
||||||
|
Clause::deleteClauses (backupClauses_);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,6 +568,9 @@ LiftedCircuit::tryInclusionExclusion (
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Globals::verbosity > 1) {
|
||||||
|
Clause::deleteClauses (backupClauses_);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,6 +606,9 @@ LiftedCircuit::tryIndepPartialGrounding (
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Globals::verbosity > 1) {
|
||||||
|
Clause::deleteClauses (backupClauses_);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -620,6 +701,9 @@ LiftedCircuit::tryAtomCounting (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Globals::verbosity > 1) {
|
||||||
|
Clause::deleteClauses (backupClauses_);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ class CircuitNode
|
|||||||
public:
|
public:
|
||||||
CircuitNode (void) { }
|
CircuitNode (void) { }
|
||||||
|
|
||||||
|
virtual ~CircuitNode (void) { }
|
||||||
|
|
||||||
virtual double weight (void) const = 0;
|
virtual double weight (void) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -35,6 +37,8 @@ class OrNode : public CircuitNode
|
|||||||
public:
|
public:
|
||||||
OrNode (void) : CircuitNode(), leftBranch_(0), rightBranch_(0) { }
|
OrNode (void) : CircuitNode(), leftBranch_(0), rightBranch_(0) { }
|
||||||
|
|
||||||
|
~OrNode (void);
|
||||||
|
|
||||||
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
||||||
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
||||||
|
|
||||||
@ -55,6 +59,8 @@ class AndNode : public CircuitNode
|
|||||||
AndNode (CircuitNode* leftBranch, CircuitNode* rightBranch)
|
AndNode (CircuitNode* leftBranch, CircuitNode* rightBranch)
|
||||||
: CircuitNode(), leftBranch_(leftBranch), rightBranch_(rightBranch) { }
|
: CircuitNode(), leftBranch_(leftBranch), rightBranch_(rightBranch) { }
|
||||||
|
|
||||||
|
~AndNode (void);
|
||||||
|
|
||||||
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
||||||
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
||||||
|
|
||||||
@ -73,6 +79,8 @@ class SetOrNode : public CircuitNode
|
|||||||
SetOrNode (unsigned nrGroundings)
|
SetOrNode (unsigned nrGroundings)
|
||||||
: CircuitNode(), follow_(0), nrGroundings_(nrGroundings) { }
|
: CircuitNode(), follow_(0), nrGroundings_(nrGroundings) { }
|
||||||
|
|
||||||
|
~SetOrNode (void);
|
||||||
|
|
||||||
CircuitNode** follow (void) { return &follow_; }
|
CircuitNode** follow (void) { return &follow_; }
|
||||||
|
|
||||||
static unsigned nrPositives (void) { return nrPos_; }
|
static unsigned nrPositives (void) { return nrPos_; }
|
||||||
@ -98,6 +106,8 @@ class SetAndNode : public CircuitNode
|
|||||||
SetAndNode (unsigned nrGroundings)
|
SetAndNode (unsigned nrGroundings)
|
||||||
: CircuitNode(), follow_(0), nrGroundings_(nrGroundings) { }
|
: CircuitNode(), follow_(0), nrGroundings_(nrGroundings) { }
|
||||||
|
|
||||||
|
~SetAndNode (void);
|
||||||
|
|
||||||
CircuitNode** follow (void) { return &follow_; }
|
CircuitNode** follow (void) { return &follow_; }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight (void) const;
|
||||||
@ -115,6 +125,8 @@ class IncExcNode : public CircuitNode
|
|||||||
IncExcNode (void)
|
IncExcNode (void)
|
||||||
: CircuitNode(), plus1Branch_(0), plus2Branch_(0), minusBranch_(0) { }
|
: CircuitNode(), plus1Branch_(0), plus2Branch_(0), minusBranch_(0) { }
|
||||||
|
|
||||||
|
~IncExcNode (void);
|
||||||
|
|
||||||
CircuitNode** plus1Branch (void) { return &plus1Branch_; }
|
CircuitNode** plus1Branch (void) { return &plus1Branch_; }
|
||||||
CircuitNode** plus2Branch (void) { return &plus2Branch_; }
|
CircuitNode** plus2Branch (void) { return &plus2Branch_; }
|
||||||
CircuitNode** minusBranch (void) { return &minusBranch_; }
|
CircuitNode** minusBranch (void) { return &minusBranch_; }
|
||||||
@ -135,6 +147,8 @@ class LeafNode : public CircuitNode
|
|||||||
LeafNode (Clause* clause, const LiftedWCNF& lwcnf)
|
LeafNode (Clause* clause, const LiftedWCNF& lwcnf)
|
||||||
: CircuitNode(), clause_(clause), lwcnf_(lwcnf) { }
|
: CircuitNode(), clause_(clause), lwcnf_(lwcnf) { }
|
||||||
|
|
||||||
|
~LeafNode (void);
|
||||||
|
|
||||||
const Clause* clause (void) const { return clause_; }
|
const Clause* clause (void) const { return clause_; }
|
||||||
|
|
||||||
Clause* clause (void) { return clause_; }
|
Clause* clause (void) { return clause_; }
|
||||||
@ -154,6 +168,8 @@ class SmoothNode : public CircuitNode
|
|||||||
SmoothNode (const Clauses& clauses, const LiftedWCNF& lwcnf)
|
SmoothNode (const Clauses& clauses, const LiftedWCNF& lwcnf)
|
||||||
: CircuitNode(), clauses_(clauses), lwcnf_(lwcnf) { }
|
: CircuitNode(), clauses_(clauses), lwcnf_(lwcnf) { }
|
||||||
|
|
||||||
|
~SmoothNode (void);
|
||||||
|
|
||||||
const Clauses& clauses (void) const { return clauses_; }
|
const Clauses& clauses (void) const { return clauses_; }
|
||||||
|
|
||||||
Clauses clauses (void) { return clauses_; }
|
Clauses clauses (void) { return clauses_; }
|
||||||
@ -192,6 +208,8 @@ class LiftedCircuit
|
|||||||
public:
|
public:
|
||||||
LiftedCircuit (const LiftedWCNF* lwcnf);
|
LiftedCircuit (const LiftedWCNF* lwcnf);
|
||||||
|
|
||||||
|
~LiftedCircuit (void);
|
||||||
|
|
||||||
bool isCompilationSucceeded (void) const;
|
bool isCompilationSucceeded (void) const;
|
||||||
|
|
||||||
double getWeightedModelCount (void) const;
|
double getWeightedModelCount (void) const;
|
||||||
|
@ -327,6 +327,16 @@ Clause::printClauses (const Clauses& clauses)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Clause::deleteClauses (Clauses& clauses)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < clauses.size(); i++) {
|
||||||
|
delete clauses[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::ostream&
|
std::ostream&
|
||||||
operator<< (ostream &os, const Clause& clause)
|
operator<< (ostream &os, const Clause& clause)
|
||||||
{
|
{
|
||||||
@ -445,7 +455,7 @@ LiftedWCNF::LiftedWCNF (const ParfactorList& pfList)
|
|||||||
|
|
||||||
LiftedWCNF::~LiftedWCNF (void)
|
LiftedWCNF::~LiftedWCNF (void)
|
||||||
{
|
{
|
||||||
|
Clause::deleteClauses (clauses_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,6 +137,8 @@ class Clause
|
|||||||
|
|
||||||
static void printClauses (const vector<Clause*>& clauses);
|
static void printClauses (const vector<Clause*>& clauses);
|
||||||
|
|
||||||
|
static void deleteClauses (vector<Clause*>& clauses);
|
||||||
|
|
||||||
friend std::ostream& operator<< (ostream &os, const Clause& clause);
|
friend std::ostream& operator<< (ostream &os, const Clause& clause);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user