#include #include #include #include #include #include using namespace boost; class PDGInfo { public: std::string desc; PDGInfo(){} PDGInfo(std::string d) : desc(d){ } }; class PDGNode { public: std::string label; PDGNode()= default; PDGNode(std::string _label) : label(_label){ } bool operator== (PDGNode &other){ return label == other.label; } }; class PDGEdge { public: std::string color; PDGEdge()= default; PDGEdge(std::string c): color(c){ } bool operator== (PDGEdge &other){ return color == other.color; } }; typedef adjacency_list graph_t; graph_t readGraphFromDOTFile(std::string filename){ std::ifstream in; graph_t graph; in.open(filename); if (!in.is_open()) { std::cerr << "Error opening " << filename << "\n"; return graph; } boost::dynamic_properties dp(boost::ignore_other_properties); dp.property("label", get(&PDGNode::label, graph)); dp.property("color", get(&PDGEdge::color, graph)); bool status = boost::read_graphviz(in, graph, dp); return graph; } template class custom_callback_mcgregor { public: custom_callback_mcgregor(const Graph1 &graph1, const Graph2 &graph2, int targetSize) : graph1_(graph1), graph2_(graph2), targetSize_(targetSize) {} template bool operator()(CorrespondenceMap1To2, CorrespondenceMap2To1,typename graph_traits::vertices_size_type subgraph_size) { if(subgraph_size == targetSize_){ std::cerr << "Size: " << subgraph_size << "\n"; return false; }else{ return true; } } private: int targetSize_; const Graph1 &graph1_; const Graph2 &graph2_; }; bool sufficient_mcgregor_common_subgraph(float factor, graph_t graph1, graph_t graph2){ int targetSize = (num_vertices(graph1) > num_vertices(graph2)) ? num_vertices(graph2) : num_vertices(graph1); targetSize = targetSize * factor; custom_callback_mcgregor callback(graph1, graph2, targetSize); mcgregor_common_subgraphs_unique(graph1, graph2, true, callback, edges_equivalent(make_property_map_equivalent(get(edge_bundle, graph1), get(edge_bundle, graph2))). vertices_equivalent(make_property_map_equivalent(get(vertex_bundle, graph1), get(vertex_bundle, graph2)))); return false; } int main(int argc, char **argv){ float factor = atof(argv[1]); std::cout << "Factor " << factor << std::endl; graph_t g1 = readGraphFromDOTFile(argv[2]); graph_t g2 = readGraphFromDOTFile(argv[3]); sufficient_mcgregor_common_subgraph(factor, g1, g2); return 0; }