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