Beijing Metro Line

Beijing Metro Line


task


  The main task of the project is through personal travel subway people can quickly find the fastest route to reach the planned destination of travel through the software.

Project requirements

  • User to get all the information based on the Beijing subway line parameter -map
java subway -map subway.txt
  那么这里的重点就在于如何存储这个subway.txt文件了,首先我们还是看一张北京地铁1号线的图  
![](https://img2018.cnblogs.com/blog/1806411/201909/1806411-20190922113916097-1876119492.jpg)   
这里比较容易想到的每条线路存储方式就是 
> 1: 苹果园 古城 八角游乐园 ...       
> 2: 积水潭 鼓楼大街 安定门 ...

  其中1表示1号线,2表示2号线,但是在从图中可以看到打圈的站点,这些站点打圈的表示是可以中转的站台,
这里比较麻烦的就是如何在txt中标明哪个站可以转乘,并且可以转乘几号线,
这里参考了一个同学的博文,他在可以换乘的站台后用(#+数字)的形式来标明该站台可以换成几号线,
如果该站台可以换成多条线路,只要继续在后面加(#+数字)即可,使用#可以在读取文件的时候很容易区分哪个站台可以换乘,
且在数字之间用#分隔,也不会使数字之间混淆   
  那么存储在txt中的存储格式就变成了这个样子    
>1: 苹果园 古城 八角游乐园 ...        
>2: 积水潭 鼓楼大街#8 安定门 ...
  • To get all the information the user sites via a line after the line number of a few parameters -a +
java subway -a 1号线 -map subway.txt -o station.txt
  其中把获得的线路信息输出在station的txt文件中供用户参考  
  其中输出样式为   
>2号线:积水潭 -> 鼓楼大街(可换乘8号线)-> 安定门 -> ...
  • User name + -b + start site termination site name parameter to obtain a route from the starting point to the specified destination (through this route requires the minimum number of stations)
java subway -b 积水潭 安华桥 -map subway.txt -o routine.txt
  这里我认为先用Dijkstra算法把每个站点到其他的任意一个站点的最短线路规划信息先存储在一个txt文件中,然后把该文件放在某个服务器上,
这样每个用户在要求获得某两个站点之间线路规划的时候就直接从服务器中读取该文件并输出相应的线路信息,
这样就不用每一次在用户要求规划线路的时候都去运行一遍算法,大大节省了用户的时间。
当然,这里的输出格式与上面一个需求的输出格式相同
>1: 积水潭 -> 鼓楼大街 -> 换成8号线 -> 安华桥 
>2: 积水潭 -> 鼓楼大街 -> ...  

  之所以这里有'1:' , '2:'这种标志,是因为可能在经过站数相同的情况下有多条线路,这时候就由用户进行选择,毕竟不同的用户可能次要需求也不一样,有些人喜欢换乘最少,但也有些人希望是时间最快到达,这里留给用户自行选择

Epilogue

  The site information personal project is very large, so the optional line travel will be very large, very complex species, now is not considered a variety of input errors, that time unified input error handling it, test input sample program cases also have to think about it slowly, and when the accuracy of the test results themselves may have to manually calculate whether it is to meet the requirements and is the least number of stations, this time artificially to calculate when two sites are relatively far apart It is still quite complicated.
Reference this blog

Guess you like

Origin www.cnblogs.com/nicochou/p/11566808.html