Pair programming work (the shortest subway route planning)

First, the needs analysis

  1. Task:

  Implement a command-line program to help Tianjin subway travel route planning.

    Key features include:

      a. java subway -map subway.txt input allows the program to read the source data into the preparation.

      b. Enter java subway line number -a 1 -map subway.txt -o station.txt station to be able to find out the article contained subway line and stored in the station.txt.

      c. Enter subway.exe -b Honghuli Fuxing Road -map subway.txt -o routine.txt to be able to find out the shortest path two stations, and save routine.txt in (to be included in the transfer path information).

  2.PSP

  

Second, the software algorithm design and realization of ideas

  1. The source data structure described

    

 

 

     Description: * .txt files to store source data, each line is represented by a line of information for all stations, wherein each station separated by a space, and the first data representative of each line is underground metro line strip name.

   The benefits of this are stored all the data can be read only once, but because without the right to ask the subway, it is only necessary to read the information!

  2. Entity class properties

    Bloggers customized the two entity classes (Station and Line)

      Station contains the following information: 

    String name:主要存储的是地铁的名字。
    boolean visited:用于BFS算法中需要用到的标记,代表是否访问。
    String preStation:BFS回退求路径需要的一个备忘录。
    String line:初始为空,当BFS算法求出一条最短路径后,需要计算此条路径下的某个站属于的地铁线。
    List<String> lineNow = new ArrayList<String>():地铁站初始属于的地铁线,可能只有一个,也可能多个,
    List<Station> nextStation = new ArrayList<Station>():相邻地铁的信息,即下一次能到达的所有地铁。当某线的开始站和结束站存储为1,其他的为2*n.

    Line包含的信息如下:
    int id:地铁的标记,不重要 
    String name:地铁的名字
    List<String> stations = new ArrayList<>():某条地铁存储的所有站

  3.关键类(Solve)实现及算法思想:
    

public void getSubwayMessage():负责读入*.txt的源数据
    public void getStationByLine(String linename):传入参数是一个地铁线名,获得整个地铁线的地铁站

private void BFS(String st, String ed):传入参数 开始的地铁站,结束的地铁站 BFS参考的是 严蔚敏版<<数据结构>> 170页的BFS算法

public List calPassStations(String st, String ed):传入参数 开始的地铁站,结束的地铁站 这个是在BFS后的改进,在加入备忘录后,通过最后一个站回退到初始站,因此能找出这个最短路径,用列表List返回。
    public void  getChangeInfo(List<String> list):传入参数 最短路径的列表 加入最短路径的中所有Station,计算出当前Station的所属线,即Station.line
    public void  output(List<String> list)传入参数 最短路径的列表 这时候所有的站都被我们计算过所属站,功能主要是计算换乘信息存入 routine.txt
  
 
 4.项目目录展示
  
三.测试效果与运行 
 1.功能测试
    
a.读入信息测试:
      

 

 

       输出lines的信息

 

      输出所有站的节点:(一共141个站台信息初始进入map)

       

 

 

 

       b.获得某个地铁线的信息

          

 

 

        打开存储文档:

          

 

      c.获得某条路线的信息并存储

      

 

      打开存储文件

      



四.打包,作业测试及提交
  1.测试功能要求1
      待补

  3.源码下载Github下载地址:https://github.com/Bettetman/ShortDis.git
    
五.总结
  1.爬坑过程中,多次用到像list1=list2的语句赋值,但是测试发现达不到想要的效果,即在编程的过程中,我们很容易把对象的引用指向宁外一个对象,但是这个过程和基础数据有很大的不同,原因是,list1=list2二者指向的是内存的同一对象,因此不管是list1还是list2操作都会改变
   原来内存中的对象.
2.项目的不足:时间精力有限,算法的实现有点粗糙,并且用BFS实现的算法复杂度较高,而BFS本身带的算法会存在一个不足,那就是当 A站->B站 所有的路径只会存在一条,而同时存在多条路径时,这个问题难免不应该让我们忽略.
  

 

 


  

    

Guess you like

Origin www.cnblogs.com/ming1024/p/11795771.html