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 <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include "BayesBall.h" #include "BayesBall.h"
#include "Util.h"
FactorGraph* FactorGraph*

View File

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

View File

@ -2,9 +2,7 @@
#define HORUS_BAYESBALLGRAPH_H #define HORUS_BAYESBALLGRAPH_H
#include <vector> #include <vector>
#include <queue> #include <unordered_map>
#include <list>
#include <map>
#include "Var.h" #include "Var.h"
#include "Horus.h" #include "Horus.h"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,3 @@
#include "Parfactor.h" #include "Parfactor.h"
#include "Histogram.h" #include "Histogram.h"
#include "Indexer.h" #include "Indexer.h"
@ -443,7 +442,7 @@ Parfactor::findGroup (const Ground& ground) const
{ {
size_t idx = indexOfGround (ground); size_t idx = indexOfGround (ground);
return idx == args_.size() return idx == args_.size()
? numeric_limits<PrvGroup>::max() ? std::numeric_limits<PrvGroup>::max()
: args_[idx].group(); : args_[idx].group();
} }
@ -452,7 +451,7 @@ Parfactor::findGroup (const Ground& ground) const
bool bool
Parfactor::containsGround (const Ground& ground) const 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 #ifndef HORUS_PARFACTOR_H
#define HORUS_PARFACTOR_H #define HORUS_PARFACTOR_H
#include <list> #include "Factor.h"
#include <unordered_map>
#include "ProbFormula.h" #include "ProbFormula.h"
#include "ConstraintTree.h" #include "ConstraintTree.h"
#include "LiftedUtils.h" #include "LiftedUtils.h"
#include "Horus.h" #include "Horus.h"
#include "Factor.h"
class Parfactor : public TFactor<ProbFormula> class Parfactor : public TFactor<ProbFormula>
{ {

View File

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

View File

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

View File

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

View File

@ -14,10 +14,11 @@ class ProbFormula
public: public:
ProbFormula (Symbol f, const LogVars& lvs, unsigned range) ProbFormula (Symbol f, const LogVars& lvs, unsigned range)
: functor_(f), logVars_(lvs), range_(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) 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_; } Symbol functor (void) const { return functor_; }

View File

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

View File

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

View File

@ -3,16 +3,17 @@
#include <cmath> #include <cmath>
#include <cassert> #include <cassert>
#include <limits>
#include <algorithm> #include <algorithm>
#include <limits>
#include <vector> #include <vector>
#include <set>
#include <queue> #include <queue>
#include <set>
#include <unordered_map> #include <unordered_map>
#include <sstream>
#include <iostream> #include <iostream>
#include <sstream>
#include "Horus.h" #include "Horus.h"
@ -20,7 +21,7 @@ using namespace std;
namespace { 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 <typename T> size_t indexOf (const vector<T>&, const T&);
template <class Operation> 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>&); template <typename T> void log (vector<T>&);
@ -245,7 +247,7 @@ Util::logSum (double x, double y)
inline unsigned inline unsigned
Util::maxUnsigned (void) 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 <sstream>
#include "Var.h" #include "Var.h"
using namespace std;
unordered_map<VarId, VarInfo> Var::varsInfo_; unordered_map<VarId, VarInfo> Var::varsInfo_;
@ -14,7 +11,7 @@ Var::Var (const Var* v)
varId_ = v->varId(); varId_ = v->varId();
range_ = v->range(); range_ = v->range();
evidence_ = v->getEvidence(); 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; varId_ = varId;
range_ = range; range_ = range;
evidence_ = evidence; evidence_ = evidence;
index_ = std::numeric_limits<unsigned>::max(); index_ = Util::maxUnsigned();
} }

View File

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

View File

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