#include "iostream"\n#include "fstream"\n#include "vector"\n#include "boost/graph/adjacency_list.hpp"\n#include "boost/graph/modularity_maximization.hpp"\n\n// 定义图的类型\ntypedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;\n\nint main() {\n std::ifstream file("data.txt"); // 打开数据矩阵文件\n std::vector<std::vector> matrix; // 存储数据矩阵\n\n // 读取数据矩阵到vector\n std::string line;\n while (std::getline(file, line)) {\n std::vector row;\n std::istringstream iss(line);\n int value;\n while (iss >> value) {\n row.push_back(value);\n }\n matrix.push_back(row);\n }\n\n // 创建图\n Graph graph(matrix.size());\n for (int i = 0; i < matrix.size(); i++) {\n for (int j = i + 1; j < matrix.size(); j++) {\n if (matrix[i][j] == 1) {\n boost::add_edge(i, j, graph);\n }\n }\n }\n\n // 计算每个节点的度\n std::vector degrees(boost::num_vertices(graph));\n boost::graph_traits::vertex_iterator vertexIt, vertexEnd;\n for (boost::tie(vertexIt, vertexEnd) = boost::vertices(graph); vertexIt != vertexEnd; ++vertexIt) {\n degrees[*vertexIt] = boost::degree(*vertexIt, graph);\n }\n\n // 计算模块\n std::vector modules(boost::num_vertices(graph));\n double modularity = boost::modularity_maximization(graph, boost::make_iterator_property_map(modules.begin(), boost::get(boost::vertex_index, graph)));\n\n // 输出每个节点的模块和度\n for (int i = 0; i < boost::num_vertices(graph); i++) {\n std::cout << "Node " << i << ": Module " << modules[i] << ", Degree " << degrees[i] << std::endl;\n }\n\n // 输出模块度和模块度增益\n std::cout << "Modularity: " << modularity << std::endl;\n\n return 0;\n}