Mercurial Hosting > traffic-intelligence
view c/utils.cpp @ 190:36968a63efe1
Got the connected_components to finally work using a vecS for the vertex list in the adjacency list.
In this case, the component map is simply a vector of ints (which is the type of UndirectedGraph::vextex_descriptor (=graph_traits<FeatureGraph>::vertex_descriptor) and probably UndirectedGraph::vertices_size_type).
To use listS, I was told on the Boost mailing list:
>> If you truly need listS, you will need to create a vertex index
>> map, fill it in before you create the property map, and pass it to the
>> vector_property_map constructor (and as a type argument to that class).
It may be feasible with a component map like
shared_array_property_map< graph_traits<FeatureGraph>::vertex_descriptor, property_map<FeatureGraph, vertex_index_t>::const_type > components(num_vertices(g), get(vertex_index, g));
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 07 Dec 2011 18:51:32 -0500 |
parents | c8a149fccfda |
children | bc4ea09b1743 |
line wrap: on
line source
#include "utils.hpp" #include <boost/foreach.hpp> #include <iostream> #include <fstream> #include <sstream> using namespace std; vector<vector<float> > loadNumbers(const string& filename, const string& separator /* = " " */) { ifstream in(filename.c_str()); vector<vector<float> > result; if (::openCheck(in, filename, "loadNumbers")) { while (!in.eof()) { string line = ::getlineComment(in); vector<string> tokens; ::split(tokens, line, separator); vector<float> numbers; BOOST_FOREACH(string s, tokens) numbers.push_back(::toFloat(s)); if (!numbers.empty()) result.push_back(numbers); } } return result; } int toInt(const std::string& s) { int i; fromString(i, s); return i;} //atoi float toFloat(const std::string& s) { float x; fromString(x, s); return x;}// lexical_cast<float>(s) double toDouble(const std::string& s) { double x; fromString(x, s); return x;} string getlineComment(ifstream& f) { string s; getline(f, s); while ((!f.eof()) && (s[0] == ::commentChar)) { getline(f, s); } if (s[0] == ::commentChar) s.clear(); return s; } void openWriteScientificPrecision(ofstream& out, const string& filename, const int& precision) { ::openWritePrecision(out, filename, precision); out.setf(ios::scientific); } void openWritePrecision(ofstream& out, const string& filename, const int& precision) { out.open(filename.c_str(), ios::binary); ::openCheck(out, filename, "openWritePrecision"); out.precision(precision); } bool openCheck(ifstream& f, const string& filename, const string& callingFunctionName) { if (!f.is_open()) { cerr << "Pb opening file " << filename << " in " << callingFunctionName << endl; return false; } else return true; } bool openCheck(ofstream& f, const string& filename, const string& callingFunctionName) { if (!f.is_open()) { cerr << "Pb opening file " << filename << " in " << callingFunctionName << endl; return false; } else return true; }