Android Metro Shortest Route transfer Inquiry System (1)

Source: Internet
Author: User

This is an android app that I used to query the shortest route of Guangzhou Metro. The shortest route transfer query and optimized query results are achieved.
There are three difficulties: first, the data structure of the figure is used to build the entire subway station point chart; second, the shortest path algorithm; and third, the optimization of the query results.
Features: Resources and algorithms are highly separated from the core, allowing you to update subway lines and site information at any time without changing algorithms and other components. Automatic Graph Generation, convenient data update, portability, and high reusability
1. Program Framework www.2cto.com
MetroSearch: a primary Activity that provides the line query function.
MapDisplay: a secondary Activity that provides the subway line browsing function. (Additional Functions)
PathSearch: the core category of metro line query, including the data structure description, algorithm implementation, and shortest path description of Metro maps.
ResFinalVars: Resource class, including subway line information.
GraphEntry: indicates the data structure of the subway map.
TableEntry: used to record the shortest path and for path description.
 
2. Data Structure Description of subway lines
Step 1: express the subway station as a digital number for easy processing
Method: Use the Hash table to store the ing between the subway station name and number.
Advantage: automatic numbering and fast search
Step 2: Use an adjacent table to construct the graph data structure. The resource data is separated from the method.
Method: The GraphEntry class is used to construct the graph. The graph is automatically generated Based on the Resource class ResFinalVars.
Feature: All changes to Subway information can be modified only in ResFinalVars. No change is required in other places.
Advantages: Automatic Graph Generation, convenient data update, portability, and high reusability
3. query result processing and Optimization
GraphEntry class
Class GraphEntry {
Private ArrayList <Integer> list;
Private int line;
Private int info;
...
}
The member line stores subway line numbers, such as line 1 and line 2. It is represented by a bit field. It can save multiple route information and save space. (Int type can save up to 32 route entries)
The member info stores the information of the common station or transfer station for quick judgment.
4. Code Implementation (subsequent)
Resource Type:
/*
* Author: shenjunyong
* E-mail: junyong.shen@samsung.com
* Date: 2.6.2.6.14
**/
Package com. xiaoben. metrosearch2;
 
Import android. app. Activity;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. util. Log;
Import android. view. View;
Import android. widget. AdapterView;
Import android. widget. ArrayAdapter;
Import android. widget. Button;
Import android. widget. Spinner;
Import android. widget. TextView;
Import android. widget. AdapterView. OnItemSelectedListener;
Import java. util .*;
 
Final class ResFinalVars {
Public static final int INFINITE = 0 xffff;
Public static final int UNKNOWN =-1;
Public static final int TRANSIT = 0;
Public static final int NORMAL = 1;

Public static enum LINESINFO {
LINE1 (1), LINE2 (2), LINE3 (4), LINE4 (8), LINE5 (0x10), LINE6 (0x20 ), LINE7 (0x40), LINE8 (0x80), linepidermal (0x100 );
Private final int value;
Private LINESINFO (int value ){
This. value = value;
}

Public int getValue (){
Return this. value;
}
};

Public static final int LINE1 = 1;
Public static final int LINE2 = 2;
Public static final int LINE3 = 4;
Public static final int LINE4 = 8;
Public static final int LINE5 = 0x10;
Public static final int LINE6 = 0x20;
Public static final int LINE7 = 0x40;
Public static final int LINE8 = 0x80;
Public static final int linepidermal = 0x100;



Public static final String [] lines_number = {
"Metro Line 1", "Metro Line 2", "Metro Line 3", "Metro Line 4", "Metro Line 5", "Metro Line 8 ", "Metro Guangfo line"
};

Public static final String line1_stations [] = {
"Guangzhou East Station", "Sports Center", "Sports west road", "Yang zhe", "East Yamaguchi", "martyrs cemetery", "Agriculture lecture center", "Park front ", "West Gate", "Chen Jia Ci", "Changshou road", "Huangsha", "Fangcun", "huadi Bay", "Keng kou", "xilang ",
};
 
Public static final String line2_stations [] = {
"Guangzhou South Railway Station", "Shibi", "huijiang", "Nanpu", "luoxi", "nanzhou", "dongxiao South", "jiangtai road", "Changgang ", "Jiangnan West", "city second Palace", "Haizhu square", "Park front", "Memorial Hall", "Yuexiu Park", "Guangzhou Railway Station", "Sanyuan li ", "Flying Park", "Baiyun Park", "Baiyun Culture Square", "Xiaogang", "Jiangxia", "huangbian", "Jiahe Wanggang ",
};
 
Public static final String line3a_stations [] = {
"Tianhe Passenger Station", "Wushan", "huashi", "gangding", "shipaqiao", "Sports west road", "Pearl River New City", "chigang Tower", "kecun ", "Datang", "Lili", "Xiamen", "dashi", "hanxi Changlong", "Shiqiao", "Panyu square"
};
 
Public static final String line3b_stations [] = {
"Sports west road", "Lin and West", "Guangzhou East Station", "yantang", "Mei Garden", "Jingxi Southern Hospital", "Tonghe", "Yongtai ", "North Baiyun Avenue", "Jiahe Wanggang", "longgui", "people", "South Airport Station ",
};
 
 
Public static final String line4_stations [] = {
"Huangcun", "Che Yun", "Che Yun Nan", "Wan Sheng Wai", "Guan Zhou", "University Chengbei", "University Chengnan", "new ", "Shi Ji", "Hai Xi", "Gao Yong", "Dong Yong", "Huang Ge Automobile City", "Huang ge", "Ji men", "Jin Zhou ",
};
 
Public static final String line5_stations [] = {
"Tongkou", "tangwei", "Zhongshan 8", "Westfield", "West Village", "Guangzhou Railway Station", "XiaoBei", "Taojin ", "zizhuang", "Zoo", "yangxiao", "Wuyang", "Zhujiang New Town", "Hunters", "Tan cun", "member cun ", "keyun road", "Cheonan", "Dongpu", "Sanxi", "Yuzhu", "dashadi", "dashada East", "wenchong ",
};
 
Public static final String line6_stations [] = {

};

Public static final String line7_stations [] = {
};
 
Public static final String line8_stations [] = {
"Wansheng Wai", "Zhuzhou", "Xingang East", "moisersha", "chigang", "kucun", "ZhuJiang", "zhongda", "Xiaogang ", "Changgang", "Baogang Avenue", "Sha yuan", "Phoenix New Village ",
};

Public static final String gfline_stations [] = {
"Xilang", "Chrysanthemum Tree", "Longxi", "financial high-tech zone", "qiandeng Lake", "(insects) gang", "nangui road", "guicheng ", "Chao 'an", "pujun North Road", "zumiao", "Tongji road", "Ji Huayuan", "kuiqi Road Station"
};

Public static final String [] [] lines = {
Line1_stations,
Line2_stations,
Line3a_stations,
Line3b_stations,
Line4_stations,
Line5_stations,
Line8_stations,
Gfline_stations,
};

Public static final String [] transit_stations = {
"Xilang", "Guangzhou East Station", "Wan shengwei", "kucun", "Changgang", "Cheonan", "Pearl River New City", "Sports west road ", "Yang zhe", "Park front", "Guangzhou Railway Station", "Jiahe Wanggang"
};
}
Author: guruxiao
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.