我生成了这段代码来测试一个随机无向图 100 次,并随机生成图的节点和权重。我的问题是,当我尝试通过调用最小距离来存储最短路径时出现问题,当我返回列表的大小时,它始终为 1。出了什么问题?
// Random Graph Generator
for (int n = 1; n <= 101; ++n)
{
int r = 0;
nodeCount = 10; //rand() % 8128 + 64;
while (r <= nodeCount)
{
++r;
int nodeNumb = (rand() % 6); // Generates a possible node from 0 to 6 (seven possiblities)
int nodeDest = (rand() % 6); // Generates a possible node destination the same as above
int node_weight = rand() % 100 + 1; // Generate random weight of node from 1 to 101
// Create adjacency list
adjacency_list[nodeNumb].push_back(neighbourer(nodeDest, node_weight));
// For undirected graph create opposite connection back
adjacency_list[nodeDest].push_back(neighbourer(nodeNumb, node_weight));
}
vector<weight_w> min_distance; // declare vector for minimum distance
vector<vertex_v> previous; // declare vector to hold previos
int origin = 3; // origin to be inputted
int destination = 5; // destination to be inputted
list<double> pathCount;
DijkstraComputePaths(origin, adjacency_list, min_distance, previous);
pathCount.push_back(min_distance[destination]);
for (int deleteIterator = 0; deleteIterator <= 6; ++deleteIterator)
{
adjacency_list[deleteIterator].clear();
}
cout << "The List Size is: " << pathCount.size() << endl;
}