MySQL database design for bus system, online, etc.
The name of the bus line and each station name of the bus line in the existing area,
such as 2 Road bus Aoyama Road--Army Day Road--Shanghai Road
3 Road bus concentrated road--Army Day Road--Shanghai Road
...
Can be from the station name 1 to arrive name 2, some is a train direct, some need to change,
Q: In MySQL, how the database design, online, etc.
THANKS if the file is larger, you can send me email 350038760@qq.com
------Solution--------------------
This should be equipped with a 2-dimensional map can be, individual do not come out. Or I understand the simple point
ID Station name several ways to transfer several ways
1 Castle Peak Road 2 way NULL
281 Road 2 Road 3 Road
3 Shanghai Road 2 Road 3 Road
4 Concentrated Road 3 way NULL
581 Road 3 Road 2 Road
6 Shanghai Road 3 Road 2 Road
Castle Peak Road > Concentrated Road:
Is Castle Peak Road on a few routes?
Concentrated road on a few road lines?
Is it consistent?
Is:...
No: Which road can turn concentrated road car?
However, there are problems, the interchange two times or more can not be found.
Code so many words do not have the heart to delete, mix a point. The novice programmer always wants to do the work while ....
------Solution--------------------
I used the "bus line mysql Design" keyword to find some.
I didn't do it and I felt a little complicated.
As soon as I see this problem, I think of graphs and generalized tables in data structures. So I prefer other languages to implement the interface form. This is my guess.
Good luck!
------Solution--------------------
The database is probably like this:
Station Name table
ID Station name a few stops (to calculate the distance several stations)
Interchange table
ID Station name several ways to change the station name (sometimes two cars will be in the same location to give different station names)
In the actual calculation, the table should be represented by the graph (not map, graph),
Is the station can be reached at each station (can interchange with each other station as the same point), and then using the Dijkstra algorithm
However, this is the simplest,
If the bus lines are more complex, such as one-way sections (which are not completely duplicated), then the table needs more fields to differentiate.
And if you need to calculate the shortest time, it is more complicated, need to record the time of the train ....
Calculate the price of the words .... If there are different cars on the same road (air-conditioned car, ordinary car) ...
And if there is a fast train (stop the station less) .... If there are different shifts in different time periods, the stops are different.
.....
.......
.........
When you're done, you can try a Google map similar project ...:)
------Solution--------------------
Give an example;
Http://tech.ddvip.com/2009-02/1234417065108419.html
Http://tech.ddvip.com/2009-02/1234598725108794.html the landlord reference.
------Solution--------------------
More Simple storage methods
Line number
On the downside
Station name Group A comma-separated station name along the road direction
If you intend to associate with the map in the future, the structure will be slightly more complex
Line number
On the downside
The first few stops
Station name
Site coordinates x
Site coordinates y
Different query algorithms used by the data organization are different
------Solution--------------------
1. Train Number Model Origin destination
2. Number up and down line via
3. Numbering fees
The bus system should be very complex, it is best to understand the operation, and then separate the design of the table content, convenient for later development. Not much experience, that's all.
------Solution--------------------
SQL code
create TABLE IF not EXISTS ' buss ' (' id ' int (one) not NU LL auto_increment, ' bus ' int (one) not null, ' line ' varchar ($) NOT NULL, PRIMARY KEY (' id ')) engine=myisam DEFAULT CHA RSET=GBK auto_increment=3;----Dump the data in the table ' buss '--insert into ' buss ' (' id ', ' bus ', ' line ') VALUES (1, 2, ' Castle Peak Road, Army Day Road, Shanghai Road '), (2, 3 , ' concentrated road, Army Day Road, Shanghai Road ');
------Solution--------------------
I just gave you the basic algorithm for direct and one-time transfers
and you're a two-time transfer
. You need to take the station of all the lines starting from the beginning, Do them one at a time: a direct or one-time transfer query
The data for your example is the Castle Peak Road, Army Day Road, Shanghai Road, and high-tech as the starting point
will get
New two road, Xinjian Road, high-Tech, Aoyama Rd
----- -Solution--------------------
Landlord apparently did not go to search "Dijkstra algorithm"