diff --git a/packages/CLPBN/horus/BayesBall.cpp b/packages/CLPBN/horus/BayesBall.cpp index 0fac25056..da0c73ff5 100644 --- a/packages/CLPBN/horus/BayesBall.cpp +++ b/packages/CLPBN/horus/BayesBall.cpp @@ -1,12 +1,6 @@ -#include #include -#include -#include -#include - #include "BayesBall.h" -#include "Util.h" FactorGraph* diff --git a/packages/CLPBN/horus/BayesBallGraph.cpp b/packages/CLPBN/horus/BayesBallGraph.cpp index 36fcbb5ee..60db22bfe 100644 --- a/packages/CLPBN/horus/BayesBallGraph.cpp +++ b/packages/CLPBN/horus/BayesBallGraph.cpp @@ -2,8 +2,8 @@ #include #include -#include #include +#include #include "BayesBallGraph.h" #include "Util.h" diff --git a/packages/CLPBN/horus/BayesBallGraph.h b/packages/CLPBN/horus/BayesBallGraph.h index 68cd9effe..eb44f0ae8 100644 --- a/packages/CLPBN/horus/BayesBallGraph.h +++ b/packages/CLPBN/horus/BayesBallGraph.h @@ -2,9 +2,7 @@ #define HORUS_BAYESBALLGRAPH_H #include -#include -#include -#include +#include #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& childs (void) const { return childs_; } diff --git a/packages/CLPBN/horus/BeliefProp.cpp b/packages/CLPBN/horus/BeliefProp.cpp index f56752fe4..64195c91b 100644 --- a/packages/CLPBN/horus/BeliefProp.cpp +++ b/packages/CLPBN/horus/BeliefProp.cpp @@ -1,13 +1,10 @@ #include -#include #include #include #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) { diff --git a/packages/CLPBN/horus/BeliefProp.h b/packages/CLPBN/horus/BeliefProp.h index 87364355c..cfdf98cbb 100644 --- a/packages/CLPBN/horus/BeliefProp.h +++ b/packages/CLPBN/horus/BeliefProp.h @@ -3,12 +3,12 @@ #include #include + #include #include "GroundSolver.h" -#include "Factor.h" #include "FactorGraph.h" -#include "Util.h" + using namespace std; diff --git a/packages/CLPBN/horus/ConstraintTree.cpp b/packages/CLPBN/horus/ConstraintTree.cpp index 3a9fe7b5e..599d28f37 100644 --- a/packages/CLPBN/horus/ConstraintTree.cpp +++ b/packages/CLPBN/horus/ConstraintTree.cpp @@ -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++) { diff --git a/packages/CLPBN/horus/CountingBp.cpp b/packages/CLPBN/horus/CountingBp.cpp index b86d22f9f..a0836332f 100644 --- a/packages/CLPBN/horus/CountingBp.cpp +++ b/packages/CLPBN/horus/CountingBp.cpp @@ -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); } } diff --git a/packages/CLPBN/horus/CountingBp.h b/packages/CLPBN/horus/CountingBp.h index 2cbd2f995..c6487cdd0 100644 --- a/packages/CLPBN/horus/CountingBp.h +++ b/packages/CLPBN/horus/CountingBp.h @@ -5,7 +5,6 @@ #include "GroundSolver.h" #include "FactorGraph.h" -#include "Util.h" #include "Horus.h" class VarCluster; diff --git a/packages/CLPBN/horus/ElimGraph.cpp b/packages/CLPBN/horus/ElimGraph.cpp index 1942bfb85..0292c775f 100644 --- a/packages/CLPBN/horus/ElimGraph.cpp +++ b/packages/CLPBN/horus/ElimGraph.cpp @@ -1,5 +1,3 @@ -#include - #include #include "ElimGraph.h" @@ -10,30 +8,27 @@ ElimHeuristic ElimGraph::elimHeuristic = MIN_NEIGHBORS; ElimGraph::ElimGraph (const vector& 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::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]); } } diff --git a/packages/CLPBN/horus/ElimGraph.h b/packages/CLPBN/horus/ElimGraph.h index 8188b5ba6..575258829 100644 --- a/packages/CLPBN/horus/ElimGraph.h +++ b/packages/CLPBN/horus/ElimGraph.h @@ -7,7 +7,6 @@ #include "TinySet.h" #include "Horus.h" - using namespace std; enum ElimHeuristic diff --git a/packages/CLPBN/horus/Factor.cpp b/packages/CLPBN/horus/Factor.cpp index 9b8ad0be7..d0acade1f 100644 --- a/packages/CLPBN/horus/Factor.cpp +++ b/packages/CLPBN/horus/Factor.cpp @@ -7,7 +7,7 @@ #include #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::multiply (g); } - TFactor::multiply (g); } diff --git a/packages/CLPBN/horus/Factor.h b/packages/CLPBN/horus/Factor.h index dd004ee24..415a3d1df 100644 --- a/packages/CLPBN/horus/Factor.h +++ b/packages/CLPBN/horus/Factor.h @@ -3,7 +3,6 @@ #include -#include "Var.h" #include "Indexer.h" #include "Util.h" diff --git a/packages/CLPBN/horus/FactorGraph.cpp b/packages/CLPBN/horus/FactorGraph.cpp index df9dd7941..85925abf6 100644 --- a/packages/CLPBN/horus/FactorGraph.cpp +++ b/packages/CLPBN/horus/FactorGraph.cpp @@ -1,13 +1,13 @@ -#include -#include #include +#include +#include + #include -#include #include +#include #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; } diff --git a/packages/CLPBN/horus/FactorGraph.h b/packages/CLPBN/horus/FactorGraph.h index 960f799cc..3417acf38 100644 --- a/packages/CLPBN/horus/FactorGraph.h +++ b/packages/CLPBN/horus/FactorGraph.h @@ -9,7 +9,6 @@ using namespace std; - class FacNode; class VarNode : public Var diff --git a/packages/CLPBN/horus/GroundSolver.cpp b/packages/CLPBN/horus/GroundSolver.cpp index 4cd3fdbd2..b683c8233 100644 --- a/packages/CLPBN/horus/GroundSolver.cpp +++ b/packages/CLPBN/horus/GroundSolver.cpp @@ -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++) { diff --git a/packages/CLPBN/horus/GroundSolver.h b/packages/CLPBN/horus/GroundSolver.h index 18b81454b..ec6bf60c7 100644 --- a/packages/CLPBN/horus/GroundSolver.h +++ b/packages/CLPBN/horus/GroundSolver.h @@ -4,7 +4,6 @@ #include #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; diff --git a/packages/CLPBN/horus/Histogram.h b/packages/CLPBN/horus/Histogram.h index af0c4595e..c9bdd78e1 100644 --- a/packages/CLPBN/horus/Histogram.h +++ b/packages/CLPBN/horus/Histogram.h @@ -2,6 +2,7 @@ #define HORUS_HISTOGRAM_H #include + #include using namespace std; diff --git a/packages/CLPBN/horus/Horus.h b/packages/CLPBN/horus/Horus.h index 7e5f12c8e..960e7bb6a 100644 --- a/packages/CLPBN/horus/Horus.h +++ b/packages/CLPBN/horus/Horus.h @@ -1,8 +1,6 @@ #ifndef HORUS_HORUS_H #define HORUS_HORUS_H -#include - #include #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ diff --git a/packages/CLPBN/horus/LiftedBp.cpp b/packages/CLPBN/horus/LiftedBp.cpp index d3f757704..bdf761e4f 100644 --- a/packages/CLPBN/horus/LiftedBp.cpp +++ b/packages/CLPBN/horus/LiftedBp.cpp @@ -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::max(); + return Util::maxUnsigned(); } diff --git a/packages/CLPBN/horus/LiftedKc.cpp b/packages/CLPBN/horus/LiftedKc.cpp index 4dbd9e9ca..c366c282d 100644 --- a/packages/CLPBN/horus/LiftedKc.cpp +++ b/packages/CLPBN/horus/LiftedKc.cpp @@ -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(node) != 0) { + if (dynamic_cast(node)) { type = CircuitNodeType::OR_NODE; - } else if (dynamic_cast(node) != 0) { + } else if (dynamic_cast(node)) { type = CircuitNodeType::AND_NODE; - } else if (dynamic_cast(node) != 0) { + } else if (dynamic_cast(node)) { type = CircuitNodeType::SET_OR_NODE; - } else if (dynamic_cast(node) != 0) { + } else if (dynamic_cast(node)) { type = CircuitNodeType::SET_AND_NODE; - } else if (dynamic_cast(node) != 0) { + } else if (dynamic_cast(node)) { type = CircuitNodeType::INC_EXC_NODE; - } else if (dynamic_cast(node) != 0) { + } else if (dynamic_cast(node)) { type = CircuitNodeType::LEAF_NODE; - } else if (dynamic_cast(node) != 0) { + } else if (dynamic_cast(node)) { type = CircuitNodeType::SMOOTH_NODE; - } else if (dynamic_cast(node) != 0) { + } else if (dynamic_cast(node)) { type = CircuitNodeType::TRUE_NODE; - } else if (dynamic_cast(node) != 0) { + } else if (dynamic_cast(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; diff --git a/packages/CLPBN/horus/LiftedKc.h b/packages/CLPBN/horus/LiftedKc.h index a4cd2dbeb..6dc4440ea 100644 --- a/packages/CLPBN/horus/LiftedKc.h +++ b/packages/CLPBN/horus/LiftedKc.h @@ -1,9 +1,8 @@ #ifndef HORUS_LIFTEDKC_H #define HORUS_LIFTEDKC_H - -#include "LiftedWCNF.h" #include "LiftedSolver.h" +#include "LiftedWCNF.h" #include "ParfactorList.h" diff --git a/packages/CLPBN/horus/LiftedOperations.cpp b/packages/CLPBN/horus/LiftedOperations.cpp index 986a22c03..6ccc41b3b 100644 --- a/packages/CLPBN/horus/LiftedOperations.cpp +++ b/packages/CLPBN/horus/LiftedOperations.cpp @@ -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::max()) { + if (group != std::numeric_limits::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); diff --git a/packages/CLPBN/horus/LiftedUtils.cpp b/packages/CLPBN/horus/LiftedUtils.cpp index 0233a8554..b85990ec1 100644 --- a/packages/CLPBN/horus/LiftedUtils.cpp +++ b/packages/CLPBN/horus/LiftedUtils.cpp @@ -1,6 +1,5 @@ #include -#include #include #include diff --git a/packages/CLPBN/horus/LiftedUtils.h b/packages/CLPBN/horus/LiftedUtils.h index de0782f1c..70e0d1071 100644 --- a/packages/CLPBN/horus/LiftedUtils.h +++ b/packages/CLPBN/horus/LiftedUtils.h @@ -1,12 +1,11 @@ #ifndef HORUS_LIFTEDUTILS_H #define HORUS_LIFTEDUTILS_H -#include #include + #include #include - #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); diff --git a/packages/CLPBN/horus/LiftedVe.cpp b/packages/CLPBN/horus/LiftedVe.cpp index bcce3e100..5c4c7464e 100644 --- a/packages/CLPBN/horus/LiftedVe.cpp +++ b/packages/CLPBN/horus/LiftedVe.cpp @@ -1,4 +1,5 @@ #include + #include #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; } diff --git a/packages/CLPBN/horus/LiftedWCNF.cpp b/packages/CLPBN/horus/LiftedWCNF.cpp index a75741fa8..682dddd6d 100644 --- a/packages/CLPBN/horus/LiftedWCNF.cpp +++ b/packages/CLPBN/horus/LiftedWCNF.cpp @@ -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_); diff --git a/packages/CLPBN/horus/LiftedWCNF.h b/packages/CLPBN/horus/LiftedWCNF.h index e0f901b7c..2aed7a6cf 100644 --- a/packages/CLPBN/horus/LiftedWCNF.h +++ b/packages/CLPBN/horus/LiftedWCNF.h @@ -1,15 +1,14 @@ #ifndef HORUS_LIFTEDWCNF_H #define HORUS_LIFTEDWCNF_H +#include + #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 LogVarTypes; - +typedef long LiteralId; +typedef vector LogVarTypes; class Literal diff --git a/packages/CLPBN/horus/Parfactor.cpp b/packages/CLPBN/horus/Parfactor.cpp index fb5518d1b..bc326801b 100644 --- a/packages/CLPBN/horus/Parfactor.cpp +++ b/packages/CLPBN/horus/Parfactor.cpp @@ -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::max() + ? std::numeric_limits::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::max(); + return findGroup (ground) != std::numeric_limits::max(); } diff --git a/packages/CLPBN/horus/Parfactor.h b/packages/CLPBN/horus/Parfactor.h index 2f4b45cd7..6cd04b23c 100644 --- a/packages/CLPBN/horus/Parfactor.h +++ b/packages/CLPBN/horus/Parfactor.h @@ -1,15 +1,12 @@ #ifndef HORUS_PARFACTOR_H #define HORUS_PARFACTOR_H -#include -#include - +#include "Factor.h" #include "ProbFormula.h" #include "ConstraintTree.h" #include "LiftedUtils.h" #include "Horus.h" -#include "Factor.h" class Parfactor : public TFactor { diff --git a/packages/CLPBN/horus/ParfactorList.cpp b/packages/CLPBN/horus/ParfactorList.cpp index 2962f144e..3481696de 100644 --- a/packages/CLPBN/horus/ParfactorList.cpp +++ b/packages/CLPBN/horus/ParfactorList.cpp @@ -1,5 +1,7 @@ #include +#include + #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])) { diff --git a/packages/CLPBN/horus/ParfactorList.h b/packages/CLPBN/horus/ParfactorList.h index 1c6404dcb..377299952 100644 --- a/packages/CLPBN/horus/ParfactorList.h +++ b/packages/CLPBN/horus/ParfactorList.h @@ -2,7 +2,6 @@ #define HORUS_PARFACTORLIST_H #include -#include #include "Parfactor.h" #include "ProbFormula.h" @@ -11,6 +10,8 @@ using namespace std; +class Parfactor; + class ParfactorList { public: diff --git a/packages/CLPBN/horus/ProbFormula.cpp b/packages/CLPBN/horus/ProbFormula.cpp index 081cccf95..67473734c 100644 --- a/packages/CLPBN/horus/ProbFormula.cpp +++ b/packages/CLPBN/horus/ProbFormula.cpp @@ -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::max()); + assert (freeGroup_ != std::numeric_limits::max()); return freeGroup_; } diff --git a/packages/CLPBN/horus/ProbFormula.h b/packages/CLPBN/horus/ProbFormula.h index 52bc7d4a0..48824b5db 100644 --- a/packages/CLPBN/horus/ProbFormula.h +++ b/packages/CLPBN/horus/ProbFormula.h @@ -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::max()) { } + countedLogVar_(), group_(std::numeric_limits::max()) { } ProbFormula (Symbol f, unsigned r) - : functor_(f), range_(r), group_(numeric_limits::max()) { } + : functor_(f), range_(r), + group_(std::numeric_limits::max()) { } Symbol functor (void) const { return functor_; } diff --git a/packages/CLPBN/horus/TinySet.h b/packages/CLPBN/horus/TinySet.h index f7ff6e083..f307e4530 100644 --- a/packages/CLPBN/horus/TinySet.h +++ b/packages/CLPBN/horus/TinySet.h @@ -1,9 +1,10 @@ #ifndef HORUS_TINYSET_H #define HORUS_TINYSET_H -#include #include +#include + using namespace std; @@ -186,7 +187,7 @@ class TinySet bool empty (void) const { - return size() == 0; + return vec_.empty(); } typename vector::size_type size (void) const diff --git a/packages/CLPBN/horus/Util.cpp b/packages/CLPBN/horus/Util.cpp index 6afd56f43..4258908d0 100644 --- a/packages/CLPBN/horus/Util.cpp +++ b/packages/CLPBN/horus/Util.cpp @@ -1,6 +1,3 @@ -#include - -#include #include #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::infinity()); + assert (sum != -std::numeric_limits::infinity()); v -= sum; } else { double sum = std::accumulate (v.begin(), v.end(), 0.0); diff --git a/packages/CLPBN/horus/Util.h b/packages/CLPBN/horus/Util.h index 1a4bfa441..f73651013 100644 --- a/packages/CLPBN/horus/Util.h +++ b/packages/CLPBN/horus/Util.h @@ -3,16 +3,17 @@ #include #include -#include #include +#include + #include -#include #include +#include #include -#include #include +#include #include "Horus.h" @@ -20,7 +21,7 @@ using namespace std; namespace { -const double NEG_INF = -numeric_limits::infinity(); +const double NEG_INF = -std::numeric_limits::infinity(); }; @@ -42,7 +43,8 @@ template bool contains ( template size_t indexOf (const vector&, const T&); template -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 void log (vector&); @@ -245,7 +247,7 @@ Util::logSum (double x, double y) inline unsigned Util::maxUnsigned (void) { - return numeric_limits::max(); + return std::numeric_limits::max(); } diff --git a/packages/CLPBN/horus/Var.cpp b/packages/CLPBN/horus/Var.cpp index 80fc0abe6..f84257585 100644 --- a/packages/CLPBN/horus/Var.cpp +++ b/packages/CLPBN/horus/Var.cpp @@ -1,10 +1,7 @@ -#include #include #include "Var.h" -using namespace std; - unordered_map Var::varsInfo_; @@ -14,7 +11,7 @@ Var::Var (const Var* v) varId_ = v->varId(); range_ = v->range(); evidence_ = v->getEvidence(); - index_ = std::numeric_limits::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::max(); + index_ = Util::maxUnsigned(); } diff --git a/packages/CLPBN/horus/Var.h b/packages/CLPBN/horus/Var.h index 8ab580c3a..d1b3461ac 100644 --- a/packages/CLPBN/horus/Var.h +++ b/packages/CLPBN/horus/Var.h @@ -3,8 +3,6 @@ #include -#include - #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) diff --git a/packages/CLPBN/horus/WeightedBp.cpp b/packages/CLPBN/horus/WeightedBp.cpp index 8416c4592..9f6fca8df 100644 --- a/packages/CLPBN/horus/WeightedBp.cpp +++ b/packages/CLPBN/horus/WeightedBp.cpp @@ -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());