我正在尝试制作一个程序,从.txt(类似于
http://pastebin.com/g4cgaHJB
)文件,然后创建并将其放入向量中。(这部分工作得很好)
here ise the code:
#include <iostream>
#include <vector>
#include <ctime>
#include <set>
#include <fstream>
#include <string>
#include <unordered_set>
#include <cstdlib>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/graph/adjacency_list.hpp>
using namespace std;
using namespace boost;
using namespace boost::algorithm;
struct VertexProperties
{
int id;
int label;
VertexProperties(){}
VertexProperties(unsigned i, unsigned l) : id(i), label(l) {}
};
struct EdgeProperties
{
unsigned id;
unsigned label;
EdgeProperties(){}
EdgeProperties(unsigned i, unsigned l) : id(i), label(l) {}
};
struct GraphProperties
{
unsigned id;
unsigned label;
GraphProperties() {}
GraphProperties(unsigned i, unsigned l) : id(i), label(l) {}
};
typedef boost::adjacency_list<
boost::vecS, boost::vecS, boost::directedS,
VertexProperties,
EdgeProperties,
GraphProperties
> Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef std::pair<boost::graph_traits<Graph>::edge_descriptor, bool> edge_t;
typedef graph_traits<Graph>::vertex_iterator vertex_iter;
typedef graph_traits<Graph>::edge_iterator edge_iter;
std::vector<std::string> tokens;
int main()
{
vector<Graph> dataG;
ifstream * file_reader= new ifstream("5.txt" );
while (!file_reader->eof())
{
string line;
file_reader->sync();
getline(*file_reader, line);
std::stringstream ss(line);
char lineType;
ss >> lineType;
if(lineType =='t')
{
char diez;
int gid;
ss >> diez >> gid;
Graph g(GraphProperties(gid,gid));
dataG.push_back(g);
} else if (lineType == 'v')
{
assert(!dataG.empty());
int vId, vLabel;
ss >> vId >> vLabel;
boost::add_vertex(VertexProperties(vId, vLabel), dataG[dataG.size()-1]);
} else if (lineType == 'e')
{
assert(!dataG.empty());
int fromId, toId, vLabel;
ss >> fromId >> toId >> vLabel;
boost::add_edge(fromId, toId,
EdgeProperties(vLabel, vLabel), dataG[dataG.size()-1]);
}
}
cout<<"fin."<<endl;
return 0;
}
想法:我试图在图上迭代,从第一条边开始(并从中创建一个图,我们称之为testg),然后测试这个图是否频繁(我将测试testg和dataG向量中的每个图之间的子图同构,然后我将计算有多少次是真的,如果有很多时间,那么2次,所以testg是频繁的),如果testg是频繁的,那么我将向它添加另一条相邻的边(并再次进行子图isomorpshism测试),如果testg不再频繁,我将删除最后添加的边(回溯)并将其更改为另一条(并再次执行子图isomorpshism测试)。如果没有更多的边可以添加,我会说testg已关闭。把它放到一个向量中,我们称它为closedG。
我的想法是这样开始的:
auto gr=dataG.at(0);
Graph testg();
edge_pair ep;
for (ep = edges(gr); ep.first != ep.second; ++ep.first)
{
vertex_t from = source(*ep.first, gr);
vertex_t to = target(*ep.first, gr);
edge_t edg = edge(from, to, gr);
boost::add_edge(from, to,testg);
}
但是,它不起作用!
以下是错误:
In function 'int main()'
:workshop.cpp:123:42: error: no matching function for call to 'add_edge(vertex_t&, vertex_t&, Graph (&)())'boost:
:add_edge(from, to, testg);
workshop.cpp:123:42: note: candidates are
:In file included from ./boost/graph/adjacency_list.hpp:246:0,from workshop.cpp:12
:./boost/graph/detail/adjacency_list.hpp:707:5: note: template<class Config> std::pair<typename boost::directed_graph_helper<Config>::edge_descriptor, bool> boost::add_edge(typename Config::vertex_descriptor, typename Config::vertex_descriptor, const typename Config::edge_property_type&, boost::directed_graph_helper<Config>&)add_edge(typename Config:
:vertex_descriptor u,
./boost/graph/detail/adjacency_list.hpp:707:5: note: template argument deduction/substitution failed
:workshop.cpp:123:42: note: candidate expects 4 arguments, 3 providedboost:
:add_edge(from, to, testg);
In file included from ./boost/graph/adjacency_list.hpp:246:0,from workshop.cpp:12
:./boost/graph/detail/adjacency_list.hpp:727:5: note: template<class Config> std::pair<typename Config::edge_descriptor, bool> boost::add_edge(typename Config::vertex_descriptor, typename Config::vertex_descriptor, boost::directed_graph_helper<Config>&)add_edge(typename Config:
:vertex_descriptor u,
./boost/graph/detail/adjacency_list.hpp:727:5: note: template argument deduction/substitution failed
:workshop.cpp:123:42: note: mismatched types 'boost::directed_graph_helper<Config>' and 'Graph() {aka boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties, GraphProperties>()}'boost:
:add_edge(from, to, testg);
In file included from ./boost/graph/adjacency_list.hpp:246:0,from workshop.cpp:12
:./boost/graph/detail/adjacency_list.hpp:1045:5: note: template<class Config> std::pair<typename Config::edge_descriptor, bool> boost::add_edge(typename Config::vertex_descriptor, typename Config::vertex_descriptor, const typename Config::edge_property_type&, boost::undirected_graph_helper<C>&)add_edge(typename Config:
:vertex_descriptor u,
./boost/graph/detail/adjacency_list.hpp:1045:5: note: template argument deduction/substitution failed
:workshop.cpp:123:42: note: candidate expects 4 arguments, 3 providedboost:
:add_edge(from, to, testg);
In file included from ./boost/graph/adjacency_list.hpp:246:0,from workshop.cpp:12
:./boost/graph/detail/adjacency_list.hpp:1075:5: note: template<class Config> std::pair<typename Config::edge_descriptor, bool> boost::add_edge(typename Config::vertex_descriptor, typename Config::vertex_descriptor, boost::undirected_graph_helper<C>&)add_edge(typename Config:
:vertex_descriptor u,
./boost/graph/detail/adjacency_list.hpp:1075:5: note: template argument deduction/substitution failed
:workshop.cpp:123:42: note: mismatched types 'boost::undirected_graph_helper<C>' and 'Graph() {aka boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties, GraphProperties>()}'boost:
:add_edge(from, to, testg);
In file included from ./boost/graph/adjacency_list.hpp:246:0,from workshop.cpp:12
:./boost/graph/detail/adjacency_list.hpp:1473:5: note: template<class Config> std::pair<typename Config::edge_descriptor, bool> boost::add_edge(typename Config::vertex_descriptor, typename Config::vertex_descriptor, const typename Config::edge_property_type&, boost::bidirectional_graph_helper_with_property<Config>&)add_edge(typename Config:
:vertex_descriptor u,
./boost/graph/detail/adjacency_list.hpp:1473:5: note: template argument deduction/substitution failed
:workshop.cpp:123:42: note: candidate expects 4 arguments, 3 providedboost:
:add_edge(from, to, testg);
In file included from ./boost/graph/adjacency_list.hpp:246:0,from workshop.cpp:12
:./boost/graph/detail/adjacency_list.hpp:1503:5: note: template<class Config> std::pair<typename Config::edge_descriptor, bool> boost::add_edge(typename Config::vertex_descriptor, typename Config::vertex_descriptor, boost::bidirectional_graph_helper_with_property<Config>&)add_edge(typename Config:
:vertex_descriptor u,
./boost/graph/detail/adjacency_list.hpp:1503:5: note: template argument deduction/substitution failed
:workshop.cpp:123:42: note: mismatched types 'boost::bidirectional_graph_helper_with_property<Config>' and 'Graph() {aka boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties, GraphProperties>()}'boost:
:add_edge(from, to, testg);
In file included from ./boost/graph/adjacency_list.hpp:246:0,from workshop.cpp:12
:./boost/graph/detail/adjacency_list.hpp:2217:5: note: template<class Graph, class Config, class Base> std::pair<typename Config::edge_descriptor, bool> boost::add_edge(typename Config::vertex_descriptor, typename Config::vertex_descriptor,const typename Config::edge_property_type&, boost::vec_adj_list_impl<G, C, B>&)add_edge(typename Config:
:vertex_descriptor u,
./boost/graph/detail/adjacency_list.hpp:2217:5: note: template argument deduction/substitution failed
:workshop.cpp:123:42: note: candidate expects 4 arguments, 3 providedboost:
:add_edge(from, to, testg);
In file included from ./boost/graph/adjacency_list.hpp:246:0,from workshop.cpp:12
:./boost/graph/detail/adjacency_list.hpp:2231:5: note: template<class Graph, class Config, class Base> std::pair<typename Config::edge_descriptor, bool> boost::add_edge(typename Config::vertex_descriptor, typename Config::vertex_descriptor,boost::vec_adj_list_impl<G, C, B>&)add_edge(typename Config:
:vertex_descriptor u,
./boost/graph/detail/adjacency_list.hpp:2231:5: note: template argument deduction/substitution failed
:workshop.cpp:123:42: note: mismatched types 'boost::vec_adj_list_impl<G, C, B>' and 'Graph() {aka boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties, GraphProperties>()}'boost::add_edge(from, to, testg);