Cosmetic fixes

This commit is contained in:
Tiago Gomes 2012-12-27 12:54:58 +00:00
parent 8bdcb65907
commit cbea630fbf
39 changed files with 106 additions and 138 deletions

View File

@ -1,12 +1,6 @@
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include "BayesBall.h"
#include "Util.h"
FactorGraph*

View File

@ -2,8 +2,8 @@
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <fstream>
#include "BayesBallGraph.h"
#include "Util.h"

View File

@ -2,9 +2,7 @@
#define HORUS_BAYESBALLGRAPH_H
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <unordered_map>
#include "Var.h"
#include "Horus.h"
@ -14,7 +12,7 @@ using namespace std;
class BBNode : public Var
{
public:
BBNode (Var* v) : Var (v) , visited_(false),
BBNode (Var* v) : Var (v), visited_(false),
markedOnTop_(false), markedOnBottom_(false) { }
const vector<BBNode*>& childs (void) const { return childs_; }

View File

@ -1,13 +1,10 @@
#include <cassert>
#include <limits>
#include <algorithm>
#include <iostream>
#include "BeliefProp.h"
#include "FactorGraph.h"
#include "Factor.h"
#include "Indexer.h"
#include "Horus.h"
@ -410,7 +407,7 @@ BeliefProp::initializeSolver (void)
bool
BeliefProp::converged (void)
{
if (links_.size() == 0) {
if (links_.empty()) {
return true;
}
if (nIters_ == 0) {

View File

@ -3,12 +3,12 @@
#include <set>
#include <vector>
#include <sstream>
#include "GroundSolver.h"
#include "Factor.h"
#include "FactorGraph.h"
#include "Util.h"
using namespace std;

View File

@ -120,7 +120,7 @@ CTNode::copySubtree (const CTNode* root1)
chIt != n1->childs().end(); ++ chIt) {
CTNode* chCopy = new CTNode (**chIt);
n2->childs().insert_sorted (chCopy);
if ((*chIt)->nrChilds() != 0) {
if ((*chIt)->nrChilds() > 0) {
stack.push_back (StackPair (*chIt, chCopy));
}
}
@ -813,10 +813,10 @@ ConstraintTree::jointCountNormalize (
cts[i]->join (exclCt);
}
if (excl1 != 0) {
if (excl1) {
cts.push_back (excl1);
}
if (excl2 != 0) {
if (excl2) {
cts.push_back (excl2);
}
@ -1072,7 +1072,7 @@ ConstraintTree::getTuples (
CTNodes& continuationNodes) const
{
if (n->isRoot() == false) {
if (currTuples.size() == 0) {
if (currTuples.empty()) {
currTuples.push_back ({ n->symbol()});
} else {
for (size_t i = 0; i < currTuples.size(); i++) {

View File

@ -81,7 +81,7 @@ CountingBp::solveQuery (VarIds queryVids)
reprArgs.push_back (getRepresentative (queryVids[i]));
}
FacNode* reprFac = getRepresentative (facNodes[idx]);
assert (reprFac != 0);
assert (reprFac);
res = solver_->getFactorJoint (reprFac, reprArgs);
}
}

View File

@ -5,7 +5,6 @@
#include "GroundSolver.h"
#include "FactorGraph.h"
#include "Util.h"
#include "Horus.h"
class VarCluster;

View File

@ -1,5 +1,3 @@
#include <limits>
#include <fstream>
#include "ElimGraph.h"
@ -10,30 +8,27 @@ ElimHeuristic ElimGraph::elimHeuristic = MIN_NEIGHBORS;
ElimGraph::ElimGraph (const vector<Factor*>& factors)
{
for (size_t i = 0; i < factors.size(); i++) {
if (factors[i] == 0) { // if contained just one var with evidence
continue;
}
const VarIds& vids = factors[i]->arguments();
for (size_t j = 0; j < vids.size() - 1; j++) {
EgNode* n1 = getEgNode (vids[j]);
if (n1 == 0) {
n1 = new EgNode (vids[j], factors[i]->range (j));
addNode (n1);
}
for (size_t k = j + 1; k < vids.size(); k++) {
EgNode* n2 = getEgNode (vids[k]);
if (n2 == 0) {
n2 = new EgNode (vids[k], factors[i]->range (k));
addNode (n2);
if (factors[i]) {
const VarIds& args = factors[i]->arguments();
for (size_t j = 0; j < args.size() - 1; j++) {
EgNode* n1 = getEgNode (args[j]);
if (!n1) {
n1 = new EgNode (args[j], factors[i]->range (j));
addNode (n1);
}
if (neighbors (n1, n2) == false) {
addEdge (n1, n2);
for (size_t k = j + 1; k < args.size(); k++) {
EgNode* n2 = getEgNode (args[k]);
if (!n2) {
n2 = new EgNode (args[k], factors[i]->range (k));
addNode (n2);
}
if (!neighbors (n1, n2)) {
addEdge (n1, n2);
}
}
}
}
if (vids.size() == 1) {
if (getEgNode (vids[0]) == 0) {
addNode (new EgNode (vids[0], factors[i]->range (0)));
if (args.size() == 1 && !getEgNode (args[0])) {
addNode (new EgNode (args[0], factors[i]->range (0)));
}
}
}
@ -51,16 +46,16 @@ ElimGraph::~ElimGraph (void)
VarIds
ElimGraph::getEliminatingOrder (const VarIds& exclude)
ElimGraph::getEliminatingOrder (const VarIds& excludedVids)
{
VarIds elimOrder;
unmarked_.reserve (nodes_.size());
for (size_t i = 0; i < nodes_.size(); i++) {
if (Util::contains (exclude, nodes_[i]->varId()) == false) {
if (Util::contains (excludedVids, nodes_[i]->varId()) == false) {
unmarked_.insert (nodes_[i]);
}
}
size_t nrVarsToEliminate = nodes_.size() - exclude.size();
size_t nrVarsToEliminate = nodes_.size() - excludedVids.size();
for (size_t i = 0; i < nrVarsToEliminate; i++) {
EgNode* node = getLowestCostNode();
unmarked_.remove (node);
@ -104,7 +99,7 @@ ElimGraph::exportToGraphViz (
}
out << "strict graph {" << endl;
for (size_t i = 0; i < nodes_.size(); i++) {
if (showNeighborless || nodes_[i]->neighbors().size() != 0) {
if (showNeighborless || nodes_[i]->neighbors().empty() == false) {
out << '"' << nodes_[i]->label() << '"' << endl;
}
}
@ -178,7 +173,7 @@ EgNode*
ElimGraph::getLowestCostNode (void) const
{
EgNode* bestNode = 0;
unsigned minCost = std::numeric_limits<unsigned>::max();
unsigned minCost = Util::maxUnsigned();
EGNeighs::const_iterator it;
switch (elimHeuristic) {
case MIN_NEIGHBORS: {
@ -233,7 +228,7 @@ ElimGraph::connectAllNeighbors (const EgNode* n)
if (neighs.size() > 0) {
for (size_t i = 0; i < neighs.size() - 1; i++) {
for (size_t j = i + 1; j < neighs.size(); j++) {
if ( ! neighbors (neighs[i], neighs[j])) {
if (!neighbors (neighs[i], neighs[j])) {
addEdge (neighs[i], neighs[j]);
}
}

View File

@ -7,7 +7,6 @@
#include "TinySet.h"
#include "Horus.h"
using namespace std;
enum ElimHeuristic

View File

@ -7,7 +7,7 @@
#include <sstream>
#include "Factor.h"
#include "Indexer.h"
#include "Var.h"
Factor::Factor (const Factor& g)
@ -100,11 +100,11 @@ Factor::sumOutAllExceptIndex (size_t idx)
void
Factor::multiply (Factor& g)
{
if (args_.size() == 0) {
if (args_.empty()) {
clone (g);
return;
} else {
TFactor<VarId>::multiply (g);
}
TFactor<VarId>::multiply (g);
}

View File

@ -3,7 +3,6 @@
#include <vector>
#include "Var.h"
#include "Indexer.h"
#include "Util.h"

View File

@ -1,13 +1,13 @@
#include <set>
#include <vector>
#include <algorithm>
#include <set>
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <fstream>
#include "FactorGraph.h"
#include "Factor.h"
#include "BayesBall.h"
#include "Util.h"
@ -146,7 +146,7 @@ FactorGraph::readFromLibDaiFormat (const char* fileName)
ignoreLines (is);
is >> ranges[j];
VarNode* var = getVarNode (vids[j]);
if (var != 0 && ranges[j] != var->range()) {
if (var && ranges[j] != var->range()) {
cerr << "Error: variable `" << vids[j] << "' appears in two or " ;
cerr << "more factors with a different range." << endl;
}

View File

@ -9,7 +9,6 @@
using namespace std;
class FacNode;
class VarNode : public Var

View File

@ -1,8 +1,8 @@
#include "GroundSolver.h"
#include "Util.h"
#include "BeliefProp.h"
#include "CountingBp.h"
#include "VarElim.h"
#include "Util.h"
void
@ -47,7 +47,7 @@ Params
GroundSolver::getJointByConditioning (
GroundSolverType solverType,
FactorGraph fg,
const VarIds& jointVarIds) const
const VarIds& jointVarIds)
{
VarNodes jointVars;
for (size_t i = 0; i < jointVarIds.size(); i++) {

View File

@ -4,7 +4,6 @@
#include <iomanip>
#include "FactorGraph.h"
#include "Var.h"
#include "Horus.h"
@ -25,8 +24,8 @@ class GroundSolver
void printAllPosterioris (void);
Params getJointByConditioning (GroundSolverType,
FactorGraph, const VarIds& jointVarIds) const;
static Params getJointByConditioning (GroundSolverType,
FactorGraph, const VarIds& jointVarIds);
protected:
const FactorGraph& fg;

View File

@ -2,6 +2,7 @@
#define HORUS_HISTOGRAM_H
#include <vector>
#include <ostream>
using namespace std;

View File

@ -1,8 +1,6 @@
#ifndef HORUS_HORUS_H
#define HORUS_HORUS_H
#include <limits>
#include <vector>
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \

View File

@ -1,7 +1,7 @@
#include "LiftedBp.h"
#include "LiftedOperations.h"
#include "WeightedBp.h"
#include "FactorGraph.h"
#include "LiftedOperations.h"
LiftedBp::LiftedBp (const ParfactorList& parfactorList)
@ -182,7 +182,7 @@ LiftedBp::rangeOfGround (const Ground& gr)
}
++ it;
}
return std::numeric_limits<unsigned>::max();
return Util::maxUnsigned();
}

View File

@ -5,7 +5,6 @@
#include "Indexer.h"
OrNode::~OrNode (void)
{
delete leftBranch_;
@ -806,7 +805,7 @@ LiftedCircuit::independentLiteral (
LitLvTypesSet
LiftedCircuit::smoothCircuit (CircuitNode* node)
{
assert (node != 0);
assert (node);
LitLvTypesSet propagLits;
switch (getCircuitNodeType (node)) {
@ -1004,23 +1003,23 @@ CircuitNodeType
LiftedCircuit::getCircuitNodeType (const CircuitNode* node) const
{
CircuitNodeType type = CircuitNodeType::OR_NODE;
if (dynamic_cast<const OrNode*>(node) != 0) {
if (dynamic_cast<const OrNode*>(node)) {
type = CircuitNodeType::OR_NODE;
} else if (dynamic_cast<const AndNode*>(node) != 0) {
} else if (dynamic_cast<const AndNode*>(node)) {
type = CircuitNodeType::AND_NODE;
} else if (dynamic_cast<const SetOrNode*>(node) != 0) {
} else if (dynamic_cast<const SetOrNode*>(node)) {
type = CircuitNodeType::SET_OR_NODE;
} else if (dynamic_cast<const SetAndNode*>(node) != 0) {
} else if (dynamic_cast<const SetAndNode*>(node)) {
type = CircuitNodeType::SET_AND_NODE;
} else if (dynamic_cast<const IncExcNode*>(node) != 0) {
} else if (dynamic_cast<const IncExcNode*>(node)) {
type = CircuitNodeType::INC_EXC_NODE;
} else if (dynamic_cast<const LeafNode*>(node) != 0) {
} else if (dynamic_cast<const LeafNode*>(node)) {
type = CircuitNodeType::LEAF_NODE;
} else if (dynamic_cast<const SmoothNode*>(node) != 0) {
} else if (dynamic_cast<const SmoothNode*>(node)) {
type = CircuitNodeType::SMOOTH_NODE;
} else if (dynamic_cast<const TrueNode*>(node) != 0) {
} else if (dynamic_cast<const TrueNode*>(node)) {
type = CircuitNodeType::TRUE_NODE;
} else if (dynamic_cast<const CompilationFailedNode*>(node) != 0) {
} else if (dynamic_cast<const CompilationFailedNode*>(node)) {
type = CircuitNodeType::COMPILATION_FAILED_NODE;
} else {
assert (false);
@ -1033,7 +1032,7 @@ LiftedCircuit::getCircuitNodeType (const CircuitNode* node) const
void
LiftedCircuit::exportToGraphViz (CircuitNode* node, ofstream& os)
{
assert (node != 0);
assert (node);
static unsigned nrAuxNodes = 0;
stringstream ss;

View File

@ -1,9 +1,8 @@
#ifndef HORUS_LIFTEDKC_H
#define HORUS_LIFTEDKC_H
#include "LiftedWCNF.h"
#include "LiftedSolver.h"
#include "LiftedWCNF.h"
#include "ParfactorList.h"

View File

@ -65,7 +65,7 @@ LiftedOperations::runWeakBayesBall (
ParfactorList::iterator it = pfList.begin();
while (it != pfList.end()) {
PrvGroup group = (*it)->findGroup (query[i]);
if (group != numeric_limits<PrvGroup>::max()) {
if (group != std::numeric_limits<PrvGroup>::max()) {
todo.push (group);
done.insert (group);
break;
@ -128,7 +128,7 @@ LiftedOperations::absorveEvidence (
it = pfList.remove (it);
Parfactors absorvedPfs = absorve (obsFormulas[i], pf);
if (absorvedPfs.empty() == false) {
if (absorvedPfs.size() == 1 && absorvedPfs[0] == 0) {
if (absorvedPfs.size() == 1 && !absorvedPfs[0]) {
// just remove pf;
} else {
Util::addToVector (newPfs, absorvedPfs);

View File

@ -1,6 +1,5 @@
#include <cassert>
#include <algorithm>
#include <iostream>
#include <sstream>

View File

@ -1,12 +1,11 @@
#ifndef HORUS_LIFTEDUTILS_H
#define HORUS_LIFTEDUTILS_H
#include <limits>
#include <string>
#include <vector>
#include <unordered_map>
#include "TinySet.h"
#include "Util.h"
@ -107,7 +106,7 @@ class Ground
size_t arity (void) const { return args_.size(); }
bool isAtom (void) const { return args_.size() == 0; }
bool isAtom (void) const { return args_.empty(); }
friend ostream& operator<< (ostream &os, const Ground& gr);

View File

@ -1,4 +1,5 @@
#include <algorithm>
#include <set>
#include "LiftedVe.h"
@ -710,7 +711,7 @@ LiftedVe::getBestOperation (const Grounds& query)
validOps = LiftedOperator::getValidOps (pfList_, query);
for (size_t i = 0; i < validOps.size(); i++) {
double cost = validOps[i]->getLogCost();
if ((bestOp == 0) || (cost < bestCost)) {
if (!bestOp || cost < bestCost) {
bestOp = validOps[i];
bestCost = cost;
}

View File

@ -3,11 +3,10 @@
#include "Indexer.h"
bool
Literal::isGround (ConstraintTree constr, LogVarSet ipgLogVars) const
{
if (logVars_.size() == 0) {
if (logVars_.empty()) {
return true;
}
LogVarSet lvs (logVars_);

View File

@ -1,15 +1,14 @@
#ifndef HORUS_LIFTEDWCNF_H
#define HORUS_LIFTEDWCNF_H
#include <unordered_map>
#include "ParfactorList.h"
using namespace std;
typedef long LiteralId;
class ConstraintTree;
enum LogVarType
{
FULL_LV,
@ -17,8 +16,8 @@ enum LogVarType
NEG_LV
};
typedef vector<LogVarType> LogVarTypes;
typedef long LiteralId;
typedef vector<LogVarType> LogVarTypes;
class Literal

View File

@ -1,4 +1,3 @@
#include "Parfactor.h"
#include "Histogram.h"
#include "Indexer.h"
@ -443,7 +442,7 @@ Parfactor::findGroup (const Ground& ground) const
{
size_t idx = indexOfGround (ground);
return idx == args_.size()
? numeric_limits<PrvGroup>::max()
? std::numeric_limits<PrvGroup>::max()
: args_[idx].group();
}
@ -452,7 +451,7 @@ Parfactor::findGroup (const Ground& ground) const
bool
Parfactor::containsGround (const Ground& ground) const
{
return findGroup (ground) != numeric_limits<PrvGroup>::max();
return findGroup (ground) != std::numeric_limits<PrvGroup>::max();
}

View File

@ -1,15 +1,12 @@
#ifndef HORUS_PARFACTOR_H
#define HORUS_PARFACTOR_H
#include <list>
#include <unordered_map>
#include "Factor.h"
#include "ProbFormula.h"
#include "ConstraintTree.h"
#include "LiftedUtils.h"
#include "Horus.h"
#include "Factor.h"
class Parfactor : public TFactor<ProbFormula>
{

View File

@ -1,5 +1,7 @@
#include <cassert>
#include <queue>
#include "ParfactorList.h"
@ -412,7 +414,7 @@ ParfactorList::shatter (Parfactor* g1, Parfactor* g2)
{
ProbFormulas& formulas1 = g1->arguments();
ProbFormulas& formulas2 = g2->arguments();
assert (g1 != 0 && g2 != 0 && g1 != g2);
assert (g1 && g2 && g1 != g2);
for (size_t i = 0; i < formulas1.size(); i++) {
for (size_t j = 0; j < formulas2.size(); j++) {
if (formulas1[i].sameSkeletonAs (formulas2[j])) {

View File

@ -2,7 +2,6 @@
#define HORUS_PARFACTORLIST_H
#include <list>
#include <queue>
#include "Parfactor.h"
#include "ProbFormula.h"
@ -11,6 +10,8 @@
using namespace std;
class Parfactor;
class ParfactorList
{
public:

View File

@ -40,7 +40,7 @@ ProbFormula::indexOf (LogVar X) const
bool
ProbFormula::isAtom (void) const
{
return logVars_.size() == 0;
return logVars_.empty();
}
@ -125,7 +125,7 @@ PrvGroup
ProbFormula::getNewGroup (void)
{
freeGroup_ ++;
assert (freeGroup_ != numeric_limits<PrvGroup>::max());
assert (freeGroup_ != std::numeric_limits<PrvGroup>::max());
return freeGroup_;
}

View File

@ -14,10 +14,11 @@ class ProbFormula
public:
ProbFormula (Symbol f, const LogVars& lvs, unsigned range)
: functor_(f), logVars_(lvs), range_(range),
countedLogVar_(), group_(numeric_limits<PrvGroup>::max()) { }
countedLogVar_(), group_(std::numeric_limits<PrvGroup>::max()) { }
ProbFormula (Symbol f, unsigned r)
: functor_(f), range_(r), group_(numeric_limits<PrvGroup>::max()) { }
: functor_(f), range_(r),
group_(std::numeric_limits<PrvGroup>::max()) { }
Symbol functor (void) const { return functor_; }

View File

@ -1,9 +1,10 @@
#ifndef HORUS_TINYSET_H
#define HORUS_TINYSET_H
#include <vector>
#include <algorithm>
#include <vector>
using namespace std;
@ -186,7 +187,7 @@ class TinySet
bool empty (void) const
{
return size() == 0;
return vec_.empty();
}
typename vector<T>::size_type size (void) const

View File

@ -1,6 +1,3 @@
#include <limits>
#include <sstream>
#include <fstream>
#include "Util.h"
@ -341,7 +338,7 @@ normalize (Params& v)
if (Globals::logDomain) {
double sum = std::accumulate (v.begin(), v.end(),
LogAware::addIdenty(), Util::logSum);
assert (sum != -numeric_limits<double>::infinity());
assert (sum != -std::numeric_limits<double>::infinity());
v -= sum;
} else {
double sum = std::accumulate (v.begin(), v.end(), 0.0);

View File

@ -3,16 +3,17 @@
#include <cmath>
#include <cassert>
#include <limits>
#include <algorithm>
#include <limits>
#include <vector>
#include <set>
#include <queue>
#include <set>
#include <unordered_map>
#include <sstream>
#include <iostream>
#include <sstream>
#include "Horus.h"
@ -20,7 +21,7 @@ using namespace std;
namespace {
const double NEG_INF = -numeric_limits<double>::infinity();
const double NEG_INF = -std::numeric_limits<double>::infinity();
};
@ -42,7 +43,8 @@ template <typename K, typename V> bool contains (
template <typename T> size_t indexOf (const vector<T>&, const T&);
template <class Operation>
void apply_n_times (Params& v1, const Params& v2, unsigned repetitions, Operation);
void apply_n_times (Params& v1, const Params& v2,
unsigned repetitions, Operation);
template <typename T> void log (vector<T>&);
@ -245,7 +247,7 @@ Util::logSum (double x, double y)
inline unsigned
Util::maxUnsigned (void)
{
return numeric_limits<unsigned>::max();
return std::numeric_limits<unsigned>::max();
}

View File

@ -1,10 +1,7 @@
#include <algorithm>
#include <sstream>
#include "Var.h"
using namespace std;
unordered_map<VarId, VarInfo> Var::varsInfo_;
@ -14,7 +11,7 @@ Var::Var (const Var* v)
varId_ = v->varId();
range_ = v->range();
evidence_ = v->getEvidence();
index_ = std::numeric_limits<unsigned>::max();
index_ = Util::maxUnsigned();
}
@ -26,7 +23,7 @@ Var::Var (VarId varId, unsigned range, int evidence)
varId_ = varId;
range_ = range;
evidence_ = evidence;
index_ = std::numeric_limits<unsigned>::max();
index_ = Util::maxUnsigned();
}

View File

@ -3,8 +3,6 @@
#include <cassert>
#include <iostream>
#include "Util.h"
#include "Horus.h"
@ -14,7 +12,8 @@ using namespace std;
struct VarInfo
{
VarInfo (string l, const States& sts) : label(l), states(sts) { }
VarInfo (string l, const States& sts)
: label(l), states(sts) { }
string label;
States states;
};
@ -55,8 +54,7 @@ class Var
bool operator!= (const Var& var) const
{
assert (!(varId_ == var.varId() && range_ != var.range()));
return varId_ != var.varId();
return !(*this == var);
}
bool isValidState (int);
@ -86,7 +84,7 @@ class Var
static bool varsHaveInfo (void)
{
return varsInfo_.size() != 0;
return varsInfo_.empty() == false;
}
static void clearVarsInfo (void)

View File

@ -18,7 +18,7 @@ WeightedBp::getPosterioriOf (VarId vid)
runSolver();
}
VarNode* var = fg.getVarNode (vid);
assert (var != 0);
assert (var);
Params probs;
if (var->hasEvidence()) {
probs.resize (var->range(), LogAware::noEvidence());