Don't abort if opening a file to export to graphviz fails

This commit is contained in:
Tiago Gomes 2012-12-20 17:11:11 +00:00
parent af8497af6e
commit 2ca31ca14a
5 changed files with 12 additions and 15 deletions

View File

@ -81,7 +81,7 @@ BayesBallGraph::exportToGraphViz (const char* fileName)
if (!out.is_open()) { if (!out.is_open()) {
cerr << "error: cannot open file to write at " ; cerr << "error: cannot open file to write at " ;
cerr << "BayesBallGraph::exportToDotFile()" << endl; cerr << "BayesBallGraph::exportToDotFile()" << endl;
abort(); return;
} }
out << "digraph {" << endl; out << "digraph {" << endl;
out << "ranksep=1" << endl; out << "ranksep=1" << endl;

View File

@ -523,7 +523,7 @@ ConstraintTree::exportToGraphViz (
if (!out.is_open()) { if (!out.is_open()) {
cerr << "error: cannot open file to write at " ; cerr << "error: cannot open file to write at " ;
cerr << "ConstraintTree::exportToDotFile()" << endl; cerr << "ConstraintTree::exportToDotFile()" << endl;
abort(); return;
} }
out << "digraph {" << endl; out << "digraph {" << endl;
ConstraintTree copy (*this); ConstraintTree copy (*this);

View File

@ -101,17 +101,14 @@ ElimGraph::exportToGraphViz (
if (!out.is_open()) { if (!out.is_open()) {
cerr << "error: cannot open file to write at " ; cerr << "error: cannot open file to write at " ;
cerr << "Markov::exportToDotFile()" << endl; cerr << "Markov::exportToDotFile()" << endl;
abort(); return;
} }
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().size() != 0) {
out << '"' << nodes_[i]->label() << '"' << endl; out << '"' << nodes_[i]->label() << '"' << endl;
} }
} }
for (size_t i = 0; i < highlightVarIds.size(); i++) { for (size_t i = 0; i < highlightVarIds.size(); i++) {
EgNode* node =getEgNode (highlightVarIds[i]); EgNode* node =getEgNode (highlightVarIds[i]);
if (node) { if (node) {
@ -122,7 +119,6 @@ ElimGraph::exportToGraphViz (
abort(); abort();
} }
} }
for (size_t i = 0; i < nodes_.size(); i++) { for (size_t i = 0; i < nodes_.size(); i++) {
EGNeighs neighs = nodes_[i]->neighbors(); EGNeighs neighs = nodes_[i]->neighbors();
for (size_t j = 0; j < neighs.size(); j++) { for (size_t j = 0; j < neighs.size(); j++) {
@ -130,7 +126,6 @@ ElimGraph::exportToGraphViz (
out << '"' << neighs[j]->label() << '"' << endl; out << '"' << neighs[j]->label() << '"' << endl;
} }
} }
out << "}" << endl; out << "}" << endl;
out.close(); out.close();
} }

View File

@ -283,7 +283,7 @@ FactorGraph::exportToGraphViz (const char* fileName) const
if (!out.is_open()) { if (!out.is_open()) {
cerr << "error: cannot open file to write at " ; cerr << "error: cannot open file to write at " ;
cerr << "FactorGraph::exportToDotFile()" << endl; cerr << "FactorGraph::exportToDotFile()" << endl;
abort(); return;
} }
out << "graph \"" << fileName << "\" {" << endl; out << "graph \"" << fileName << "\" {" << endl;
for (size_t i = 0; i < varNodes_.size(); i++) { for (size_t i = 0; i < varNodes_.size(); i++) {
@ -316,8 +316,9 @@ 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 " << fileName << endl; cerr << "error: cannot open file to write at " ;
abort(); cerr << "ConstraintTree::exportToUaiFormat()" << endl;
return;
} }
out << "MARKOV" << endl; out << "MARKOV" << endl;
out << varNodes_.size() << endl; out << varNodes_.size() << endl;
@ -350,8 +351,9 @@ 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 " << fileName << endl; cerr << "error: cannot open file to write at " ;
abort(); cerr << "ConstraintTree::exportToUaiFormat()" << endl;
return;
} }
out << facNodes_.size() << endl << endl; out << facNodes_.size() << endl << endl;
for (size_t i = 0; i < facNodes_.size(); i++) { for (size_t i = 0; i < facNodes_.size(); i++) {

View File

@ -278,8 +278,8 @@ 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: cannot open file to write at " ;
cerr << "BayesBallGraph::exportToDotFile()" << endl; cerr << "LiftedCircuit::exportToDotFile()" << endl;
abort(); return;
} }
out << "digraph {" << endl; out << "digraph {" << endl;
out << "ranksep=1" << endl; out << "ranksep=1" << endl;