Improve the error messages
This commit is contained in:
parent
685f46dc27
commit
b44ed7db39
@ -79,8 +79,7 @@ BayesBallGraph::exportToGraphViz (const char* fileName)
|
||||
{
|
||||
ofstream out (fileName);
|
||||
if (!out.is_open()) {
|
||||
cerr << "error: cannot open file to write at " ;
|
||||
cerr << "BayesBallGraph::exportToDotFile()" << endl;
|
||||
cerr << "Error: couldn't open file '" << fileName << "'." ;
|
||||
return;
|
||||
}
|
||||
out << "digraph {" << endl;
|
||||
|
@ -521,8 +521,7 @@ ConstraintTree::exportToGraphViz (
|
||||
{
|
||||
ofstream out (fileName);
|
||||
if (!out.is_open()) {
|
||||
cerr << "error: cannot open file to write at " ;
|
||||
cerr << "ConstraintTree::exportToDotFile()" << endl;
|
||||
cerr << "Error: couldn't open file '" << fileName << "'." ;
|
||||
return;
|
||||
}
|
||||
out << "digraph {" << endl;
|
||||
|
@ -99,8 +99,7 @@ ElimGraph::exportToGraphViz (
|
||||
{
|
||||
ofstream out (fileName);
|
||||
if (!out.is_open()) {
|
||||
cerr << "error: cannot open file to write at " ;
|
||||
cerr << "ElimGraph::exportToDotFile()" << endl;
|
||||
cerr << "Error: couldn't open file '" << fileName << "'." ;
|
||||
return;
|
||||
}
|
||||
out << "strict graph {" << endl;
|
||||
@ -115,7 +114,8 @@ ElimGraph::exportToGraphViz (
|
||||
out << '"' << node->label() << '"' ;
|
||||
out << " [shape=box3d]" << endl;
|
||||
} else {
|
||||
cerr << "error: invalid variable id: " << highlightVarIds[i] << endl;
|
||||
cerr << "Error: invalid variable id: " << highlightVarIds[i] << "." ;
|
||||
cerr << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
@ -37,14 +37,14 @@ FactorGraph::readFromUaiFormat (const char* fileName)
|
||||
{
|
||||
std::ifstream is (fileName);
|
||||
if (!is.is_open()) {
|
||||
cerr << "error: cannot read from file " << fileName << endl;
|
||||
cerr << "Error: couldn't open file '" << fileName << "'." ;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
ignoreLines (is);
|
||||
string line;
|
||||
getline (is, line);
|
||||
if (line != "MARKOV") {
|
||||
cerr << "error: the network must be a MARKOV network " << endl;
|
||||
cerr << "Error: the network must be a MARKOV network." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// read the number of vars
|
||||
@ -71,9 +71,9 @@ FactorGraph::readFromUaiFormat (const char* fileName)
|
||||
for (unsigned j = 0; j < nrArgs; j++) {
|
||||
is >> vid;
|
||||
if (vid >= ranges.size()) {
|
||||
cerr << "error: invalid variable identifier `" << vid << "'" << endl;
|
||||
cerr << "identifiers must be between 0 and " << ranges.size() - 1 ;
|
||||
cerr << endl;
|
||||
cerr << "Error: invalid variable identifier `" << vid << "'. " ;
|
||||
cerr << "Identifiers must be between 0 and " << ranges.size() - 1 ;
|
||||
cerr << "." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
factorVarIds.back().push_back (vid);
|
||||
@ -86,9 +86,9 @@ FactorGraph::readFromUaiFormat (const char* fileName)
|
||||
ignoreLines (is);
|
||||
is >> nrParams;
|
||||
if (nrParams != Util::sizeExpected (factorRanges[i])) {
|
||||
cerr << "error: invalid number of parameters for factor nº " << i ;
|
||||
cerr << ", expected: " << Util::sizeExpected (factorRanges[i]);
|
||||
cerr << ", given: " << nrParams << endl;
|
||||
cerr << "Error: invalid number of parameters for factor nº " << i ;
|
||||
cerr << ", " << Util::sizeExpected (factorRanges[i]);
|
||||
cerr << " expected, " << nrParams << " given." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
Params params (nrParams);
|
||||
@ -110,7 +110,7 @@ FactorGraph::readFromLibDaiFormat (const char* fileName)
|
||||
{
|
||||
std::ifstream is (fileName);
|
||||
if (!is.is_open()) {
|
||||
cerr << "error: cannot read from file " << fileName << endl;
|
||||
cerr << "Error: couldn't open file '" << fileName << "'." ;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
ignoreLines (is);
|
||||
@ -135,8 +135,8 @@ FactorGraph::readFromLibDaiFormat (const char* fileName)
|
||||
is >> ranges[j];
|
||||
VarNode* var = getVarNode (vids[j]);
|
||||
if (var != 0 && ranges[j] != var->range()) {
|
||||
cerr << "error: variable `" << vids[j] << "' appears in two or " ;
|
||||
cerr << "more factors with a different range" << endl;
|
||||
cerr << "Error: variable `" << vids[j] << "' appears in two or " ;
|
||||
cerr << "more factors with a different range." << endl;
|
||||
}
|
||||
}
|
||||
// read parameters
|
||||
@ -281,8 +281,7 @@ FactorGraph::exportToGraphViz (const char* fileName) const
|
||||
{
|
||||
ofstream out (fileName);
|
||||
if (!out.is_open()) {
|
||||
cerr << "error: cannot open file to write at " ;
|
||||
cerr << "FactorGraph::exportToDotFile()" << endl;
|
||||
cerr << "Error: couldn't open file '" << fileName << "'." ;
|
||||
return;
|
||||
}
|
||||
out << "graph \"" << fileName << "\" {" << endl;
|
||||
@ -316,8 +315,7 @@ FactorGraph::exportToUaiFormat (const char* fileName) const
|
||||
{
|
||||
ofstream out (fileName);
|
||||
if (!out.is_open()) {
|
||||
cerr << "error: cannot open file to write at " ;
|
||||
cerr << "ConstraintTree::exportToUaiFormat()" << endl;
|
||||
cerr << "Error: couldn't open file '" << fileName << "'." ;
|
||||
return;
|
||||
}
|
||||
out << "MARKOV" << endl;
|
||||
@ -351,8 +349,7 @@ FactorGraph::exportToLibDaiFormat (const char* fileName) const
|
||||
{
|
||||
ofstream out (fileName);
|
||||
if (!out.is_open()) {
|
||||
cerr << "error: cannot open file to write at " ;
|
||||
cerr << "ConstraintTree::exportToUaiFormat()" << endl;
|
||||
cerr << "Error: couldn't open file '" << fileName << "'." ;
|
||||
return;
|
||||
}
|
||||
out << facNodes_.size() << endl << endl;
|
||||
|
@ -17,14 +17,14 @@ VarIds readQueryAndEvidence (FactorGraph&, int, const char* [], int);
|
||||
void runSolver (const FactorGraph&, const VarIds&);
|
||||
|
||||
const string USAGE = "usage: ./hcli [HORUS_FLAG=VALUE] \
|
||||
NETWORK_FILE [VARIABLE | OBSERVED_VARIABLE=EVIDENCE] ..." ;
|
||||
MODEL_FILE [VARIABLE | OBSERVED_VARIABLE=EVIDENCE] ..." ;
|
||||
|
||||
|
||||
int
|
||||
main (int argc, const char* argv[])
|
||||
{
|
||||
if (argc <= 1) {
|
||||
cerr << "error: no graphical model specified" << endl;
|
||||
cerr << "Error: no probabilistic graphical model was given." << endl;
|
||||
cerr << USAGE << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
@ -51,12 +51,12 @@ readHorusFlags (int argc, const char* argv[])
|
||||
string leftArg = arg.substr (0, pos);
|
||||
string rightArg = arg.substr (pos + 1);
|
||||
if (leftArg.empty()) {
|
||||
cerr << "error: missing left argument" << endl;
|
||||
cerr << "Error: missing left argument." << endl;
|
||||
cerr << USAGE << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (rightArg.empty()) {
|
||||
cerr << "error: missing right argument" << endl;
|
||||
cerr << "Error: missing right argument." << endl;
|
||||
cerr << USAGE << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
@ -77,8 +77,8 @@ readFactorGraph (FactorGraph& fg, const char* s)
|
||||
} else if (extension == "fg") {
|
||||
fg.readFromLibDaiFormat (fileName.c_str());
|
||||
} else {
|
||||
cerr << "error: the graphical model must be defined either " ;
|
||||
cerr << "in a UAI or libDAI file" << endl;
|
||||
cerr << "Error: the probabilistic graphical model must be " ;
|
||||
cerr << "defined either in a UAI or libDAI file." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -97,16 +97,16 @@ readQueryAndEvidence (
|
||||
const string& arg = argv[i];
|
||||
if (arg.find ('=') == std::string::npos) {
|
||||
if (Util::isInteger (arg) == false) {
|
||||
cerr << "error: `" << arg << "' " ;
|
||||
cerr << "is not a variable id" ;
|
||||
cerr << "Error: `" << arg << "' " ;
|
||||
cerr << "is not a variable id." ;
|
||||
cerr << endl;
|
||||
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;
|
||||
cerr << "Error: unknow variable with id " ;
|
||||
cerr << "`" << vid << "'." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
queryIds.push_back (vid);
|
||||
@ -115,37 +115,37 @@ readQueryAndEvidence (
|
||||
string leftArg = arg.substr (0, pos);
|
||||
string rightArg = arg.substr (pos + 1);
|
||||
if (leftArg.empty()) {
|
||||
cerr << "error: missing left argument" << endl;
|
||||
cerr << "Error: missing left argument." << endl;
|
||||
cerr << USAGE << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (Util::isInteger (leftArg) == false) {
|
||||
cerr << "error: `" << leftArg << "' " ;
|
||||
cerr << "is not a variable id" << endl ;
|
||||
cerr << "Error: `" << leftArg << "' " ;
|
||||
cerr << "is not a variable id." << endl ;
|
||||
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;
|
||||
cerr << "Error: unknow variable with id " ;
|
||||
cerr << "`" << vid << "'." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (rightArg.empty()) {
|
||||
cerr << "error: missing right argument" << endl;
|
||||
cerr << "Error: missing right argument." << endl;
|
||||
cerr << USAGE << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (Util::isInteger (rightArg) == false) {
|
||||
cerr << "error: `" << rightArg << "' " ;
|
||||
cerr << "is not a state index" << endl ;
|
||||
cerr << "Error: `" << rightArg << "' " ;
|
||||
cerr << "is not a state index." << endl ;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
unsigned stateIdx = Util::stringToUnsigned (rightArg);
|
||||
if (observedVar->isValidState (stateIdx) == false) {
|
||||
cerr << "error: `" << stateIdx << "' " ;
|
||||
cerr << "Error: `" << stateIdx << "' " ;
|
||||
cerr << "is not a valid state index for variable with id " ;
|
||||
cerr << "`" << vid << "'" << endl;
|
||||
cerr << "`" << vid << "'." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
observedVar->setEvidence (stateIdx);
|
||||
|
@ -423,7 +423,7 @@ readParfactor (YAP_Term pfTerm)
|
||||
for (unsigned i = 1; i <= arity; i++) {
|
||||
YAP_Term ti = YAP_ArgOfTerm (i, term);
|
||||
if (YAP_IsAtomTerm (ti) == false) {
|
||||
cerr << "error: constraint has free variables" << endl;
|
||||
cerr << "Error: the constraint contains free variables." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
string name ((char*) YAP_AtomName (YAP_AtomOfTerm (ti)));
|
||||
|
@ -277,8 +277,7 @@ LiftedCircuit::exportToGraphViz (const char* fileName)
|
||||
{
|
||||
ofstream out (fileName);
|
||||
if (!out.is_open()) {
|
||||
cerr << "error: cannot open file to write at " ;
|
||||
cerr << "LiftedCircuit::exportToDotFile()" << endl;
|
||||
cerr << "Error: couldn't open file '" << fileName << "'." ;
|
||||
return;
|
||||
}
|
||||
out << "digraph {" << endl;
|
||||
|
@ -22,7 +22,7 @@ LiftedKc::solveQuery (const Grounds& query)
|
||||
lwcnf_ = new LiftedWCNF (pfList_);
|
||||
circuit_ = new LiftedCircuit (lwcnf_);
|
||||
if (circuit_->isCompilationSucceeded() == false) {
|
||||
cerr << "error: compilation failed" << endl;
|
||||
cerr << "Error: the circuit compilation has failed." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
vector<PrvGroup> groups;
|
||||
|
@ -35,8 +35,8 @@ LiftedOperations::shatterAgainstQuery (
|
||||
}
|
||||
}
|
||||
if (found == false) {
|
||||
cerr << "error: could not find a parfactor with ground " ;
|
||||
cerr << "`" << query[i] << "'" << endl;
|
||||
cerr << "Error: could not find a parfactor with ground " ;
|
||||
cerr << "`" << query[i] << "'." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
pfList.add (newPfs);
|
||||
|
@ -23,10 +23,10 @@ CC=@CC@
|
||||
CXX=@CXX@
|
||||
|
||||
# normal
|
||||
CXXFLAGS= -std=c++0x @SHLIB_CXXFLAGS@ $(YAP_EXTRAS) $(DEFS) -D_YAP_NOT_INSTALLED_=1 -I$(srcdir) -I../../.. -I$(srcdir)/../../../include @CPPFLAGS@ -DNDEBUG
|
||||
#CXXFLAGS= -std=c++0x @SHLIB_CXXFLAGS@ $(YAP_EXTRAS) $(DEFS) -D_YAP_NOT_INSTALLED_=1 -I$(srcdir) -I../../.. -I$(srcdir)/../../../include @CPPFLAGS@ -DNDEBUG
|
||||
|
||||
# debug
|
||||
#CXXFLAGS= -std=c++0x @SHLIB_CXXFLAGS@ $(YAP_EXTRAS) $(DEFS) -D_YAP_NOT_INSTALLED_=1 -I$(srcdir) -I../../.. -I$(srcdir)/../../../include @CPPFLAGS@ -g -O0 -Wextra
|
||||
CXXFLAGS= -std=c++0x @SHLIB_CXXFLAGS@ $(YAP_EXTRAS) $(DEFS) -D_YAP_NOT_INSTALLED_=1 -I$(srcdir) -I../../.. -I$(srcdir)/../../../include @CPPFLAGS@ -g -O0 -Wextra
|
||||
|
||||
|
||||
#
|
||||
|
@ -689,7 +689,7 @@ Parfactor::expandPotential (
|
||||
{
|
||||
ullong newSize = (params_.size() / ranges_[fIdx]) * newRange;
|
||||
if (newSize > params_.max_size()) {
|
||||
cerr << "error: an overflow occurred when performing expansion" ;
|
||||
cerr << "Error: an overflow occurred when performing expansion." ;
|
||||
cerr << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
@ -334,7 +334,7 @@ ParfactorList::shatterAgainstMySelf (
|
||||
ProbFormula& f1 = g->argument (fIdx1);
|
||||
ProbFormula& f2 = g->argument (fIdx2);
|
||||
if (f1.isAtom()) {
|
||||
cerr << "error: a ground occurs twice in a parfactor" << endl;
|
||||
cerr << "Error: a ground occurs twice in the same parfactor." << endl;
|
||||
cerr << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ stringToUnsigned (string str)
|
||||
ss << str;
|
||||
ss >> val;
|
||||
if (val < 0) {
|
||||
cerr << "error: the readed number is negative" << endl;
|
||||
cerr << "Error: the number readed is negative." << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
return static_cast<unsigned> (val);
|
||||
|
Reference in New Issue
Block a user