int Graph::toGraphviz(string filename){ ofstream dotFile (filename.c_str()); if( !dotFile.is_open()){ return -1; } vector<string> ids; vector< pair< double, double> > locs; vector<nodeType> types; map< edge_d,string> edge_labels; // cout << "Num vertices " << num_vertices(*this) << endl; // property_map<MyGraphType, vertex_name_t>::type idmap = get(vertex_name_t(),*this); graph_traits<MyGraphType>::vertex_iterator vi, vi_end, next; tie(vi, vi_end) = vertices(*this); for (next = vi; next != vi_end; next++) { // printf("Vertex id [%d] = %s\n",*next,idmap[*next].c_str()); ids.push_back((*this)[*next].id); locs.push_back( make_pair( (*this)[*next].x, (*this)[*next].y)); types.push_back((*this)[*next].t); } graph_traits<MyGraphType>::edge_iterator ei,e_end,e_next; graph_traits<MyGraphType>::edge_descriptor e; tie(ei, e_end) = edges( (*this)); for(e_next = ei; e_next != e_end; e_next++) { edge_labels[*e_next] = (*this)[*e_next].label; } write_graphviz(dotFile, *this,make_position_writer(ids,locs,types),make_edge_writer(edge_labels),graph_writer()); return 0; }
bool ExpDotWriter::writeDotFile(const std::shared_ptr<Exp> &exp, const QString &filename) { QFile dotFile(filename); if (!dotFile.open(QFile::WriteOnly)) { LOG_ERROR("Could not open %1 to write dotty file", filename); return false; } OStream os(&dotFile); m_os = &os; *m_os << "digraph Exp {\n"; exp->acceptVisitor(this); *m_os << "}"; dotFile.flush(); dotFile.close(); m_os = nullptr; return true; }
void Internal_Graph::output() { std::ofstream dotFile("dependencies.dot"); write_graphviz(dotFile, g, graphnode_property_writer < VertexNodeMap > (*NodeMap)); dotFile.flush(); }
int main(int argc, char** argv) { if (argc < 3) { std::cout<<"Usage: prog formula_file calc_file "<<std::endl; std::cout<<"formula_file -- file with formulas, one formula on each line"<<std::endl; std::cout<<"calc_file -- file with parameters to calculate, one parameter on line"<<std::endl; std::cout<<"Program creates file filename.csv -- result of calculations"<<std::endl; std::cout<<"Program creates files filename_i.dot and filename_i.png -- images of graphs for each formula"<<std::endl; return 0; } std::string filePrefix = argv[1]; std::ifstream inFile(argv[1]); std::ifstream calcFile(argv[2]); Calculator calculator(calcFile); std::ofstream outFile(filePrefix + "_out.csv"); // Заголовок таблицы в CSV outFile << "N\tFormula"; calculator.printHeaders(outFile); outFile<<std::endl; int formulaCount = 0; while (inFile.peek() != EOF) { std::string formula; std::getline(inFile, formula); if (formula.empty()) continue; formulaCount++; Molecule m(formula); std::string dotFileName = (boost::format("%1%_%2%.dot") % filePrefix % formulaCount).str(); std::string pngFileName = (boost::format("%1%_%2%.png") % filePrefix % formulaCount).str(); std::ofstream dotFile(dotFileName); m.WriteGraphviz(dotFile); dotFile.close(); std::system((boost::format("dot -Tpng -o %1% %2%") % pngFileName % dotFileName).str().c_str()); outFile << formulaCount << '\t' << formula; std::vector<size_t> results = calculator.calculate(m); for (auto it = results.cbegin(); it != results.cend(); ++it) { outFile << '\t' << *it; } outFile << std::endl; } inFile.close(); calcFile.close(); outFile.close(); return 0; }