Main.cpp
上传用户:yingjiejs
上传日期:2022-06-05
资源大小:841k
文件大小:4k
源码类别:

GIS编程

开发平台:

Visual C++

  1. /*
  2.  *导游系统的实验代码
  3.  *这里采用是迪杰斯特的算法进行最短路径的寻找
  4.  */ 
  5. #include "Head.h"
  6. //主函数                                       
  7. void  main()
  8. {
  9.     const int numv = 8; //节点的个数                                              
  10. int choose=1,i,j, vv=0,vvt=0;
  11.     int which;//功能选择变量
  12. string name; //插入顶点的值
  13. //这里采用图的邻接矩阵进行存储,其中MAX表示无穷大
  14. //路径长度的矩阵
  15.     int   cost[numv][numv]={                                             
  16. {MAX,130,80,260,MAX,MAX,MAX,MAX},
  17. {130,MAX,MAX,75,MAX,265,MAX,MAX},
  18. {80,MAX,MAX,MAX,50,MAX,MAX,MAX},
  19. {260,75,MAX,MAX,120,85,400,MAX},
  20. {MAX,MAX,50,120,MAX,MAX,350,200},
  21. {MAX,265,MAX,85,MAX,MAX,120,MAX},
  22. {MAX,MAX,MAX,400,350,120,MAX,150},
  23. {MAX,MAX,MAX,MAX,200,MAX,150,MAX}};
  24.   //每一条边的信息
  25.   string   arcifoss[numv][numv]={
  26.   {"11","12","13","14","15","16","17","18"},
  27.   {"21","22","23","24","25","26","27","28"},
  28.   {"31","32","33","34","35","36","37","38"},
  29.   {"41","42","43","44","45","46","47","48"},
  30.   {"51","52","53","54","55","56","57","58"},
  31.   {"61","62","63","64","65","66","67","68"},
  32.   {"71","72","73","74","75","76","77","78"},
  33.   {"81","82","83","84","85","86","87","88"}};
  34.     //每个节点的名字
  35.     string  vname[numv]={"综A学楼","综B教学楼","嘉庚图书馆  ","西苑餐厅  ","计算机学院","尚大楼  ","综合实验楼","校医院    "};     
  36. //代号
  37. string vnos[numv]={"J4","J3","J2","J1","Q4","Q3","Q2","Q1"};
  38.     //简介
  39. string  vifo[numv]={"教学专用","教学专用","用于学生的读书自习","在第五社区的食堂","培养计算机专业学生","行政办公楼","用于做物理实验","学生的日常保健和医疗中心"};
  40.                                                               
  41.                        
  42.     //初始化图
  43. MGraph  G;
  44. InitGraph(G,cost[0], vname,vnos,vifo,arcifoss, numv);
  45.     while ( choose==1 )                                                
  46. {  
  47.   nemu();
  48.       scanf("%d",&which);
  49.       switch( which )                                                 
  50.   {
  51.          
  52.   case 1:  //1.输出顶点信息                                                          
  53.     PutOutVexInfo(G);
  54.    getchar();getchar(); break;
  55.   case 2:  //2.输出边的信息                                                        
  56.      PutOutArcInfo(G);
  57.      getchar();getchar(); break;
  58.       case 3:  // 3.修改某条路径
  59.        printf("改变两个节点间的权重(长度):");
  60.    printf("请输入第一节点:");
  61.    scanf("%d",&i);
  62.    printf("第二个节点值:");
  63.                scanf("%d",&j);
  64.    printf("你要改变的节点是:  从%s  到  %s的权重n",G.vertex[i].c_str(),G.vertex[j].c_str());
  65.                int length;
  66.                printf("请输入从%s  到  %s的权重n",G.vertex[i].c_str(),G.vertex[j].c_str());
  67.                scanf("%d",&length);
  68.    SetArc(G,i,j,length);
  69.       getchar();getchar();break;
  70.  case 4:     // 删除某一条边                                                   
  71.             int pos1;
  72. int pos2;
  73.          printf("请输入两顶点:n");
  74.      scanf("%d %d",&pos1,&pos2);
  75.  DeleteArc(G,pos1,pos2); 
  76.          getchar();getchar();break;
  77.       case 5:     //两地最短的路径                                                     
  78. printf("请输入源顶点:n");
  79. scanf("%d",&vv);
  80.             printf("请输入结束顶点:n");
  81. scanf("%d",&vvt);
  82. Dijkstra(G,vv,vvt,MUL);
  83. getchar();getchar();break;
  84.       case 6:    //到某地最短路径                                                       
  85.  printf("请输入顶点:n");
  86.  scanf("%d",&vv);
  87.  Dijkstra(G,vv,vvt,EVERYONE);
  88.                  getchar();getchar();break;   
  89.       case 7:     //退出
  90.               choose=0;
  91.               getchar();getchar();break;
  92.      }
  93.   }   
  94. }
  95.