1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| #include <boost/graph/adjacency_list.hpp>
#include <boost/graph/vf2_sub_graph_iso.hpp>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
using namespace std;
using namespace boost;
/*********************************************/
// vertex
struct VertexProperties {
int id;
int label;
VertexProperties(unsigned i=0, unsigned l=0) : id(i), label(l) {}
};
// edge
struct EdgeProperties {
unsigned id;
unsigned label;
EdgeProperties(unsigned i=0, unsigned l=0) : id(i), label(l) {}
};
// Graph
struct GraphProperties {
unsigned id;
unsigned label;
GraphProperties(unsigned i=0, unsigned l=0) : id(i), label(l) {}
};
// adjency list
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
VertexProperties,
EdgeProperties,
GraphProperties> Graph;
// descriptors
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef std::pair<boost::graph_traits<Graph>::edge_descriptor, bool> edge_t;
// iterators
typedef graph_traits<Graph>::vertex_iterator vertex_iter;
typedef graph_traits<Graph>::edge_iterator edge_iter;
int main()
{
clock_t start=std::clock();
std::vector<Graph> dataG;
std::ifstream file_reader("1000.data"); // flux d'entrée pour opérer sur les fichiers.
//ifstream * file_reader= new ifstream("60.txt" ); //flux d'entrée pour opérer sur les fichiers.
std::string line;
while (std::getline(file_reader, line)) { // getline reads characters from an input stream and places them into a string
char lineType;
std::stringstream ss(line); // use a string buffer that contains a sequence of characters.
if (ss >> lineType) switch (lineType) {
case 't':
{
char diez;
unsigned gid;
if (ss >> diez >> gid) {
dataG.emplace_back(GraphProperties (gid, gid));
//dataG.push_back(GraphProperties (gid, gid));
}
else throw std::runtime_error("Error parsing '" + line + "'");
}
break;
case 'v':
{
assert(!dataG.empty());
int vId, vLabel;
if (ss >> vId >> vLabel) {
boost::add_vertex(VertexProperties(vId, vLabel), dataG.back());
}
else throw std::runtime_error("Error parsing '" + line + "'");
}
break;
case 'e':
{
assert(!dataG.empty());
int fromId, toId, vLabel;
if (ss >> fromId >> toId >> vLabel) {
// Note that the EdgeProperty.id doesn't make sense with your input data
// as it only contains [vertexFrom vertexTo edgeData]
boost::add_edge(fromId, toId, EdgeProperties(vLabel, vLabel), dataG.back());
}
else throw std::runtime_error("Error parsing '" + line + "'");
}
break;
} else
{
// ignoring empty line
}
}
} |
Partager