kill Util::abort, s/vectorIndex/indexOf and s/isCarteesianProduct/isCartesianProduct
This commit is contained in:
parent
db0d2c9772
commit
f7ba86d3ed
@ -242,11 +242,9 @@ void
|
|||||||
ConstraintTree::moveToTop (const LogVars& lvs)
|
ConstraintTree::moveToTop (const LogVars& lvs)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < lvs.size(); i++) {
|
for (unsigned i = 0; i < lvs.size(); i++) {
|
||||||
LogVars::iterator it =
|
int pos = Util::indexOf (logVars_, lvs[i]);
|
||||||
std::find (logVars_.begin(), logVars_.end(), lvs[i]);
|
assert (pos != -1);
|
||||||
assert (it != logVars_.end());
|
for (int j = pos; j > (int)i; j--) {
|
||||||
unsigned pos = std::distance (logVars_.begin(), it);
|
|
||||||
for (unsigned j = pos; j > i; j--) {
|
|
||||||
swapLogVar (logVars_[j-1]);
|
swapLogVar (logVars_[j-1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,9 +259,9 @@ ConstraintTree::moveToBottom (const LogVars& lvs)
|
|||||||
LogVars::iterator it =
|
LogVars::iterator it =
|
||||||
std::find (logVars_.begin(), logVars_.end(), lvs[i]);
|
std::find (logVars_.begin(), logVars_.end(), lvs[i]);
|
||||||
assert (it != logVars_.end());
|
assert (it != logVars_.end());
|
||||||
unsigned pos = std::distance (logVars_.begin(), it);
|
int pos = Util::indexOf (logVars_, lvs[i]);
|
||||||
unsigned stop = logVars_.size() - (lvs.size() - i - 1);
|
int stop = logVars_.size() - (lvs.size() - i - 1);
|
||||||
for (unsigned j = pos; j < stop - 1; j++) {
|
for (int j = pos; j < stop - 1; j++) {
|
||||||
swapLogVar (logVars_[j]);
|
swapLogVar (logVars_[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -328,10 +326,7 @@ ConstraintTree::join (ConstraintTree* ct, bool oneTwoOne)
|
|||||||
unsigned
|
unsigned
|
||||||
ConstraintTree::getLevel (LogVar X) const
|
ConstraintTree::getLevel (LogVar X) const
|
||||||
{
|
{
|
||||||
LogVars::const_iterator it =
|
unsigned level = Util::indexOf (logVars_, X);
|
||||||
std::find (logVars_.begin(), logVars_.end(), X);
|
|
||||||
assert (it != logVars_.end());
|
|
||||||
unsigned level = std::distance (logVars_.begin(), it);
|
|
||||||
level += 1; // root is in level 0, first logVar is in level 1
|
level += 1; // root is in level 0, first logVar is in level 1
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
@ -471,7 +466,7 @@ ConstraintTree::tupleSet (const LogVars& originalLvs)
|
|||||||
vector<int> indexes;
|
vector<int> indexes;
|
||||||
indexes.reserve (originalLvs.size());
|
indexes.reserve (originalLvs.size());
|
||||||
for (unsigned i = 0; i < originalLvs.size(); i++) {
|
for (unsigned i = 0; i < originalLvs.size(); i++) {
|
||||||
indexes.push_back (Util::vectorIndex (uniqueLvs, originalLvs[i]));
|
indexes.push_back (Util::indexOf (uniqueLvs, originalLvs[i]));
|
||||||
}
|
}
|
||||||
Tuples tuples2;
|
Tuples tuples2;
|
||||||
tuples2.reserve (tuples.size());
|
tuples2.reserve (tuples.size());
|
||||||
@ -618,7 +613,7 @@ ConstraintTree::getConditionalCounts (const LogVarSet& Ys)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ConstraintTree::isCarteesianProduct (const LogVarSet& Xs)
|
ConstraintTree::isCartesianProduct (const LogVarSet& Xs)
|
||||||
{
|
{
|
||||||
assert (logVarSet_.contains (Xs));
|
assert (logVarSet_.contains (Xs));
|
||||||
if (Xs.size() <= 1) {
|
if (Xs.size() <= 1) {
|
||||||
@ -979,10 +974,8 @@ ConstraintTree::appendOnBottom (CTNode* n, const CTChilds& childs)
|
|||||||
void
|
void
|
||||||
ConstraintTree::swapLogVar (LogVar X)
|
ConstraintTree::swapLogVar (LogVar X)
|
||||||
{
|
{
|
||||||
LogVars::iterator it;
|
int pos = Util::indexOf (logVars_, X);
|
||||||
it = std::find (logVars_.begin(),logVars_.end(), X);
|
assert (pos != -1);
|
||||||
assert (it != logVars_.end());
|
|
||||||
unsigned pos = std::distance (logVars_.begin(), it);
|
|
||||||
const CTNodes& nodes = getNodesAtLevel (pos);
|
const CTNodes& nodes = getNodesAtLevel (pos);
|
||||||
for (CTNodes::const_iterator nodeIt = nodes.begin();
|
for (CTNodes::const_iterator nodeIt = nodes.begin();
|
||||||
nodeIt != nodes.end(); ++ nodeIt) {
|
nodeIt != nodes.end(); ++ nodeIt) {
|
||||||
|
@ -185,7 +185,7 @@ class ConstraintTree
|
|||||||
|
|
||||||
TinySet<unsigned> getConditionalCounts (const LogVarSet&);
|
TinySet<unsigned> getConditionalCounts (const LogVarSet&);
|
||||||
|
|
||||||
bool isCarteesianProduct (const LogVarSet&);
|
bool isCartesianProduct (const LogVarSet&);
|
||||||
|
|
||||||
std::pair<ConstraintTree*, ConstraintTree*> split (const Tuple&);
|
std::pair<ConstraintTree*, ConstraintTree*> split (const Tuple&);
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ CountingOperator::getLogCost (void)
|
|||||||
cost += size * HistogramSet::nrHistograms (counts[i], range);
|
cost += size * HistogramSet::nrHistograms (counts[i], range);
|
||||||
}
|
}
|
||||||
unsigned group = (*pfIter_)->argument (fIdx).group();
|
unsigned group = (*pfIter_)->argument (fIdx).group();
|
||||||
int lvIndex = Util::vectorIndex (
|
int lvIndex = Util::indexOf (
|
||||||
(*pfIter_)->argument (fIdx).logVars(), X_);
|
(*pfIter_)->argument (fIdx).logVars(), X_);
|
||||||
assert (lvIndex != -1);
|
assert (lvIndex != -1);
|
||||||
ParfactorList::iterator pfIter = pfList_.begin();
|
ParfactorList::iterator pfIter = pfList_.begin();
|
||||||
@ -379,7 +379,7 @@ CountingOperator::apply (void)
|
|||||||
Parfactors pfs = FoveSolver::countNormalize (pf, X_);
|
Parfactors pfs = FoveSolver::countNormalize (pf, X_);
|
||||||
for (unsigned i = 0; i < pfs.size(); i++) {
|
for (unsigned i = 0; i < pfs.size(); i++) {
|
||||||
unsigned condCount = pfs[i]->constr()->getConditionalCount (X_);
|
unsigned condCount = pfs[i]->constr()->getConditionalCount (X_);
|
||||||
bool cartProduct = pfs[i]->constr()->isCarteesianProduct (
|
bool cartProduct = pfs[i]->constr()->isCartesianProduct (
|
||||||
pfs[i]->countedLogVars() | X_);
|
pfs[i]->countedLogVars() | X_);
|
||||||
if (condCount > 1 && cartProduct) {
|
if (condCount > 1 && cartProduct) {
|
||||||
pfs[i]->countConvert (X_);
|
pfs[i]->countConvert (X_);
|
||||||
|
@ -194,7 +194,7 @@ Parfactor::multiply (Parfactor& g)
|
|||||||
TFactor<ProbFormula>::multiply (g);
|
TFactor<ProbFormula>::multiply (g);
|
||||||
constr_->join (g.constr(), true);
|
constr_->join (g.constr(), true);
|
||||||
simplifyGrounds();
|
simplifyGrounds();
|
||||||
assert (constr_->isCarteesianProduct (countedLogVars()));
|
assert (constr_->isCartesianProduct (countedLogVars()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ Parfactor::canCountConvert (LogVar X)
|
|||||||
if (constr_->getConditionalCount (X) == 1) {
|
if (constr_->getConditionalCount (X) == 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (constr_->isCarteesianProduct (countedLogVars() | X) == false) {
|
if (constr_->isCartesianProduct (countedLogVars() | X) == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -32,13 +32,7 @@ ProbFormula::contains (LogVarSet s) const
|
|||||||
int
|
int
|
||||||
ProbFormula::indexOf (LogVar X) const
|
ProbFormula::indexOf (LogVar X) const
|
||||||
{
|
{
|
||||||
int pos = std::distance (
|
return Util::indexOf (logVars_, X);
|
||||||
logVars_.begin(),
|
|
||||||
std::find (logVars_.begin(), logVars_.end(), X));
|
|
||||||
if (pos == (int)logVars_.size()) {
|
|
||||||
pos = -1;
|
|
||||||
}
|
|
||||||
return pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +55,10 @@ stringToUnsigned (string str)
|
|||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss << str;
|
ss << str;
|
||||||
ss >> val;
|
ss >> val;
|
||||||
abort ("error: the value tried to read is negative", val < 0);
|
if (val < 0) {
|
||||||
|
cerr << "error: the readed number is negative" << endl;
|
||||||
|
abort();
|
||||||
|
}
|
||||||
return static_cast<unsigned> (val);
|
return static_cast<unsigned> (val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,17 +297,6 @@ setHorusFlag (string key, string value)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
abort (string msg, bool b)
|
|
||||||
{
|
|
||||||
if (b) {
|
|
||||||
cerr << msg << endl;
|
|
||||||
std::abort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
printHeader (string header, std::ostream& os)
|
printHeader (string header, std::ostream& os)
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,7 @@ template <typename T> bool contains (const set<T>&, const T&);
|
|||||||
template <typename K, typename V> bool contains (
|
template <typename K, typename V> bool contains (
|
||||||
const unordered_map<K, V>&, const K&);
|
const unordered_map<K, V>&, const K&);
|
||||||
|
|
||||||
template <typename T> int vectorIndex (const vector<T>&, const T&);
|
template <typename T> int indexOf (const vector<T>&, const T&);
|
||||||
|
|
||||||
template <typename T> std::string toString (const T&);
|
template <typename T> std::string toString (const T&);
|
||||||
|
|
||||||
@ -78,8 +78,6 @@ vector<string> getStateLines (const Vars&);
|
|||||||
|
|
||||||
bool setHorusFlag (string key, string value);
|
bool setHorusFlag (string key, string value);
|
||||||
|
|
||||||
void abort (string msg, bool = true);
|
|
||||||
|
|
||||||
void printHeader (string, std::ostream& os = std::cout);
|
void printHeader (string, std::ostream& os = std::cout);
|
||||||
|
|
||||||
void printSubHeader (string, std::ostream& os = std::cout);
|
void printSubHeader (string, std::ostream& os = std::cout);
|
||||||
@ -143,10 +141,10 @@ Util::contains (const unordered_map<K, V>& m, const K& k)
|
|||||||
|
|
||||||
|
|
||||||
template <typename T> int
|
template <typename T> int
|
||||||
Util::vectorIndex (const vector<T>& v, const T& e)
|
Util::indexOf (const vector<T>& v, const T& e)
|
||||||
{
|
{
|
||||||
int pos = std::distance (v.begin(),
|
int pos = std::distance (v.begin(),
|
||||||
std::find (v.begin(), v.end(), e));
|
std::find (v.begin(), v.end(), e));
|
||||||
if (pos == (int)v.size()) {
|
if (pos == (int)v.size()) {
|
||||||
pos = -1;
|
pos = -1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user