本文整理汇总了C++中Graph::GetDistMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ Graph::GetDistMatrix方法的具体用法?C++ Graph::GetDistMatrix怎么用?C++ Graph::GetDistMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph::GetDistMatrix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
if (argc <= 2) {
cerr << "Usage: " << argv[0] << " start end [max_distance]" << endl;
return 1;
}
int start = atoi(argv[1]);
int end = atoi(argv[2]);
int max_distance = (argc >= 4 ? atof(argv[3]) : -1);
Graph graph;
graph.LoadEdgeList(cin);
graph.FloydWarshall();
const vector<vector<int> >& dist_matrix = graph.GetDistMatrix();
cerr << "start: " << start << ", end:" << end << endl;
cerr << "min dist: " << dist_matrix[start][end] << endl;
if (max_distance > 0) {
std::vector<int> new_var_array;
std::vector<int> remove_array;
new_var_array.resize(graph.GetNumberOfVertices() + 1);
int new_vertex_num = 1;
for (int i = 1; i <= graph.GetNumberOfVertices(); ++i) {
if (dist_matrix[start][i] + dist_matrix[i][end] > max_distance) {
remove_array.push_back(i);
} else {
new_var_array[i] = new_vertex_num;
++new_vertex_num;
}
}
//for (unsigned int i = 0; i < remove_array.size(); ++i) {
// cout << remove_array[i] << ", ";
//}
cerr << "rename vertices:" << endl;
for (int i = 1; i <= graph.GetNumberOfVertices(); ++i) {
if (std::find(remove_array.begin(), remove_array.end(), i) == remove_array.end()) {
cerr << i << " -> " << new_var_array[i] << endl;
}
}
graph.RemoveVertices(remove_array, new_var_array);
graph.PrintEdgeList(cout);
}
return 0;
}