1. How the bus route information is stored in the database
Obviously, if the simple use of table Bus_route in the database (route name, route through the site, cost) to save the bus route information, it is difficult to use the query statement to achieve the bus line query, therefore, should be processed on the line of information and then saved to the database, The method used by the author is to store bus routes using the site-route relationship Table Stop_route (site, Route name, site in the route), for example, if the following 3 routes
R1:S1->S2->S3->S4->S5
r2:s6->s7->s2->s8
R3:S8->S9->S10
Then the corresponding site-route relationship Table Stop_route is
Stop |
Route |
Position |
S1 |
R1 |
1 |
S2 |
R1 |
2 |
S3 |
R1 |
3 |
S4 |
R1 |
4 |
S5 |
R1 |
5 |
S6 |
R2 |
1 |
S7 |
R2 |
2 |
S2 |
R2 |
3 |
S8 |
R2 |
4 |
S8 |
R3 |
1 |
S9 |
R3 |
2 |
S10 |
R3 |
3 |
Note: Stop is the site name, route is the route name, position is the location of the site in the route