数据结构课程设计报告之模拟一个全国城市间的交通咨询程序文件
- 格式:doc
- 大小:340.50 KB
- 文档页数:55
.郑州工业应用技术学院课程设计任务书题目全国交通资询系统主要内容:设计了一个方便用户查询交通咨询系统。
该系统所做的工作的是模拟全国交通咨询,为旅客提供三种最优决策的交通咨询。
该系统可以进行城市,列车车次和飞机航班的编辑的基本信息输入操作。
程序的输出信息主要是:最快需要多少时间才能到达,或最少需要多少旅费才能到达,或最少需要多少次中转到达,并详细说明依次于何时乘坐哪一趟列车或哪一次班机到何地。
程序的功能包括:提供对城市信息的编辑,提供列车时刻表和飞机航班表的编辑,提供三种最优决策:最快到达、最省钱到达、最少中转次数到达。
基本要求:1、掌握C语言的变量及函数的灵活使用;2、熟练掌握图的深度、广度优先遍历算法思想及其程序实现;3、掌握C语言中文件的基本操作;4、掌握VC++6.0软件的熟练使用。
主要参考资料:[1] 李春葆.数据结构程序设计[M].北京:清华大学出版社,2002,03[2] 王黎,袁永康战略[M].北京:清华大学出版社,2002,01[3] 谭浩强.C程序设计第二版[M].北京:清华大学出版社,2003,03[4] 任哲.MFC Windows程序设计[M].北京:清华大学出版社,2004,06完成期限:2016.12.05—2017.01.05指导教师签名:课程负责人签名:随着高科技的飞速发展,列车、飞机、动车、高铁的出现极大的减少了人们花在旅途上的时间。
对于城市间错综复杂交通网的管理,是一项庞大而复杂的工作。
在此基础上,如何实现交通网智能化的管理达到帮助乘客选择经济高效的交通工具是目前仍处空白。
尤其乘客交通工具的择优选择是一个令人懊恼的工作,一个原因就是各种交通工具的查询十分分散和繁琐。
即使有互联网的帮忙,但是没有一个统一的归类、没有一个精细的算法、系统的软件帮助,人们仍然无法获得最优方式。
为此开发一个交通择优系统是十分必要的。
采用计算机对城市间的交通工具进行系统录入和管理,进一步提高了交通部门针对城市间客运网络的管理效率,实现交通运营网络的系统化、规范化和自动化。
浙江工商大学计算机与信息工程学院数据结构实验大作业报告专业:物流1001班级: 1001学号:姓名:金渐指导教师:庄毅2011年12月8日一、问题描述处于对不同目的的旅客对交通工具有不同的要求。
例如,因公出差的旅客希望在旅途中的时间尽可能短,出门旅游的游客则希望旅费尽可能省,而老年旅客则要求中转次数最少。
编制一个全国城市间的交通咨询程序,为旅客提供两种或三种最优决策的交通咨询。
【基本要求】(1)提供对城市信息进行编辑(如:添加或删除)的功能。
(2)城市之间有两种交通工具:火车和飞机。
提供对列车时刻表和飞机航班进行编辑(增设或删除)的功能。
(3)提供两种最优决策:最快到达或最省钱到达。
全程只考虑一种交通工具。
(4)旅途中耗费的总时间应该包括中转站的等候时间。
(5)咨询以用户和计算机的对话方式进行。
由用户输入起始站、终点站、最优决策原则和交通工具,输出信息:最快需要多长时间才能到达或者最少需要多少旅费才能到达,并详细说明依次于何时乘坐哪一趟列车或哪一次班机到何地。
系统框图:模块说明:本系统共分1、23、4、删除城市5、添加列车6、添加航班7、删除列车或航班8、找出最小费用路线9、打印出最小费用路线10、初始化系统数据(读入内存)11、找出最快路线12、计算最快路线耗费的时间并打印13、计算最小费用路线14、主界面15、存储信息到文件16、退出下面是系统总流程图:下面是各模块示意图:三、系统测试1、主界面2、添加城市模块:输入命令 1 后,将提示输入城市名,而后返回主界面3、删除城市:输入命令2后,提示输入城市名,而后返回主界面4、添加交通路线:输入命令3,提示输入起点站和重点站,并提示选择火车或飞机,而后输入班次、出发时间、到达时间、票价,而后返回主界面原train文件:添加路线后:5、删除路线:输入命令4,输入班次,而后返回主界面原train文件:删除后ttrain文件:6、查询最小费用路线:输入命令5,并输入起点站和重点站,然后选择交通工具结果正确!7、查询时间最短路线:输入命令6,并输入起点站和重点站,然后选择交通工具四、小结从小学家里买了电脑起,我对计算机就相当感兴趣,有事没事就喜欢捣鼓捣鼓。
数据结构课程设计-全国交通咨询模拟系统程序设计源代码一、程序界面A.关于程序1. 该程序以C语言为开发工具,运行该程序前请确保你的机器上已安装tc或turboc ,否则系统会提示:BGI Error: Graphics not initialized (use 'initgraph')而无法使用该程序。
遇到此情况请安装tc ,建议将其安装到C:目录下,以确保程序运行万无一失。
2. 该软件完全支持鼠标,请放心使用。
3. 该程序能将您输入的城市转换为象素坐标,显示在屏幕上,操作直观方便,选择城市时,用时标一点该城市即可,省去了输入的麻烦。
如果您选择的两个城市间有路径的话,程序除了给您信息输出外,还会在地图上将此路径以不同颜色画出,更加直观。
4. 该程序附带三个数据文件(num.txt,vex.t xt,len.txt --此文件由系统默认)以供用户调试,用户还可自己创建文件,以备实验查询使用.B. 程序的使用用户打开程序,会看到命令行: FILE CHANGE SHORTWAY MAP HELP ABOUT QUIT CLRSCR用户将鼠标放于某命令上会看到屏幕最下面有一行字在闪动,这是对命令的解释,如当鼠标访于FILE上时其下解释"press this button to open/creat a file" ,当鼠标空闲时在下面显示:"Please Enter Your Choice With Mouse Or Keyboard" ,提示用户进行命令选择.单机鼠标就会将某一功能打开从而进行某一操作2.用户运行程序时请先打开 FILE 菜单,该菜单有4个命令选项:[ 信息提示 ]1. 调用已存信息库文件(由用户提供)2. 创建新的信息库文件3. 调用演示信息库文件4. 退出程序[ 请输入你的选择(1/2/3/4) ]此时程序等待用户输入选择.输入正确后程序会自动打开地图由用户进行下一步操作.3. 对于其他命令,用户可由显示于屏幕下面的提示进行相关操作.二.程序内部设计及数据结构A. 数据的存放格式1.火车信息数据结构定义:typedef struct inf{ int num;/*车次*/int stt1;int stt2;/*出发时间*/int endt1;int endt2;/*到达时间*/int waitt;/*等待时间*/int allt;/*两站之间总耗时*/int money;/*票价*/}inf2.车站信息数据结构定义:typedef struct ArcCell{int ff;/*ff=1 表示两点有信息*/int adj;/*路程长度*/inf two;/*火车信息* /}ArcCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM]; 3.图的数据结构定义typedef struct Mgraph{ char vexs[MAX_VERTEX_NUM][MAX_VERTEX_NUM];/*顶点名*/AdjMatrix arcs;/* 车站信息*/int vexsx[MAX_VERTEX_NUM];/*该顶点的X坐标*/int vexsy[MAX_VERTEX_NUM]; /*该顶点的Y坐标*/int vexnum,arcnum; /* vexnum:顶点的数目,arcnum:路线数目*/}Mgraph;4.基于以上数据结构的数据存储举例:(以下为部分顶点信息)wulumuqi 49 59(表示城市wulumuqi 在640X480的屏幕中位于坐标49,59处,下同)xining 97 155lanzhou 121 174(以下为部分路线信息)wulumuqi lanzhou 1 1892 1001 1 0 12 0 10 670 150(表示从城市wulumuqi 到城市lanzhou 有信息…1?,路线长度为1892,车次为1001,从城市wulumuqi开出时间为1:00,到lanzhou站时间为12:00,在lanzhou 停留10分钟,总耗时670分钟(总耗时由系统自动计算出),车票报价150元。
数据结构课程设计报告题目:全国交通咨询模拟一.需求分析1.程序设计任务:从中国地图平面图中选取部分城市,抽象为程序所需要图的结点,并以城市间的列车路线和飞机路线,作为图结点中的弧信息,设计一个全国交通咨询模拟系统。
利用该系统实现两种最优决策:最快到达或最省钱到达。
2. 明确规定:(1)输入形式和输入值的范围:每条飞机弧或者火车弧涉及的信息量很多,包括:起始城市、目的城市、出发时间、到达时间、班次以及费用。
作为管理员要输入的信息包括以上信息,而作为用户或者客户,要输入的信息有起始城市和目的城市,并选择何种最优决策。
(2)输出形式:按用户提供的最优决策的不同而输出不同的信息,其中输出的所搭飞机或火车的班次及其起始地点和终点、起始时间和出发时间还有相关的最优信息,比如最快经多少时间到达、最省钱多少钱到达和最少经多少中转站到达。
(3)程序所能达到的功能a.该系统有供用户选择的菜单和交互性。
可以对城市、列车车次和飞机航班进行编辑,添加或删除。
b.建立一个全国交通咨询系统,该系统具备自动查找任意两城市间铁路、飞机交通的最短路径和最少花费及中转次数最少等功能。
c.初始化交通系统有两种方式,键盘和文档。
二.设计概要1. 算法设计(1)、总体设计(1) 数据存储:城市信息(城市名、代码)、交通信息(城市间的里程、各航班和列车时刻)存储于磁盘文件。
建议把城市信息存于文件前面,交通信息存于文件的后面,用fread和fwrite函数操作。
(2) 数据的逻辑结构:根据设计任务的描述,其城市之间的旅游交通问题是典型的图结构,可看作为有向图,图的顶点是城市,边是城市之间所耗费的时间(要包括中转站的等候时间)或旅费。
(3) 数据的存储结构:采用邻接表和邻接矩阵都可作为数据的存储结构,但当邻接边不多时,宜采用邻接表,以提高空间的存储效率。
这里采用邻接表作为数据的存储结构。
(4) 用不同的功能模块对城市信息和交通信息进行编辑。
添加、修改、删除功能可用菜单方式或命令提示方式。
X X 学院计算机系《数据结构》课程设计报告书全国交通咨询模拟系统的设计与实现学生姓名:学号:年级专业及班级:指导老师及职称:讲师专业:计算机科学与技术专业提交日期:2011年6月全国交通咨询模拟系统的设计与实现学生:指导老师:(怀化学院计算机系,怀化418008)摘要:该课程设计主要实现了对全国火车及飞机信息的修改和查询,其中主要包括:管理员对火车、飞机信息的操作,其中又包含对两种交通方式的增加和删除操作.旅客用户对两种交通信息的查询,其中飞机信息和火车信息都包含了对两个站点间最短路径方式的查询、最少花费方式的查询以及城市中所有的交通信息的查询.关键词:全国交通咨询;1前言为了完成数据结构的课程设计,为了巩固自己数据结构的知识,也是为了提高自己的编程能力和逻辑思维能力,我选了这道全国交通咨询模拟系统的设计与实现一题。
在对其需求进行分析之后,按照需求分析,逐步完成其各部分的功能实现.对于总的方面来讲,管理员功能实现并不难,而难点在于用户功能中的算法及数据结构中的知识以及编程的细微方面,下面将详细介绍本课程设计的内容.2需求分析2.1 范围2.1。
2 系统概述1.软件名称:全国交通咨询系统V1.02.软件功能:主要的功能有:管理员增删和修改城市站点信息、飞机路线信息、火车路线信息。
3.用户:查询最小耗费路线、查询最短时间路线、查询城市所有路线.4.开发者:2.1.3 文档概述需求分析采用在面向对象的方法,主要使用结构体struct的方法来进行实际的编程,在文档中主要采E—R图和对功能的简单描述的方法来表述系统的需求。
本需求分析的审查者是老师,所以主要是写给老师看的,用来说明我对这个系统的分析情况。
2.2 引用文件无2.3 需求概述2.3。
1 系统目标本系统的总体目标是通过使用该系统,管理员可以对飞机或者火车的信息的简单管理,也方便外出旅客在不同的需求下(如:最少的花费和最短的路程),快速浏览到所要的信息。
.郑州工业应用技术学院课程设计任务书题目全国交通资询系统主要内容:设计了一个方便用户查询交通咨询系统。
该系统所做的工作的是模拟全国交通咨询,为旅客提供三种最优决策的交通咨询。
该系统可以进行城市,列车车次和飞机航班的编辑的基本信息输入操作。
程序的输出信息主要是:最快需要多少时间才能到达,或最少需要多少旅费才能到达,或最少需要多少次中转到达,并详细说明依次于何时乘坐哪一趟列车或哪一次班机到何地。
程序的功能包括:提供对城市信息的编辑,提供列车时刻表和飞机航班表的编辑,提供三种最优决策:最快到达、最省钱到达、最少中转次数到达。
基本要求:1、掌握C语言的变量及函数的灵活使用;2、熟练掌握图的深度、广度优先遍历算法思想及其程序实现;3、掌握C语言中文件的基本操作;4、掌握VC++6.0软件的熟练使用。
主要参考资料:[1] 李春葆.数据结构程序设计[M].北京:清华大学出版社,2002,03[2] 王黎,袁永康战略[M].北京:清华大学出版社,2002,01[3] 谭浩强.C程序设计第二版[M].北京:清华大学出版社,2003,03[4] 任哲.MFC Windows程序设计[M].北京:清华大学出版社,2004,06完成期限:2016.12.05—2017.01.05指导教师签名:课程负责人签名:随着高科技的飞速发展,列车、飞机、动车、高铁的出现极大的减少了人们花在旅途上的时间。
对于城市间错综复杂交通网的管理,是一项庞大而复杂的工作。
在此基础上,如何实现交通网智能化的管理达到帮助乘客选择经济高效的交通工具是目前仍处空白。
尤其乘客交通工具的择优选择是一个令人懊恼的工作,一个原因就是各种交通工具的查询十分分散和繁琐。
即使有互联网的帮忙,但是没有一个统一的归类、没有一个精细的算法、系统的软件帮助,人们仍然无法获得最优方式。
为此开发一个交通择优系统是十分必要的。
采用计算机对城市间的交通工具进行系统录入和管理,进一步提高了交通部门针对城市间客运网络的管理效率,实现交通运营网络的系统化、规范化和自动化。
2数据结构——全国交通咨询模拟系统实验报告
实验目的:
实验环境:
本次实验的开发环境为Java编程语言,使用了面向对象的编程思想,采用了数据结构中的图和链表等数据结构。
实验内容:
1.设计交通工具类:
首先,根据系统需求,设计了交通工具类,该类用于表示交通工具的
基本信息,包括交通工具的名称、班次、票价等。
在该类中,使用了链表
数据结构来存储交通工具的班次信息。
2.设计城市类:
接下来,设计了城市类,用于表示各个城市的交通信息。
在该类中,
使用了图数据结构来表示城市之间的联通关系,每个城市作为图的一个节点,城市间的交通工具作为图的边。
实验结果:
经过测试,实验系统能够准确地输出起点城市到终点城市的最短路径
和最佳交通方案,用户可以根据输出信息来决定如何安排旅行计划。
实验总结:。
数据结构课程设计报告班级:195182学号:20181003991姓名:钟欢日期:2019.12一、课程设计题目与要求1.课程设计题目:全国交通咨询模拟2.问题描述:出于不同目的的旅客对交通工具有不同的要求。
例如,因公出差的旅客希望在旅途中的时间尽可能短,出门旅游的游客则期望旅费尽可能省,而老年旅客则要求中转次数最少。
编制一个全国城市间的交通咨询程序,为旅客提供两种或三种最优决策的交通咨询。
3.基本要求:3.1提供对城市信息进行编辑(如添加或删除)的功能。
3.2城市之间有两种交通工具:火车和飞机。
提供对列车时刻表和飞机航班进行编辑(增加或删除)的功能。
3.3提供两种最优决策:最快到达或最省钱到达。
全程只考虑一种交通工具。
3.4旅途中耗费的总时间应该包括中转站的等候时间。
3.5咨询以用户和计算机的对话方式进行。
二、需求分析1.问题描述搭建一个全国交通咨询模拟系统,可以实现简单的人机互动从而达到咨询的效果。
需要完成的功能有,对城市、列车时刻表、航班时刻表进行编辑(手动/文件添加,删除),能够根据出发城市以及到达城市进行相关线路推荐(花费最少线路、耗时最短线路),其中整个线路的耗时总时长包括中转等待时间。
2.程序的功能:2.1维护功能:2.1.1航班操作2.1.2列车操作2.1.3更改密码2.2咨询功能2.2.1选择出行交通工具2.2.2选择要查询的信息:○1查询花费最小的路径○2查询耗时最短的路径2.2.3进行进一步的输入得到所需要的结果三、设计1.设计思想1.1数据结构设计1.1.1逻辑结构设计采用图结构来表示该全国交通网络,用一个结构体来表示时间,结构体内有标准化的(天,时,分)的相关表示以及操作,重载的运算符“-”。
全国交通网络中的城市用结点表示,两个城市之间的航线或者列车线用两个结点之间的边来表示。
城市结点中包含城市名字、城市编号、第一条航线/列车线以及航线/列车线的数目;边结点中包含到达城市名称,指向下一航线/列车线的指针,以及指向该边所指代航线/列车线信息的指针;航班线/列车线信息结点包含航班号/列车号,出发时间,到达时间,花费时间,花费金额。
一、课程设计概述:使用语言:java编译环境:java虚拟机二、课程设计题目一[实验内容]全国交通咨询模拟[问题描述]1、管理员可以添加、修改、删除各交通路线信息。
2、用户查询从某一地点到另一地点的信息,提供查询转车次数最少、花费最少、所用时间最少的相关信息。
[需求分析]1、管理员和用户拥有不同的操作界面。
管理员从键盘输入个交通路线并保存在trainInformation.txt中。
2、对文件trainInformation.txt中的数据进行处理,要求具有如下功能:①、城市信息进行编辑。
②、对列车时刻表进行编辑(增设或删除)的功能。
③、提供三种最优决策:最省钱到达,转车最少。
④、提供各列车详细信息。
3、界面美观[概要设计]class MoneyLeast{}//求出两站点花费最少的路径class TrainContral{}//从文件中读出列车的所有信息或者将列车的信息写入到文件class TrainGraph{}//列车航线交通图class AdmFrame{}//管理员登陆界面class SearchInFrame{}//用户查询信息和显示信息界面[存储结构]class City{//城市存储private String cityName;}class Train {//列车存储private String trainID;private City startCity;private City endCity;private Date startDate;private Date endDate;private int money;}[详细设计]---City----/*** 城市的对象* 城市有城市名* 实现序列化* 重写equals方法和toString方法*/package com.consel;import java.io.Serializable;//实现序列化的接口public class City implements Serializable {private static final long serialVersionUID = 5612649006026227701L;private String cityName;public City(String cityName) {this.cityName = cityName;}public String getCityName() {return cityName;}public void setCityName(String cityName) {this.cityName = cityName;}@Overridepublic String toString() {return cityName;}@Overridepublic boolean equals(Object obj) {if (obj instanceof City) {City temp = (City) obj;if (this.cityName.equals(temp.cityName)) {return true;}}return false;}}----MoneyLeast-----/*** MoneyLeast 查找从花费最少的路径,及乘车路径* 使用的是普里姆算法*/package com.consel;public class MoneyLeast {final static int maxMoney = 10000;int n;int[] s;//s用来存储n个节点的标记int minMoney, u = 0;//t为列车信息图,c为起始城市,数组money是用来存储最少花费的路径,path是用来存储节点的上一节点public void leastMoney(TrainGraph t, City c, int[] money, City[] path) throws Exception {n = t.getNumOfVer();s = new int[n];for (int i = 0; i < n; i++) {money[i] = t.getMoney(c, t.city.get(i));s[i] = 0;if (money[i] < maxMoney) {path[i] = c;} else {path[i] = null;}}s[t.city.indexOf(c)] = 1;for (int i = 0; i < n; i++) {minMoney = maxMoney;for (int j = 0; j < n; j++) {if (s[j] == 0 && money[j] < minMoney) {u = j;minMoney = money[j];}}if (minMoney == maxMoney) {return;}s[u] = 1;City city = t.city.get(u);for (int j = 0; j < n; j++) {if (s[j] == 0 && t.getMoney(city, t.city.get(j)) < maxMoney &&money[u] + t.getMoney(city, t.city.get(j)) < money[j]) {money[j] = money[u] + t.getMoney(city, t.city.get(j));path[j] = city;}}}}}----MoneyTest-----package com.consel;import java.util.Iterator;import java.util.Stack;public class MoneyTest {MoneyLeast ml = new MoneyLeast();TrainGraph tg = new TrainGraph();int[] money;City[] path;public Stack<Train> st = new Stack<Train>();public MoneyTest() {int n = tg.city.size();money = new int[n];path = new City[n];for (int i = 0; i < n; i++) {money[i] = tg.maxMoney;path[i] = null;}}public Stack findMoneyLeast(City c1,City c2) throws Exception{ml.leastMoney(tg, c1,money, path);Stack<City> s = new Stack();s.add(c2);while (!c2.equals(c1)) {City c3 = path[tg.city.indexOf(c2)];s.add(c3);TrainContral ct = new TrainContral();ct.trainRead();Iterator<Train> i = ct.train.iterator();while(i.hasNext()){Train temp = i.next();if(temp.getStartCity().equals(c3) && temp.getEndCity().equals(c2)){st.add(temp);}}c2 = c3;}return s;}}----Train-----/*** Train 序列化,存储列车的信息,包括ID,起始站,终点站,发车时间,到站时间,价格*/package com.consel;import java.util.*;import java.io.Serializable;public class Train implements Serializable {private static final long serialVersionUID = 5612649006026227700L;private String trainID;//列车号private City startCity;//起始站private City endCity;//终点站private Date startDate;//发车时间private Date endDate;//到站时间private int money;//价格public Train(String trainID, City startCity, City endCity, Date startDate, Date endDate, int money) {this.trainID = trainID;this.startCity = startCity;this.endCity = endCity;this.startDate = startDate;this.endDate = endDate;this.money = money;/*** @return the trainID*/public String getTrainID() { return trainID;}/*** @return the money*/public int getMoney() {return money;}/*** @return the startCity*/public City getStartCity() { return startCity;}/*** @return the endCity*/public City getEndCity() { return endCity;}/*** @return the startDate */public Date getStartDate() { return startDate;}/*** @return the endDatepublic Date getEndDate() {return endDate;}}-----TrainContral------/*** TrainContral 从文件trainInformation.txt中读出各列车信息或将各列车信息写入到文件trainInformation.txt中*/package com.consel;import java.io.*;import java.util.*;public class TrainContral {File filename = new File("config/trainInformation.txt");ObjectInputStream ois;ObjectOutputStream oos;public List<Train> train = new ArrayList<Train>();/** 从trainInformation.txt读出所有列车的信息* 并存储于链表train中*/public void trainRead() {try {ois = new ObjectInputStream(new FileInputStream(filename));//文件输入流train = (List<Train>) ois.readObject();} catch (FileNotFoundException ex) {ex.printStackTrace();} catch (IOException ex) {ex.printStackTrace();} catch (ClassNotFoundException ex) {ex.printStackTrace();} finally {try {ois.close();// 关闭文件输入流} catch (Exception exx) {exx.printStackTrace();}}}/*** 将链表t中的所有火车信息写入到trainInformation.txt中* @param t*/public void trainWrite(List<Train> t) {try {oos = new ObjectOutputStream(new FileOutputStream(filename));// 文件输出流oos.writeObject(t);} catch (FileNotFoundException ex) {ex.printStackTrace();} catch (IOException ex) {ex.printStackTrace();} finally {try {oos.flush();//关闭文件缓冲流oos.close();//关闭文件流} catch (Exception exx) {exx.printStackTrace();}}}}------TrainGraph-------/*** TrainGraph 表示所有列车的信息* 查找以一个城市作为起点站,可以到达的另一个城市*/package com.consel;import java.util.*;public class TrainGraph {final static int maxMoney = 10000;List<City> city = new ArrayList<City>();TrainContral tc = new TrainContral();int[][] edges;public List<Train> train;Stack stack1 = new Stack();public Stack<City> stack = new Stack();/*临时保存路径节点的栈*/ public ArrayList<Stack> sers = new ArrayList();/*存储路径的集合*/public int getNumOfVer() {return city.size();}public TrainGraph() {//构造方法tc.trainRead();//从文件中读出所有列车的信息int n = tc.train.size();train = tc.train;Iterator it = train.iterator();/*** 存储交通路线中所有涉及到的城市*/while (it.hasNext()) {Train t = (Train) it.next();City c1 = t.getStartCity();City c2 = t.getEndCity();int x = city.indexOf(c1);int y = city.indexOf(c2);if (x < 0) {}if (y < 0) {city.add(c2);}}edges = new int[city.size()][city.size()];for (int i = 0; i < city.size(); i++) {for (int j = 0; j < city.size(); j++) {edges[i][j] = 0;}}it = tc.train.iterator();while (it.hasNext()) {Train t = (Train) it.next();City c1 = t.getStartCity();City c2 = t.getEndCity();int x = city.indexOf(c1);int y = city.indexOf(c2);edges[x][y] = 1;}}//以c为起始站的第一个终点站public int getFirstNeighbor(City c) throws Exception { int n = city.indexOf(c);if (n >= 0) {return getFirstNeighbor(n);}return - 1;}//查找邻接的城市private int getFirstNeighbor(int v) throws Exception { if (v < 0 || v > city.size()) {throw new Exception("参数错误!");}for (int col = 0; col < city.size(); col++) {if (edges[v][col] > 0) {}}return -1;}//查找下一个邻接城市public int getNextNeighbor(City c1, City c2) throws Exception { int m = city.indexOf(c1);int n = city.indexOf(c2);if (m >= 0 && n >= 0) {return getNextNeighbor(m, n);}return -1;}//查找下一个邻接城市private int getNextNeighbor(int v1, int v2) throws Exception { if (v1 < 0 || v1 > city.size() || v2 < 0 || v2 > city.size()) {throw new Exception("参数错误!");}for (int col = v2 + 1; col < city.size(); col++) {if (edges[v1][col] > 0) {return col;}}return -1;}//返回从c1到c2直达所花费的钱public int getMoney(City c1, City c2) throws Exception { int m = city.indexOf(c1);int n = city.indexOf(c2);if (m < 0 || n < 0) {throw new Exception("城市C1或C2错误!");} else {Iterator<Train> i = train.iterator();boolean flag = false;while (i.hasNext()) {temp = i.next();if (temp.getStartCity().equals(c1) && temp.getEndCity().equals(c2)) { flag = true;break;}}if (flag) {return temp.getMoney();} else {return maxMoney;}}}private boolean isCityInStack(City city) {//判断节点是否在栈中Iterator<City> it = stack.iterator();while (it.hasNext()) {City node1 = it.next();if (city.equals(node1)) {return true;}}return false;}// 存储一条通路private void savePath() {Stack<City> temp = new Stack();Iterator<City> i = stack.iterator();while (i.hasNext()) {City c = i.next();temp.add(c);}sers.add(temp); /*转储*/}// 查找从startCity到endCity的所有路径public void getPaths(City startCity, City endCity) throws Exception {stack.push(startCity);int n = getFirstNeighbor(startCity);if (n >= 0) {City c = city.get(n);getPaths(startCity, endCity, c, startCity);while (c != null) {n = getNextNeighbor(startCity, c);if (n > 0) {c = city.get(n);getPaths(startCity, endCity, c, startCity);} else {c = null;}}}}// 用递归的方法求startCity到endCity的路径currentCity是当前的城市,perCity是currentCity的上一个城市private boolean getPaths(City startCity, City endCity, City currentCity, City perCity) throws Exception {City nCity = null;if (currentCity != null && perCity != null && currentCity.equals(perCity)) { return false;}if (currentCity != null) {stack.push(currentCity);if (currentCity.equals(endCity)) {savePath();stack.pop();return true;} else {int n = getFirstNeighbor(currentCity);if (n >= 0) {nCity = city.get(n);} else {nCity = null;}while (nCity != null) {if (perCity != null && (nCity.equals(startCity) || perCity.equals(nCity) || isCityInStack(nCity))) {n = getNextNeighbor(currentCity, nCity);if (n >= 0) {nCity = city.get(n);} else {nCity = null;}continue;}if (getPaths(startCity, endCity, nCity, currentCity)) {if (!stack.isEmpty()) {stack.pop();}}n = getNextNeighbor(currentCity, nCity);if (n >= 0) {nCity = city.get(n);} else {nCity = null;}}if (!stack.isEmpty()) {stack.pop();}return false;}} else {return false;}}}-----AdmFrame-------/** 管理员登陆界面* 用户名为:Adm* 口令为:123456*/package com.desgin;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class AdmFrame {ImageIcon img = new ImageIcon("config/Adm.gif");JLabel background = new JLabel(img);JFrame admFrame = new JFrame();JLabel user = new JLabel("用户名:");JTextField userInput = new JTextField(20);JLabel passWord = new JLabel("口令:");JPasswordField passWordIn = new JPasswordField(20);JPanel panel = new JPanel();JButton login = new JButton("登陆");JButton exit = new JButton("退出");public AdmFrame() {admFrame.setLayout(null);admFrame.setTitle("Administrator");admFrame.setSize(img.getIconWidth(), img.getIconHeight() + 20);admFrame.setLocationRelativeTo(null);admFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);panel.setLayout(new GridLayout(2, 2, 20, 20));panel.add(user);user.setHorizontalAlignment(JTextField.RIGHT);passWord.setHorizontalAlignment(JTextField.RIGHT);panel.add(userInput);panel.add(passWord);panel.add(passWordIn);panel.setBounds(40, 50, 250, 60);JPanel tempPanel = new JPanel();tempPanel.add(login);tempPanel.add(exit);tempPanel.setBounds(130, 130, 200, 40);admFrame.add(panel);admFrame.add(tempPanel);admFrame.add(background);background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());admFrame.setVisible(true);admFrame.setResizable(false);exit.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {System.exit(0);}});login.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {if (userInput.getText().trim().equals("") || passWordIn.getText().trim().equals("")) {JOptionPane.showMessageDialog(null, "请输入用户名或口令!","Warning", JOptionPane.WARNING_MESSAGE);} else if (userInput.getText().equals("Adm") && passWordIn.getText().equals("123456")) {admFrame.dispose();AdmMainWindow amw = new AdmMainWindow();amw.setVisible(true);} else {JOptionPane.showMessageDialog(null, "用户名或口令错误,请重新输入!","用户名或口令错误", JOptionPane.ERROR_MESSAGE);}}});}public static void main(String[] args) {AdmFrame af = new AdmFrame();}}-----AdmMFListener-------/** 管理员登陆后的界面监听器* 对添加、修改、删除作出相应的变化*/package com.desgin;import com.consel.*;import com.consel.TrainContral;import java.awt.event.*;import java.util.*;import javax.swing.JOptionPane;public class AdmMFListener extends MouseAdapter {AdmMainWindow amw;public AdmMFListener(AdmMainWindow amw) {this.amw = amw;}/** 鼠标点击事件监听*/@Overridepublic void mouseClicked(MouseEvent e) {if (e.getSource() == amw.add) {ChangeDialog cd = new ChangeDialog(amw, "添加", true);cd.setVisible(true);}if (e.getSource() == amw.change) {int selectedRow = amw.table.getSelectedRow();if (selectedRow > -1) {ChangeDialog cd = new ChangeDialog(amw, "添加", true,(String) amw.table.getValueAt(selectedRow, 0));cd.setVisible(true);} else {JOptionPane.showMessageDialog(null, "请选中要修改对象","Warnnig", JOptionPane.WARNING_MESSAGE);}}if (e.getSource() == amw.exit) {amw.dispose();}if (e.getSource() == amw.delete) {int selectedRow = amw.table.getSelectedRow();if (selectedRow > -1) {TrainContral tc = new TrainContral();tc.trainRead();Iterator<Train> i = tc.train.iterator();while (i.hasNext()) {Train temp = i.next();if (temp.getTrainID().equals(amw.table.getValueAt(selectedRow, 0))) {i.remove();tc.trainWrite(tc.train);break;}}amw.table.setModel(new AdmTable());} else {JOptionPane.showMessageDialog(null, "请选中要删除对象","Warnnig", JOptionPane.WARNING_MESSAGE);}}}}------AdmMainWindow-------/*** 管理员管理列车信息的主界面* 显示所有列车的相关信息*/package com.desgin;import javax.swing.*;public class AdmMainWindow extends JFrame {JTable table;JScrollPane jsp;AdmTable model = new AdmTable();JButton change = new JButton("修改");JButton add = new JButton("添加");JButton delete = new JButton("删除");JButton exit = new JButton("退出");AdmMFListener amfl;public AdmMainWindow() {this.setTitle("Administrator");this.setSize(400, 300);this.setLocationRelativeTo(null);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);amfl = new AdmMFListener(this);table = new JTable(model);jsp = new JScrollPane(table);JPanel panel = new JPanel();panel.add(add);add.addMouseListener(amfl);panel.add(change);change.addMouseListener(amfl);panel.add(delete);delete.addMouseListener(amfl);panel.add(exit);exit.addMouseListener(amfl);this.add(jsp, "Center");this.add(new JLabel(" "), "North");this.add(panel, "South");}}-----AdmTable------/** Table的一个模式* 从文件中读取列车的信息,添加到table中* 显示在主界面中*/package com.desgin;import com.consel.*;import java.text.SimpleDateFormat;import java.util.*;import javax.swing.table.*;public class AdmTable extends AbstractTableModel {TrainContral tc = new TrainContral();Vector rowData, columnNames;List<Train> train;SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");public AdmTable() {tc.trainRead();train = tc.train;init(train);}private void init(List<Train> train) {columnNames = new Vector();columnNames.add("列车号");columnNames.add("出发地");columnNames.add("到达地");columnNames.add("发车时间");columnNames.add("到站时间");columnNames.add("票价");rowData = new Vector();boolean flag = true;Iterator i = train.iterator();while (i.hasNext()) {Train c = (Train) i.next();Vector hang = new Vector();hang.add(c.getTrainID());hang.add(c.getStartCity());hang.add(c.getEndCity());hang.add(formatter.format(c.getStartDate()));hang.add(formatter.format(c.getEndDate()));hang.add(c.getMoney() + "元");rowData.add(hang);}}// 返回行数public int getRowCount() {return this.rowData.size();}//返回列数public int getColumnCount() {return this.columnNames.size();}//返回rowIndex,column处的值public Object getValueAt(int rowIndex, int column) { return ((Vector) this.rowData.get(rowIndex)).get(column); }//返回表头@Overridepublic String getColumnName(int arg0) {return (String) this.columnNames.get(arg0);}}----ChangeDialog-----/** 管理员修改或者添加航线的信息的UI界面*/package com.desgin;import com.consel.*;import java.awt.*;import java.awt.event.*;import java.util.*;import java.util.Iterator;import javax.swing.*;public class ChangeDialog extends JDialog implements ActionListener {JTextField t1 = new JTextField(15);JTextField t2 = new JTextField(15);JTextField t3 = new JTextField(15);JTextField t41 = new JTextField(5);JTextField t42 = new JTextField(5);JTextField t51 = new JTextField(5);JTextField t52 = new JTextField(5);JTextField t6 = new JTextField(15);AdmMainWindow amw;JButton save = new JButton("保存");JButton exit = new JButton("取消");//添加时的构造方法public ChangeDialog(AdmMainWindow amw, String s, boolean b) { super(amw, s, b);this.amw = amw;this.setSize(300, 275);this.setResizable(false);JPanel p1 = new JPanel();p1.setLayout(new GridLayout(7, 1, 8, 8));p1.add(new JLabel("列车号: ", SwingConstants.CENTER));p1.add(t1);p1.add(new JLabel("出发地: ", SwingConstants.CENTER));p1.add(t2);p1.add(new JLabel("到达地: ", SwingConstants.CENTER));p1.add(t3);p1.add(new JLabel("发车时间: ", SwingConstants.CENTER));JPanel panel1 = new JPanel();panel1.add(t41);panel1.add(new JLabel(":"));panel1.add(t42);p1.add(panel1);p1.add(new JLabel("到站时间: ", SwingConstants.CENTER));JPanel panel2 = new JPanel();panel2.add(t51);panel2.add(new JLabel(":"));panel2.add(t52);p1.add(panel2);p1.add(new JLabel("票价: ", SwingConstants.CENTER));p1.add(t6);p1.add(new JLabel("", SwingConstants.CENTER));JPanel pane2 = new JPanel();pane2.add(save);pane2.add(exit);p1.add(pane2);this.add(p1);save.addActionListener(this);exit.addActionListener(this);}//修改时的构造方法public ChangeDialog(AdmMainWindow amw, String s, boolean b, String x) { super(amw, s, b);this.amw = amw;this.setSize(300, 275);this.setResizable(false);JPanel p1 = new JPanel();p1.setLayout(new GridLayout(7, 1, 8, 8));TrainContral tc = new TrainContral();tc.trainRead();Iterator<Train> i = tc.train.iterator();Train temp = null;while (i.hasNext()) {temp = i.next();if (temp.getTrainID().equals(x)) {break;}}p1.add(new JLabel("列车号: ", SwingConstants.CENTER)); p1.add(t1);p1.add(new JLabel("出发地: ", SwingConstants.CENTER)); p1.add(t2);p1.add(new JLabel("到达地: ", SwingConstants.CENTER)); p1.add(t3);p1.add(new JLabel("发车时间: ", SwingConstants.CENTER)); JPanel panel1 = new JPanel();panel1.add(t41);panel1.add(new JLabel(":"));panel1.add(t42);p1.add(panel1);p1.add(new JLabel("到站时间: ", SwingConstants.CENTER)); JPanel panel2 = new JPanel();panel2.add(t51);panel2.add(new JLabel(":"));panel2.add(t52);p1.add(panel2);p1.add(new JLabel("票价: ", SwingConstants.CENTER));p1.add(t6);p1.add(new JLabel("", SwingConstants.CENTER));JPanel pane2 = new JPanel();pane2.add(save);pane2.add(exit);p1.add(pane2);this.add(p1);save.addActionListener(this);exit.addActionListener(this);t1.setText(temp.getTrainID());t2.setText(temp.getStartCity().toString());t3.setText(temp.getEndCity().toString());t41.setText(temp.getStartDate().getHours() + "");t42.setText(temp.getStartDate().getMinutes() + "");t51.setText(temp.getEndDate().getHours() + "");t52.setText(temp.getEndDate().getMinutes() + "");t6.setText(temp.getMoney() + "");}//监听器,对保存、退出按钮进行监听public void actionPerformed(ActionEvent e) {if (e.getSource() == exit) {this.dispose();}if (e.getSource() == save) {TrainContral tc = new TrainContral();tc.trainRead();Date d1 = new Date();d1.setHours(Integer.parseInt(t41.getText().trim()));d1.setHours(Integer.parseInt(t42.getText().trim()));Date d2 = new Date();d2.setHours(Integer.parseInt(t51.getText().trim()));d2.setHours(Integer.parseInt(t52.getText().trim()));Train t = new Train(t1.getText().trim(),new City(t2.getText().trim()),new City(t3.getText().trim()),d1,d2,Integer.parseInt(t6.getText().trim()));Iterator<Train> i = tc.train.iterator();while(i.hasNext()){Train temp = i.next();if(t.getStartCity().equals(temp.getStartCity()) && t.getEndCity().equals(temp.getEndCity())){i.remove();}}tc.train.add(t);tc.trainWrite(tc.train);this.dispose();amw.table.setModel(new AdmTable());}}}-----MainWindow----/** 用户界面测试*/package com.desgin;public class MainWindow {UserFrame uf = new UserFrame();public static void main(String[] args) {MainWindow m = new MainWindow();m.uf.jf.setVisible(true);}}-----MoreDialog-------/** 显示详细信息*/package com.desgin;import com.consel.*;import java.awt.Color;import java.awt.event.*;import java.text.SimpleDateFormat;import java.util.*;import javax.swing.*;public class MoreDialog extends JDialog {SearchInFrame sif;JButton back = new JButton("返回");TrainGraph tg = new TrainGraph();JTable table;Vector colName = new Vector();Vector rowData = new Vector();SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");JButton exit = new JButton("退出");public MoreDialog(SearchInFrame sif, String string, boolean b) { super(sif.mainFrame, string, b);this.sif = sif;this.setSize(300, 275);this.setLocationRelativeTo(null);//设置窗口居中int rowCount = sif.infTable.getSelectedRow();String str = (String) sif.infTable.getValueAt(rowCount, 1);colName.add("列车号");colName.add("起始站");colName.add("终点站");colName.add("发车时间");colName.add("到站时间");colName.add("票价");try {TrainGraph tg = new TrainGraph();tg.getPaths(new City(sif.start), new City(sif.end));Iterator<Stack> iter = tg.sers.iterator();Stack<City> temp = new Stack();while (iter.hasNext()) {if (!temp.isEmpty()) {temp.removeAllElements();}Stack stack = iter.next();Vector hang = new Vector();String s = "";while (!stack.isEmpty()) {City c = (City) stack.pop();if (!(c.getCityName().equals(sif.start) || c.getCityName().equals(sif.end))) {s = c.getCityName() + " " + s;}temp.push(c);}if (s.equals("")) {s += "无";}if (s.equals(str)) {break;}}City eCity = null;City sCity = null;if (!temp.isEmpty()) {sCity = temp.pop();}while (!temp.isEmpty()) {eCity = temp.pop();Iterator<Train> i = tg.train.iterator();while (i.hasNext()) {Train t = i.next();if (t.getStartCity().equals(sCity) && t.getEndCity().equals(eCity)) {Vector hang = new Vector();hang.add(t.getTrainID());hang.add(t.getStartCity());hang.add(t.getEndCity());hang.add(formatter.format(t.getStartDate()));hang.add(formatter.format(t.getEndDate()));hang.add(t.getMoney() + "元");rowData.add(hang);}}sCity = eCity;}} catch (Exception ex) {ex.printStackTrace();}table = new JTable(rowData, colName);JScrollPane jsp = new JScrollPane(table);this.add(jsp);exit.setBackground(Color.lightGray);exit.setBounds(0, 0, 10, 10);exit.addMouseListener(new MouseAdapter() {@Overridepublic void mousePressed(MouseEvent e) {System.exit(0);}});this.add(exit, "South");table.addMouseListener(new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {int selectedRow = table.getSelectedRow();if (selectedRow > 0) {table.setSelectionForeground(Color.RED);}}});}}------MyMonitor-----/** 用户界面的监听器* 查询、退出的相关操作*/package com.desgin;import java.awt.event.*;import javax.swing.JOptionPane;public class MyMonitor extends MouseAdapter {UserFrame uf;public MyMonitor(UserFrame uf) {super();this.uf = uf;}@Overridepublic void mousePressed(MouseEvent e) {if (e.getSource() == uf.exit) {System.exit(0);}if (e.getSource() == uf.search) {if (uf.start.getText().trim().equals("") || uf.end.getText().trim().equals("")) { JOptionPane.showMessageDialog(null, "请正确输入起始站和终点站!","Warnnig", JOptionPane.WARNING_MESSAGE);} else {uf.sif = new SearchInFrame(uf.start.getText().trim(),uf.end.getText().trim());uf.sif.mainFrame.setVisible(true);uf.jf.dispose();}}}}----MyTable-----/** 用户界面显示在table中的列车信息的模板*/package com.desgin;import com.consel.*;import java.util.*;import javax.swing.table.*;public class MyTable extends AbstractTableModel {TrainContral tc = new TrainContral();Vector rowData, columnNames;String startCity, endCity;SearchInFrame sf;int n;List<Train> train;//构造方法public MyTable(String startCity, String endCity, SearchInFrame sf, int n) { this.sf = sf;this.startCity = startCity;this.endCity = endCity;tc.trainRead();train = tc.train;this.n = n;init(train);}public void init(List<Train> train) {columnNames = new Vector();columnNames.add("出发地");columnNames.add("中转站");columnNames.add("到达地");。
分类号编号华北水利水电学院North China Institute of Water Conservancy and Hydroelectric Power 课程设计题目:全国交通资讯系统院系信息工程学院专业计算机科学与技术专业姓名指导教师彬2013年6月28日目录1.需求分析 (1)问题描述 (1)1.1基本要求 (2)2概要设计 (3)2.1 数据结构 (3)2.2 程序模块 (5)3.详细设计 (6)3.1用到的各种函数 (6)3.2函数调用关系图 (8)3.3测试与分析 (8)4.用户说明书 (13)5.总结 (15)5.1明月的总结 (15)5.2璐璐的总结 (16)5.3吕竹青的总结 (17)参考文献: (18)附录:程序源代码 (18)1.需求分析问题描述设计、模拟一个全国城市间的交通咨询程序,为旅客提供三种最优咨询方案:(1)时间最短;(2)费用最小;(3)中转次数最少。
1.1基本要求1.1.1输入输出的形式和输入值的围在程序中输入城市名称时,需输入10个字母以的字母串;输入列车或飞机编号时需输入一个整型数据;输入列车或飞机的费用时需输入一个实型数据;输入列车或飞机开始时间和到达时间时均需输入两个整型数据(以hh:mm的形式);在选择功能时,应输入与所选功能对应的一个整型数据。
1.1.2 输出形式程序的输出信息主要是:最快需要多少时间才能到达,或最少需要多少旅费才能到达,或最少需要多少次中转到达,并详细说明依次于何时乘坐哪一趟列车或哪一次班机到何地。
1.1.3程序所能达到的功能程序的功能包括:提供对城市信息的编辑,提供列车时刻表和飞机航班表的编辑,提供三种最优决策:最快到达、最省钱到达、最少中转次数到达,显示编辑的全国交通系统。
1.1.4任务分配在本程序中,我们一共划分了三个模块。
管理员模块的初始化数据,城市信息的编辑,以及显示交通系统和整体的界面由明月完成。
航班班次以及列车车次添加删除以及数据结构的初步实现由吕竹青完成。
对于最少时间,最少花费以及最少的中转次数这三个函数的实现由璐璐进行完成。
2概要设计2.1 数据结构#define MAX_VERTEX_NUM 18//城市节点数#define MAX_ARC_SIZE 100#define MAX_ROUTE_NUM 5//路线数#define False 0#define True 1#define INFINITY 10000struct Vehide{int number;//航班号,火车号float expenditure;//费用int begintime[2];//出发时间int arrivetime[2];//到达时间};//航班、列车信息节点struct infolist{Vehide stata[MAX_ROUTE_NUM];//一个出发地到达目的地所对应的航班数或列车车次数int last;//顺序表所对应的下标,从0开始};//顺序表表示struct ArcNode{int adjvex;//节点下标ArcNode *nextarc; //节点的下一个指针域infolist info;//节点的数据域};//邻接表中各个节点信息typedef struct VNode{char cityname[10];//城市名ArcNode *planefirstarc,*trainfirstarc;//航班链、列车链} VNode,AdjList[MAX_VERTEX_NUM];struct ALGraph{AdjList vertices;int vexnum,planearcnum,trainarcnum;//城市数、航班数、列车数};struct Node{int adjvex;int route;Node *next;};//临时建立的一个邻接表,用来求最少中转次数和最少费用struct QNode{int adjvex;struct QNode *next;};//链队节点信息struct LinkQueue{QNode *front;QNode *rear;};//链队信息typedef struct TimeNode{int adjvex;int route;int begintime[2];int arrivetime[2];struct TimeNode *child[MAX_ROUTE_NUM];}TimeNode,*TimeTree;struct arc{int co;char vt[10];//出发地名字char vh[10];//目的地名字int bt[2];//出发时间int at[2];//到达时间float mo;//费用}a[MAX_ARC_SIZE];char city[MAX_VERTEX_NUM][10];int TTime[2];int time[2];int time1[2];int time2[2];int c[MAX_VERTEX_NUM];int d[MAX_VERTEX_NUM];2.2 程序模块主要包括管理员编辑模块和用户查询模块以及显示全国交通信息模块。
2.2.1各模块之间的调用关系以及算法设计3.详细设计3.1用到的各种函数void Administer(ALGraph *G); //void CityEdit(ALGraph *G); //城市编辑void CreateCityFile();void CreateGraph(ALGraph *G);void CreatePlaneFile();void CreateTrainFile();int DeleteplaneArc(ALGraph *G);void DeleteQueue(LinkQueue *Q,int *x);int DeletetrainArc(ALGraph *G);void DeleteVertex(ALGraph *G);void DemandDispose(int n,ALGraph G);void EnterplaneArc(ALGraph *G);void EnterQueue(LinkQueue *Q,int x);void EntertrainArc(ALGraph *G);void EnterVertex(ALGraph *G);void ExpenditureDispose(int k,infolist (*arcs)[MAX_VERTEX_NUM],ALGraph G,int v0,int v1,float *M,int *final);void flightedit(ALGraph *G);void InitGraph(ALGraph *G);void InitQueue(LinkQueue *Q);int IsEmpty(LinkQueue *Q);int LocateVertex(ALGraph *G,char *v);void MinExpenditure(infolist arcs,float *expenditure,int *route);void PrintGraph(ALGraph *G);int save(ALGraph *G);void trainedit(ALGraph *G);void TransferDispose(int k,infolist (*arcs)[MAX_VERTEX_NUM],ALGraph G,int v0,int v1); void CopyTimeTree(TimeTree p,TimeTree q);void DestoryTimeTree(TimeTree p);void MinTime(infolist arcs,int *time,int *route);void VisitTimeTree(TimeTree p);void TimeDispose(int k,infolist (*arcs)[MAX_VERTEX_NUM],ALGraph G,int v0,int v1,int (*T)[2],int *final);void TimeTreeDispose(Node *head,infolist (*arcs)[MAX_VERTEX_NUM]);void trainedit(ALGraph *G);void CreateTimeTree(TimeTree p,int i,int j,LinkQueue *Q,infolist(*arcs)[MAX_VERTEX_NUM]);void UserDemand(ALGraph G);3.2函数调用关系图3.3测试与分析3.3.1测试数据与截图1.管理员操作界面2.对整个结构进行初始化3.对城市,飞机班次,列车车次的编辑对城市的编辑:对航班的编辑:对列车的编辑:1.用户操作界面1.查询最少费用2.查询最短时间3.查询最少的中转次数3.3.2测试分析1.1.1考虑到道路网多是稀疏网,故采用了邻接表作存储结构,其空间复杂度位O(e),此时的时间复杂度也为O(e)。
构建邻接表的时间复杂度位O(n+e),输出路径的时间复杂度为O(n2)。
由此,本交通资讯系统的时间复杂度位O(n2)。
1.1.2本程序在求最短路径时使用了迪杰斯特拉算法,主要考虑在本程序的初级阶段,并不需要大量的查询,更多会是图信息的添加和修改,重在算法的理解和掌握,因此采用了算法复杂度相对较低的迪杰斯特拉算法。
当然,从性能上来说,当交通图基本稳定,而且城市信息基本完善的时候,使用佛洛伊德把所有的最短路径信息存储起来可能会更方便一点,后续的查询的时间复杂度也会相对降低。
由此可见,在选用算法时,不能单纯地只考虑算法的时间复杂度,有时还必须综合考虑各种因素。
航班时刻表机号出发地到达地出发时间到达时间费用6320 16:2018:00 17:2519:05680元2104乌鲁木齐乌鲁木齐8:0010:459:5511:401150元列车时刻表873 07:1321:42 21:1711:46134元116 9:3618:54 18:3203:4898元373 13:1500:35 00:1511:35116元747 17:4115:1314:4712:19210元371乌鲁木齐乌鲁木齐11:4200:3523:5411:23114元218 18:5001:34 11:5118:35178元4.用户说明书1.2本程序运行在Windows系统下,执行文件为:全国交通资讯系统.exe;1.3双击运行程序后会显示控制台窗口,如图所示:1.4输入操作命令“1”,进入管理员操作界面,输入1-5的操作命令可以执行相应的操作,如图所示:1.5输入“2”操作命令则进入用户查询窗口,如图所示:1.6输入“3”命令则显示整个交通网络.5.总结5.1明月的总结在这次的课程设计中,我们抽中了这个全国交通咨询系统,刚看完题目真的感觉无从下手,最后经过我们的讨论以及需求分析,我们这个系统所要用的结构主要是图,我被分到的模块主要是对整个这个交通系统的初始化,以及对城市信息的编辑,也就是对城市的添加和删除,还有对整个系统的界面的操作。