Exit is better than abort.
Also use a macro instead of integer to indicate failure.
This commit is contained in:
parent
2ca31ca14a
commit
053fa31bb2
@ -116,7 +116,7 @@ ElimGraph::exportToGraphViz (
|
||||
out << " [shape=box3d]" << endl;
|
||||
} else {
|
||||
cout << "error: invalid variable id: " << highlightVarIds[i] << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < nodes_.size(); i++) {
|
||||
|
@ -38,14 +38,14 @@ FactorGraph::readFromUaiFormat (const char* fileName)
|
||||
std::ifstream is (fileName);
|
||||
if (!is.is_open()) {
|
||||
cerr << "error: cannot read from file " << fileName << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
ignoreLines (is);
|
||||
string line;
|
||||
getline (is, line);
|
||||
if (line != "MARKOV") {
|
||||
cerr << "error: the network must be a MARKOV network " << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// read the number of vars
|
||||
ignoreLines (is);
|
||||
@ -74,7 +74,7 @@ FactorGraph::readFromUaiFormat (const char* fileName)
|
||||
cerr << "error: invalid variable identifier `" << vid << "'" << endl;
|
||||
cerr << "identifiers must be between 0 and " << ranges.size() - 1 ;
|
||||
cerr << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
factorVarIds.back().push_back (vid);
|
||||
factorRanges.back().push_back (ranges[vid]);
|
||||
@ -89,7 +89,7 @@ FactorGraph::readFromUaiFormat (const char* fileName)
|
||||
cerr << "error: invalid number of parameters for factor nº " << i ;
|
||||
cerr << ", expected: " << Util::sizeExpected (factorRanges[i]);
|
||||
cerr << ", given: " << nrParams << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
Params params (nrParams);
|
||||
for (unsigned j = 0; j < nrParams; j++) {
|
||||
@ -111,7 +111,7 @@ FactorGraph::readFromLibDaiFormat (const char* fileName)
|
||||
std::ifstream is (fileName);
|
||||
if (!is.is_open()) {
|
||||
cerr << "error: cannot read from file " << fileName << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
ignoreLines (is);
|
||||
unsigned nrFactors;
|
||||
|
@ -26,7 +26,7 @@ main (int argc, const char* argv[])
|
||||
if (argc <= 1) {
|
||||
cerr << "error: no graphical model specified" << endl;
|
||||
cerr << USAGE << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
int idx = readHorusFlags (argc, argv);
|
||||
FactorGraph fg;
|
||||
@ -53,12 +53,12 @@ readHorusFlags (int argc, const char* argv[])
|
||||
if (leftArg.empty()) {
|
||||
cerr << "error: missing left argument" << endl;
|
||||
cerr << USAGE << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (rightArg.empty()) {
|
||||
cerr << "error: missing right argument" << endl;
|
||||
cerr << USAGE << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
Util::setHorusFlag (leftArg, rightArg);
|
||||
}
|
||||
@ -79,7 +79,7 @@ readFactorGraph (FactorGraph& fg, const char* s)
|
||||
} else {
|
||||
cerr << "error: the graphical model must be defined either " ;
|
||||
cerr << "in a UAI or libDAI file" << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,14 +100,14 @@ readQueryAndEvidence (
|
||||
cerr << "error: `" << arg << "' " ;
|
||||
cerr << "is not a variable id" ;
|
||||
cerr << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
VarId vid = Util::stringToUnsigned (arg);
|
||||
VarNode* queryVar = fg.getVarNode (vid);
|
||||
if (queryVar == false) {
|
||||
cerr << "error: unknow variable with id " ;
|
||||
cerr << "`" << vid << "'" << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
queryIds.push_back (vid);
|
||||
} else {
|
||||
@ -117,37 +117,36 @@ readQueryAndEvidence (
|
||||
if (leftArg.empty()) {
|
||||
cerr << "error: missing left argument" << endl;
|
||||
cerr << USAGE << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (Util::isInteger (leftArg) == false) {
|
||||
cerr << "error: `" << leftArg << "' " ;
|
||||
cerr << "is not a variable id" << endl ;
|
||||
exit (0);
|
||||
continue;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
VarId vid = Util::stringToUnsigned (leftArg);
|
||||
VarNode* observedVar = fg.getVarNode (vid);
|
||||
if (observedVar == false) {
|
||||
cerr << "error: unknow variable with id " ;
|
||||
cerr << "`" << vid << "'" << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (rightArg.empty()) {
|
||||
cerr << "error: missing right argument" << endl;
|
||||
cerr << USAGE << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (Util::isInteger (rightArg) == false) {
|
||||
cerr << "error: `" << rightArg << "' " ;
|
||||
cerr << "is not a state index" << endl ;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
unsigned stateIdx = Util::stringToUnsigned (rightArg);
|
||||
if (observedVar->isValidState (stateIdx) == false) {
|
||||
cerr << "error: `" << stateIdx << "' " ;
|
||||
cerr << "is not a valid state index for variable with id " ;
|
||||
cerr << "`" << vid << "'" << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
observedVar->setEvidence (stateIdx);
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ readParfactor (YAP_Term pfTerm)
|
||||
YAP_Term ti = YAP_ArgOfTerm (i, term);
|
||||
if (YAP_IsAtomTerm (ti) == false) {
|
||||
cerr << "error: constraint has free variables" << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
string name ((char*) YAP_AtomName (YAP_AtomOfTerm (ti)));
|
||||
tuple[i - 1] = LiftedUtils::getSymbol (name);
|
||||
|
@ -23,7 +23,7 @@ LiftedKc::solveQuery (const Grounds& query)
|
||||
circuit_ = new LiftedCircuit (lwcnf_);
|
||||
if (circuit_->isCompilationSucceeded() == false) {
|
||||
cerr << "error: compilation failed" << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
vector<PrvGroup> groups;
|
||||
Ranges ranges;
|
||||
|
@ -37,7 +37,7 @@ LiftedOperations::shatterAgainstQuery (
|
||||
if (found == false) {
|
||||
cerr << "error: could not find a parfactor with ground " ;
|
||||
cerr << "`" << query[i] << "'" << endl;
|
||||
exit (0);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
pfList.add (newPfs);
|
||||
}
|
||||
|
@ -691,7 +691,7 @@ Parfactor::expandPotential (
|
||||
if (newSize > params_.max_size()) {
|
||||
cerr << "error: an overflow occurred when performing expansion" ;
|
||||
cerr << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Params backup = params_;
|
||||
|
@ -336,7 +336,7 @@ ParfactorList::shatterAgainstMySelf (
|
||||
if (f1.isAtom()) {
|
||||
cerr << "error: a ground occurs twice in a parfactor" << endl;
|
||||
cerr << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
assert (g->constr()->empty() == false);
|
||||
ConstraintTree ctCopy (*g->constr());
|
||||
|
@ -54,7 +54,7 @@ stringToUnsigned (string str)
|
||||
ss >> val;
|
||||
if (val < 0) {
|
||||
cerr << "error: the readed number is negative" << endl;
|
||||
abort();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
return static_cast<unsigned> (val);
|
||||
}
|
||||
|
Reference in New Issue
Block a user