int main(int argc, char ** argv) { try { using float_t = double; using size_type = std::uint32_t; if (4 != argc) throw std::invalid_argument("usage: simplify <<t> | -p> <in_file> <out_file>"); // read the flow complex from file auto fc = FC::flow_complex<float_t, size_type>(42, 42); // dummy { auto in_filename = argv[2]; std::ifstream in_file(in_filename); in_file >> fc; } char const* action = argv[1]; if (std::string(action) == "-p") { char const* out_filename = argv[3]; std::ofstream out_file(out_filename); print_histogram(out_file, std::move(fc)); } else { // simplify float_t const t = std::atof(argv[1]); if (t < 1) throw std::invalid_argument("prerequisite: t >= 1"); fc = simplify(std::move(fc), t); // write result flow complex to file char const* out_filename = argv[3]; std::ofstream out_file(out_filename); out_file << fc; } } catch (std::exception & e) { std::cerr << e.what() << std::endl; std::exit(EXIT_FAILURE); } std::exit(EXIT_SUCCESS); }
void ExplicitSystemManager::dump_system() { int denominator = std::max((int)options.save_frequency, 1); std::string filename_tail = (boost::format("_%05d") % (iteration_number / denominator)).str(); std::string displacements_filename = (boost::format("%s%s.txt") % options.nodal_displacements_filename % filename_tail).str(); std::string velocities_filename = (boost::format("%s%s.txt") % options.nodal_velocities_filename % filename_tail).str(); std::string forces_filename = (boost::format("%s%s.txt") % options.nodal_forces_filename % filename_tail).str(); save_column_vector(explicit_system->getDisplacements(), displacements_filename); config_doc["nodal_displacements"].SetString(displacements_filename.c_str(), displacements_filename.length()); save_column_vector(explicit_system->getVelocities(), velocities_filename); config_doc["nodal_velocities"].SetString(velocities_filename.c_str(), velocities_filename.length()); save_column_vector(explicit_system->getForces(), forces_filename); config_doc["start_time"].SetDouble(explicit_system->getTime()); config_doc["iteration_number"].SetUint(iteration_number); std::string state_filename((boost::format("%s%s.json") % options.state_filename % filename_tail).str()); std::ofstream out_file(state_filename); if (out_file.is_open()) { rapidjson::OStreamWrapper o_wrapper(out_file); rapidjson::PrettyWriter<rapidjson::OStreamWrapper> writer(o_wrapper); config_doc.Accept(writer); out_file.close(); } else { throw std::runtime_error((boost::format("Unable to open %s.") % state_filename).str()); } }
void EMFit::output(std::string out_file_name, std::string out_pdb_file_name) { std::ofstream out_file(out_file_name.c_str()); out_file << "receptorPdb (str) " << rec_file_name_ << std::endl; out_file << "ligandPdb (str) " << lig_file_name_ << std::endl; EM3DFitResult::print_header(out_file); out_file.setf(std::ios::fixed, std::ios::floatfield); out_file.setf(std::ios::right, std::ios::adjustfield); IMP::algebra::Vector3Ds lig_points; IMP::saxs::get_coordinates(lig_particles_, lig_points); for (unsigned int i = 0; i < fit_results_.size(); i++) { out_file << fit_results_[i] << std::endl; } out_file.close(); if (fit_results_.size() == 1) { // output PDB IMP::algebra::Transformation3D tr = fit_results_[0].get_map_trans(); IMP::Particles ps = rec_particles_; ps.insert(ps.end(), lig_particles_.begin(), lig_particles_.end()); // transform for (IMP::Particles::iterator it = ps.begin(); it != ps.end(); it++) { IMP::core::XYZ d(*it); d.set_coordinates(tr * d.get_coordinates()); } // output std::ofstream out_file2(out_pdb_file_name.c_str()); IMP::ParticlesTemp pst = ps; IMP::atom::write_pdb(pst, out_file2); out_file2.close(); } }
bool Curves::plot_print_standard_residual(const char *path , double *standard_residual) const { bool status = false; register int i; ofstream out_file(path); if (out_file) { status = true; // writing of observed responses and standardized residuals for (i = 0;i < length;i++) { if (frequency[i] > 0) { out_file << i << " " << point[0][i]; if (standard_residual) { out_file << " " << standard_residual[i]; } out_file << " " << frequency[i] << endl; } } } return status; }
static void file_init(void) { int i; /* loop index */ /* * * Gets everything ready for the next input file. * */ dwb_devname[0] = '\0'; res = 0; hort = 1; vert = 1; font = 1; size = 10; nfonts = 0; slant = 0; height = 0; for ( i = 0; i < NFONT; i++ ) fontname[i].name[0] = '\0'; pages = 0; bytes = 0; out_file(); /* set up the output file */ } /* End of file_init */
void ObjectWriter::CopyFile(std::string in, std::string out){ std::ifstream in_file(in.c_str(), std::fstream::binary); std::ofstream out_file(out.c_str(), std::fstream::trunc|std::fstream::binary); out_file << in_file.rdbuf(); in_file.close(); out_file.close(); }
int main() { // set_Progress_Bar_visibility(true); std::ofstream out_file("data/Precision_Scan.txt", std::fstream::out); out_file << "Tilde basis:" << std::endl; out_file.close(); Verify::Precision_Scan(&Tilde::Palphabeta, 0, 1e-2); Verify::Precision_Scan(&Tilde::Palphabeta, 1, 1e-2); out_file.open("data/Precision_Scan.txt", std::fstream::app); out_file << "Hat basis:" << std::endl; out_file.close(); Verify::Precision_Scan(&Hat::Palphabeta, 0, 1e-2); Verify::Precision_Scan(&Hat::Palphabeta, 0, 1e-3); Verify::Precision_Scan(&Hat::Palphabeta, 1, 1e-2); Verify::Precision_Scan(&Hat::Palphabeta, 1, 1e-3); out_file.open("data/Precision_Scan.txt", std::fstream::app); out_file << "Check basis (GF):" << std::endl; out_file.close(); Verify::Precision_Scan(&GF::Palphabeta, 0, 1e-2); Verify::Precision_Scan(&Check::Palphabeta, 0, 1e-2); Verify::Precision_Scan(&GF::Palphabeta, 0, 1e-3); Verify::Precision_Scan(&GF::Palphabeta, 1, 1e-3); out_file.close(); return 0; }
int main() { // NOTE The rotation matrices below are in Yin Yang's convention (not mine!) // Airship2IMU gives matrix such that v_Airship = Airship2IMU * v_IMU double Airship2IMU_raw[] = { 0.280265845357, 0.0, 0.959922421827, 0.0, -1.0, 0.0, 0.959922421827, 0.0, -0.280265845357}; ReaK::rot_mat_3D<double> Airship2IMU(Airship2IMU_raw); ReaK::quaternion<double> Airship2IMU_quat = ReaK::quaternion<double>(Airship2IMU); ReaK::quaternion<double> IMU_orientation = Airship2IMU_quat; ReaK::vect<double,3> IMU_location(-0.896665, 0.0, 0.25711); // Room2Global gives matrix such that v_room = Room2Global * v_gbl double Room2Global_raw[] = { 0.75298919442, -0.65759795928, 0.02392064034, -0.6577626482, -0.7532241836, -0.0012758604, 0.018856608, -0.0147733946, -0.9997130464}; ReaK::rot_mat_3D<double> Room2Global(Room2Global_raw); ReaK::quaternion<double> Room2Global_quat = ReaK::quaternion<double>(Room2Global); ReaK::quaternion<double> room_orientation = invert(Room2Global_quat); ReaK::serialization::xml_oarchive out_file("airship3D_transforms.xml"); out_file & RK_SERIAL_SAVE_WITH_NAME(IMU_orientation) & RK_SERIAL_SAVE_WITH_NAME(IMU_location) & RK_SERIAL_SAVE_WITH_NAME(room_orientation); return 0; };
bool LLCrashLogger::sendCrashLogs() { gatherFiles(); LLSD post_data; post_data = constructPostData(); updateApplication("Sending reports..."); std::string dump_path = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "SecondLifeCrashReport"); std::string report_file = dump_path + ".log"; std::ofstream out_file(report_file.c_str()); LLSDSerialize::toPrettyXML(post_data, out_file); out_file.close(); bool sent = false; //*TODO: Translate if(mCrashHost != "") { sent = runCrashLogPost(mCrashHost, post_data, std::string("Sending to server"), 3, 5); } if(!sent) { sent = runCrashLogPost(mAltCrashHost, post_data, std::string("Sending to alternate server"), 3, 5); } mSentCrashLogs = sent; return true; }
void printTime2File ( const double Time ) { std::stringstream msg; msg << "Total scope_life time= " << Time << " usecs" << std::endl; File out_file( "times.log" ); out_file.write( msg.str( ).c_str( ) ); }
void LogSelectorForm::check_config(){ QString conf_path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation).append("/config.json"); QFile f(conf_path); if (!f.exists()){ QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); QJsonValue algorithm("KMeans"); QJsonObject param = QJsonObject(); param.insert("n_clusters",4); QJsonArray features; features.append(QString("count_domain_with_numbers")); features.append(QString("average_domain_length")); features.append(QString("std_domain_length")); features.append(QString("count_request")); features.append(QString("average_requisition_degree")); features.append(QString("std_requisition_degree")); features.append(QString("minimum_requisition_degree")); QJsonObject target = QJsonObject(); target.insert("algorithm",algorithm); target.insert("features",features); target.insert("param",param); QJsonDocument config_out(target); QFile out_file(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation).append("/config.json")); out_file.open(QIODevice::WriteOnly | QIODevice::Text); out_file.write(config_out.toJson()); out_file.close(); } }
bool CompoundData::ascii_write(StatError &error , const string path , bool exhaustive) const { bool status = false; if (compound) { ofstream out_file(path.c_str()); error.init(); if (!out_file) { status = false; error.update(STAT_error[STATR_FILE_NAME]); } else { status = true; compound->ascii_write(out_file , this , exhaustive , true); } } return status; }
void convert_matrices(const std::string &in, const std::string &out) { std::ifstream in_file(in); // TODO check if in file exists std::ofstream out_file(out, std::ofstream::trunc); std::string line; int line_num = 0; while (std::getline(in_file, line)) { std::istringstream line_stream(line); std::stringstream output_stream; out_file << line_num << ' '; ++line_num; bool c; int c_num = 0; int matches = 0; while (line_stream >> c) { if (c) { ++matches; output_stream << ' ' << c_num; } ++c_num; } // construct line out_file << matches << output_stream.str() << std::endl; } in_file.close(); out_file.close(); }
void SaveToFile(const FileEx &src_file, LONGLONG &ptr) { DWORD rw = 0; BYTE buff[BLOCK_SIZE] = {0}; STATISTIC statistic; TCHAR file_name[1024] = {0}; _stprintf_s(file_name, 1024, _T("%06I64d.txt"), ptr); FileEx out_file(file_name); if (const_cast<FileEx &>(src_file).SetPointer(ptr)) { while (rw = const_cast<FileEx &>(src_file).Read(buff, BLOCK_SIZE)) { AnalyzeBuffer(buff, rw, statistic); if (IsPartOfTextFile(statistic) && out_file.Create()) { if (statistic.ch_cnt < rw) { out_file.Write(buff, GetSequenceLength(buff, rw)); break; } else out_file.Write(buff, rw); } else return; } } }
void write_half_exr( const boost::filesystem::path& p, Imf::Header& header, const image::const_image_view_t& view, bool write_alpha) { boost::gil::rgba16f_image_t img( view.width(), view.height()); boost::gil::copy_and_convert_pixels( view, boost::gil::view( img)); header.channels().insert( "R", Imf::HALF); header.channels().insert( "G", Imf::HALF); header.channels().insert( "B", Imf::HALF); if( write_alpha) header.channels().insert( "A", Imf::HALF); Imf::FrameBuffer frameBuffer; char *ptr = (char *) boost::gil::interleaved_view_get_raw_data( boost::gil::view( img)); std::size_t xstride = 4 * sizeof(half); std::size_t ystride = xstride * img.width(); frameBuffer.insert( "R", Imf::Slice( Imf::HALF, ptr, xstride, ystride)); ptr += sizeof(half); frameBuffer.insert( "G", Imf::Slice( Imf::HALF, ptr, xstride, ystride)); ptr += sizeof(half); frameBuffer.insert( "B", Imf::Slice( Imf::HALF, ptr, xstride, ystride)); ptr += sizeof(half); if( write_alpha) frameBuffer.insert( "A", Imf::Slice( Imf::HALF, ptr, xstride, ystride)); Imf::OutputFile out_file( p.external_file_string().c_str(), header); out_file.setFrameBuffer( frameBuffer); out_file.writePixels( img.height()); }
// Saves Solver input (.sif) file. void Control::saveSolverInputFile(char* out_filename) { ofstream out_file(out_filename, ios::out); if ( !write_ok(out_file, out_filename, "(Writing ELMER Solver input file)") ) return; #if defined(FRONT_DEBUG) theModel->saveSolverInputFile(out_file, out_filename); #else try { theModel->saveSolverInputFile(out_file, out_filename); } catch (...) { theUI->showMsg("ERROR: Unable to save Solver input file (sif-file)!"); } #endif out_file.close(); }
void BBAzimuthalReflex::process(DataPacket& abs_in_packet) { LB_ASSERT(abs_in_packet._domain == DOM_TEMPORAL, "Packet must be in temporal domain."); DPTemporal& in_packet = dynamic_cast<DPTemporal&>(abs_in_packet); //Scan through ILD data and decide the next motor command lbfloat ILD = in_packet[0][0]; //If we can move the head (reflex not ended yet) if(!_lock) { //ILD<0 means the source is on the right if(ILD<0) { //So we turn clockwise _neck_motor->reach_position(_cw_angle_limit+1); } //ILD>0 means the source is on the left else { //So we turn counter-clockwise _neck_motor->reach_position(_ccw_angle_limit-1); } } //Save data for later log _ILD.push_back(ILD); _L_energies.push_back(in_packet[0][1]); _R_energies.push_back(in_packet[0][2]); int current_position; _neck_motor->get_value(MX28_PRESENT_POSITION, current_position); _theta.push_back((lbfloat)current_position); _time.push_back(in_packet.get_start_index()/_sample_freq); //If the ILD's sign changes, we are facing the source //We also verify that ILD variation is big enough if(_old_ILD*ILD<0 && _old_ILD!=0 && fabs(_old_ILD-ILD)>=_step_threshold) { _neck_motor->stop(); _lock = true; _neck_motor->get_value(MX28_PRESENT_POSITION, _final_position); _final_ILD = ILD; std::cout << "Initial orientation : " << Mx28::step_to_angle(_start_position) << "°" << std::endl << "Final orientation : " << Mx28::step_to_angle((_final_position+_theta[_theta.size()-2])/2) << "°" << std::endl << "Final ILD : " << (_final_ILD+_old_ILD)/2 << std::endl; //<< "Final energies (L/R) : " << in_packet[0][1] << " " << in_packet[0][2] << std::endl; std::ofstream out_file("tests/data/reflex_data.dat"); out_file << "# Params: " << std::endl; out_file << "# Time(s) \t ILD \t Left Energy \t Right Energy \t Angle" << std::endl; for(size_t ii=0; ii<_time.size(); ++ii) { out_file << _time[ii] << " " << _ILD[ii] << " " << _L_energies[ii] << " " << _R_energies[ii] << " " << _theta[ii] << std::endl; } out_file.close(); } _old_ILD = ILD; }
int main(int argc, char** argv) { std::ifstream in_file(argv[1]); std::string input((std::istreambuf_iterator<char_type>(in_file)), std::istreambuf_iterator<char_type>()); std::transform(input.begin(), input.end(), input.begin(), caesar_cipher(std::atoi(argv[2]))); std::ofstream out_file("caesar_cipher.txt"); std::cout << input << std::endl; out_file << input; }
int main( int argc, char **argv ) { // args #include <PrepArg/declarations.h> #include <PrepArg/parse.h> if ( beg_files < 0 ) return usage( argv[ 0 ], "Please specify an input file", 2 ); bool add_base_files = not ( disp_lexems or disp_tokens ); // particular case if ( disp_tokens or disp_lexems ) { // -> source data ReadFile r( argv[ beg_files ] ); if ( not r ) { std::cerr << "Impossible to open " << argv[ beg_files ] << std::endl; return 2; } // -> lexical data ErrorList e; Lexer l( e ); l.parse( r.data, argv[ beg_files ] ); if ( e ) return 3; if ( disp_lexems ) l.display(); if ( disp_tokens ) TODO; return 0; } // input files Vec<String> input_files; if ( add_base_files and false ) input_files << String( base_met_files ) + "/base.met"; for( int i = beg_files; i < argc; ++i ) input_files << argv[ i ]; // context Ip ip_inst; ip = &ip_inst; ip->add_inc_path( base_met_files ); // parse for( int i = 0; i < input_files.size(); ++i ) ip->import( input_files[ i ] ); // compile Codegen_C cr; cr.disp_inst_graph_wo_phi = disp_inst_g_wo_phi; cr.disp_inst_graph = disp_inst_g; cr << ip->sys_state.get_val(); std::ofstream out_file( "out.cpp" ); cr.write_to( out_file ); return ip->error_list; }
int main(int argc, char *argv[]) { int thisnode, totalnodes; MPI_Status status; MPI_Init(&argc, &argv); int number_of_realizations = argc - 4; Real input_rho = atof(argv[1]); Real input_g = atof(argv[2]); Real input_alpha = atof(argv[3]); Real noise_list[number_of_realizations]; for (int i = 0; i < number_of_realizations; i++) noise_list[i] = atof(argv[i + 4]); MPI_Comm_size(MPI_COMM_WORLD, &totalnodes); MPI_Comm_rank(MPI_COMM_WORLD, &thisnode); long int seed = 0 + thisnode*112488; while (!Chek_Seeds(seed, thisnode, totalnodes)) { seed = time(NULL) + thisnode*112488; MPI_Barrier(MPI_COMM_WORLD); } C2DVector::Init_Rand(seed); Real t_eq,t_sim; Box box; for (int i = 0; i < number_of_realizations; i++) { if ((i % totalnodes) == thisnode) { box.Init(input_rho, input_g, input_alpha, noise_list[i]); cout << "From processor " << thisnode << " Box information is: " << box.info.str() << endl; stringstream address; address.str(""); address << box.info.str() << "-r-v.bin"; ofstream out_file(address.str().c_str()); t_eq = equilibrium(&box, equilibrium_step, saving_period, out_file); cout << i << " From node: " << thisnode << "\t" << "elapsed time of equilibrium is \t" << t_eq << endl; t_sim = data_gathering(&box, total_step, saving_period, out_file); cout << i << " From node: " << thisnode << "\t" << "elapsed time of simulation is \t" << t_sim << endl; out_file.close(); } } MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); }
Solution *Solver::solve(){ std::ofstream out_file (file_out.c_str()); if (!out_file.is_open()) { std::cout << "Unable to open file"; } init(); // ------ print solution ------- print_solution(current_solution); //print_file_solution(0, current_solution, out_file); // ------ print solution ------- clock_t start, end, total; start = clock(); for(unsigned int i=0;i<max_iterations;i++){ iter_cost_time = 0; std::cout << "----- iteration "<< i << " ------" << std::endl; local_search(); // ------ print solution ------- std::cout << "local search "; print_solution(current_solution); print_file_solution(i, current_solution, out_file); // ------ print solution ------- global_search(); // ------ print solution ------- std::cout << "global search "; print_solution(current_solution); //print_file_solution(i, current_solution, out_file); // ------ print solution ------- tabu_list->update_tabu(); total_cost_time += iter_cost_time; if(global_best_cost == 0) break; } end = clock(); total = end - start; printf("\nTotal OpenCL Kernel time in milliseconds = %0.3f ms\n", (total_cost_time / 1000000.0) ); printf("Total CPU time in milliseconds = %0.3f ms\n", total /1000.0); return global_best; }
void printOHLC2File ( const OHLC_t * ohlc ) { std::stringstream msg; msg << "O= " << ohlc->Open << ", "; msg << "H= " << ohlc->High << ", "; msg << "L= " << ohlc->Low << ", "; msg << "C= " << ohlc->Close << std::endl; File out_file( "OHLC.log" ); out_file.write( msg.str( ).data( ) ); }
void swd::daemon::write_pid(const std::string& file) { std::ofstream out_file(file.c_str()); if (!out_file.is_open()) { throw swd::exceptions::core_exception("Failed to write pid file"); } out_file << getpid(); out_file.close(); }
void ReadDB::save() const { std::string out_filename = m_indexed_reads_filename + READ_DB_SUFFIX; std::ofstream out_file(out_filename.c_str()); for(const auto& iter : m_data) { const ReadDBData& entry = iter.second; out_file << iter.first << "\t" << entry.signal_data_path << "\n"; } }
void ExplicitSystemManager::save_column_vector(const ColumnVector &vec, std::string filename) { std::ofstream out_file(filename); if (out_file.is_open()) { for (int i = 0; i < vec.size(); ++i) { out_file << std::setprecision(15) << vec[i] << "\n"; } out_file.close(); } else { throw std::runtime_error((boost::format("Unable to open %s.") % filename).str()); } }
// Convert the input txt file (just after conversion from .mat) // into libsvm format // so as to compare resuls with visible units to the onces with new learned features void transform_to_libsvm_format(std::string data_file, int sample_size, int num_visible_units, std::string libsvm_features_file){ std::string feature_file(data_file); std::string label_file(data_file); feature_file += ".fea"; label_file += ".labels"; float ** input_f = new float*[sample_size]; for (int i=0; i<sample_size; i++){ input_f[i] = new float[num_visible_units]; } std::ifstream feat_file(feature_file.c_str(),std::ios::in); for (int i=0; i<sample_size; i++){ for (int j=0; j<num_visible_units; j++){ feat_file >> input_f[i][j]; // Binary RBM if (input_f[i][j] > 0){ input_f[i][j] = 1; } } } feat_file.close(); int * output_labels = new int[sample_size]; FILE * tmpfp = fopen(label_file.c_str(),"r"); for (int i = 0; i < sample_size; i++){ fscanf(tmpfp, "%d", &output_labels[i]); } fclose(tmpfp); // write the features to libsvm_features_file // libsvm uses a sparse format std::ofstream out_file(libsvm_features_file); if (out_file.is_open()){ for (int i=0; i<sample_size; i++){ int non_zero_features = 0; for (int j=0; j<num_visible_units; j++){ if (input_f[i][j] != 0){ non_zero_features++; if (non_zero_features == 1){ out_file << output_labels[i]; } out_file << " " << (j+1) << ":" << input_f[i][j]; // indexing starts at 1 in libsvm } } if (non_zero_features > 0){ out_file << std::endl; } } out_file.close(); } }
bool write_file(std::string outfile_name, std::string contents) { std::ofstream out_file(outfile_name.c_str()); if (out_file.is_open()) { out_file << contents; } else { return false; } out_file.close(); return true; }
bool WriteNode::pullToFile(const Path &file_path) { //Set up file std::ofstream out_file(file_path.getSystem(), std::ofstream::out); AudioVelChunk chunk(AUDIO_CHUNK_SIZE, 0); //Check input connections //TODO: Only pull from buffer AudioPullPacket packet(&cursor, &chunk, TransferMethod::COPY); return connectors[INPUTS.AUDIO_ID]->pullData(packet); }
// 自己対局の局面を生成し、ファイルに書き出す void make(std::istringstream &is) { std::string record_file_name; is >> record_file_name; std::string book_file_name; std::vector<std::vector<std::string>> book; is >> book_file_name; if (!book_file_name.empty()) load_book(book_file_name, book); std::vector<PositionData> position_list; int count = 0; int write_count = 0; Options["USI_Hash"] = 512; while (true) { play_game(position_list, book); ++count; if (count % 500 == 0) std::cout << count << std::endl; else if (count % 100 == 0) std::cout << "o" << std::flush; else if (count % 10 == 0) std::cout << "." << std::flush; if (position_list.size() > kKifuStoreNum) { std::shuffle(position_list.begin(), position_list.end(), std::mt19937()); std::ofstream out_file(record_file_name, std::ios::out | std::ios::app); for (auto &m : position_list) { out_file << m.sfen << "," << m.value; if (m.win == kBlack) out_file << ",b"; else if (m.win == kWhite) out_file << ",w"; else out_file << ",d"; out_file << "," << m.next_move; out_file << std::endl; } out_file.close(); position_list.clear(); ++write_count; if (write_count == kEndCount) break; } } }
void ResidualGraph::toDot(const std::string& filename, const Path& p, Node& s, Node& t) const { std::ofstream out_file(filename.c_str()); if(!out_file.good()) { throw std::runtime_error("Could not open file " + filename + " to save graph to"); } out_file << "digraph G {\n"; // find all nodes participating in path p std::set<Node> nodesOnPath; for(const std::pair<OriginalArc, int>& af : p) { ResidualArcCandidate ac = arcToPair(af.first); nodesOnPath.insert(ac.first); nodesOnPath.insert(ac.second); } // arcs for(Graph::ArcIt a(*this); a != lemon::INVALID; ++a) { ResidualArcCandidate ac = residualArcToPair(a); // only draw arcs that are close to the path if(nodesOnPath.count(ac.first) == 0 && nodesOnPath.count(ac.second) == 0) continue; // only draw arcs that are not connected to source or sink if(ac.first == s || ac.first == t || ac.first == s || ac.second == t) continue; out_file << "\t" << id(ac.first) << " -> " << id(ac.second) << " [ label=\"" << "cost=" << residualArcMap_.at(ac).cost << " originSource=" << originalGraph_.id(originMap_.at(ac.first)) << " originTarget=" << originalGraph_.id(originMap_.at(ac.second)) << "\" "; // highlight arcs on the given path for(const std::pair<OriginalArc, int>& af : p) { if(ac == arcToPair(af.first) || ac == arcToInversePair(af.first)) out_file << "color=\"red\" fontcolor=\"red\" "; } out_file << "]; \n" << std::flush; } out_file << "}"; }