本文整理汇总了C++中Graph::GetNumOfVertex方法的典型用法代码示例。如果您正苦于以下问题:C++ Graph::GetNumOfVertex方法的具体用法?C++ Graph::GetNumOfVertex怎么用?C++ Graph::GetNumOfVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph::GetNumOfVertex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Djonson_SelfOrganizationHeap
// Алгоритм Джонсона с использованием алгоритма Дейкстры на самоорганизующейся куче
void Djonson_SelfOrganizationHeap(int** dist, Graph ADJ, int num_vert)
{
Graph AdditionalGraph = ADJ;
AdditionalGraph.AddVertex(ADJ.GetNumOfVertex() + 1);
int* dist_Bellman_Ford = new int[AdditionalGraph.GetNumOfVertex()];// Он будет содержать значения не больше нуля
for(int i = 0; i < AdditionalGraph.GetNumOfVertex() - 1; i++)
AdditionalGraph.AddEdge(AdditionalGraph.GetNumOfVertex() - 1, i, 0);
// Применяем Беллмана-Форда для графа с наличием отрицательных весов ребер
if(Bellman_Ford(dist_Bellman_Ford, AdditionalGraph, AdditionalGraph.GetNumOfVertex(), AdditionalGraph.GetNumOfVertex() - 1))
{
for(ADJ.Reset(); !ADJ.IsEnd(); ADJ.GoNext())// Делаем неотрицательные веса для алгоритма Дейкстры
{
ADJ.SetWeightOfEdge(ADJ.GetCurrVertex(),
ADJ.GetCurrEdge().vertB,
ADJ.GetCurrEdge().weight + dist_Bellman_Ford[ADJ.GetCurrVertex()] - dist_Bellman_Ford[ADJ.GetCurrEdge().vertB]);
}
for(int i = 0; i < ADJ.GetNumOfVertex(); i++)
{
Dijkstra_SelfOrganizationHeap(dist[i], ADJ, ADJ.GetNumOfVertex(), i);
for(int j = 0; j < ADJ.GetNumOfVertex(); j++)
dist[i][j] = dist[i][j] + dist_Bellman_Ford[j] - dist_Bellman_Ford[i];
}
for(ADJ.Reset(); !ADJ.IsEnd(); ADJ.GoNext())// Обратно меняем веса на предыдущие у графа ADJ
{
ADJ.SetWeightOfEdge(ADJ.GetCurrVertex(),
ADJ.GetCurrEdge().vertB,
ADJ.GetCurrEdge().weight + dist_Bellman_Ford[ADJ.GetCurrEdge().vertB ] - dist_Bellman_Ford[ADJ.GetCurrVertex()]);
}
}
else
cout << "Graph contains a cycle of negative weight" << endl;
}
示例2: main
void main()
{
Graph test;
int num_of_vert, num_of_edge, low_lim_weight, up_lim_weight;
double work_time_DJ_LeftHeap = 0.0;
double start_time_DJ_LeftHeap = 0.0;
double end_time_DJ_LeftHeap = 0.0;
double work_time_DJ_DHeap = 0.0;
double start_time_DJ_DHeap = 0.0;
double end_time_DJ_DHeap = 0.0;
double work_time_DJ_SelforganizationHeap = 0.0;
double start_time_DJ_SelforganizationHeap = 0.0;
double end_time_DJ_SelforganizationHeap = 0.0;
bool Exit = false;
int Option;
while(!Exit)
{
cout << "Enter 1 to create a graph: " << endl;
cout << "Enter 2 to show a graph: " << endl;
cout << "Enter 3 to run the algorithm Johnson which uses Dijkstra's algorithm on the left heap: " << endl;
cout << "Enter 4 to run the algorithm Johnson which uses Dijkstra's algorithm on the d-heap: " << endl;
cout << "Enter 5 to run the algorithm Johnson which uses Dijkstra's algorithm on the selforganization heap: " << endl;
cout << "Enter 6 to run the experiments: " << endl;
cout << "Enter 7 to clear the output window: " << endl;
cout << "Enter 0 to close this program: " << endl;
cout << endl;
cin >> Option;
switch(Option)
{
case 1:
{
cout << "Input number of vertexs: " <<endl;
cin >> num_of_vert;
cout << "Input number of edges: " <<endl;
cin >> num_of_edge;
cout << "Input lower limit of weight: " <<endl;
cin >> low_lim_weight;
cout << "Input upper limit of weight: " <<endl;
cin >> up_lim_weight;
Graph test_1(num_of_vert, num_of_edge, low_lim_weight, up_lim_weight);
test = test_1;
break;
}
case 2:
{
if(!test.IsEmpty())
test.ShowGraph();
else
cout << "Graph is empty! " << endl;
cout << endl;
break;
}
case 3:
{
if(!test.IsEmpty())
{
int** table_of_dists;
int Show_table;
table_of_dists = new int*[test.GetNumOfVertex()];
for(int i = 0; i < test.GetNumOfVertex(); i++)
table_of_dists[i] = new int[test.GetNumOfVertex()];
start_time_DJ_LeftHeap = omp_get_wtime();
Djonson_LeftHeap(table_of_dists, test, test.GetNumOfVertex());
end_time_DJ_LeftHeap = omp_get_wtime();
work_time_DJ_LeftHeap = end_time_DJ_LeftHeap - start_time_DJ_LeftHeap;
cout << "Show table of shortest distances? (1 - yes, 0 - no)" << endl;
cin >> Show_table;
cout << endl;
if(Show_table)
{
for(int i = 0; i < test.GetNumOfVertex(); i++)
{
cout << i << ":";
for(int j = 0; j < test.GetNumOfVertex(); j++)
cout << " " <<table_of_dists[i][j];
cout << endl;
}
}
cout << endl;
// Выдать время работы
//.........这里部分代码省略.........