“苦水”通过精心收集,向本站投稿了3篇公交车路线查询系统后台数据库设计――引入步行路线,下面是小编给大家带来公交车路线查询系统后台数据库设计――引入步行路线,一起来阅读吧,希望对您有所帮助。
篇1:公交车路线查询系统后台数据库设计――引入步行路线
在《查询算法》和《关联地名和站点》两篇文章中,已经实现了通过地名或站点进行路线查询的算法 ,但是在现实中,从起点到终点不一定全程都是乘车,例如,有以下3条路线:
R1: S1->S2->S3->S4->S5
R2: S6->S7->S2->S8
R3: S8->S9->S10
假如现在要从站点S1到S7,如果用Inquiry查询路线,显然没有合适的乘车方案,但是S2和S7相距仅仅 一个站的距离,可以用步行代替,因此可以先从S1乘坐R1到S2再步行到S7。
为了实现在乘车路线中插入步行路线,在数据库使用WalkRoute(StartStop, EndStop, Distance, Remark)(StartStop-起始站点,EndStop-目的站点,Distance-距离,Remark-备注)储存距离较近的两个站点 。
加入表WalkRoute后,查询算法也要作相应的修改,其实WalkRoute和RouteT0很相似,因此只需把 WalkRoute看成是特殊的直达线路即可,修改后的InqueryT1如下:
InquiryT1
/* 查询站点@StartStops到站点@EndStops之间的一次换乘乘车路线,多个站点用'/'分开,如: exec InquiryT1 '站点1/站点2','站点3/站点4' */ CREATE proc InquiryT1(@StartStops varchar(32),@EndStops varchar(32)) as begin declare @ss_tab table(name varchar(32)) declare @es_tab table(name varchar(32)) insert @ss_tab select Value from dbo.SplitString(@StartStops,'/') insert @es_tab select Value from dbo.SplitString(@EndStops,'/') if(exists(select * from @ss_tab sst,@es_tab est where sst.name=est.name)) begin raiserror ('起点集和终点集中含有相同的站点',16,1) return end declare @stops table(name varchar(32)) insert @stops select name from @ss_tab insert @stops select name from @es_tab declare @result table( StartStop varchar(32), Route1 varchar(256), TransStop varchar(32), Route2 varchar(256), EndStop varchar(32), StopCount int ) declare @count int set @count=0 --查询“步行-乘车”路线 insert @result select sst.name as StartStop, '从'+r1.StartStop+'步行到'+r1.EndStop as Route1, r1.EndStop as TransStop, r2.Route as Route2, est.name as EndStop, r2.StopCount as StopCount from @ss_tab sst, @es_tab est, (select * from WalkRoute where EndStop not in (select name from @stops)) r1, RouteT0 r2 where sst.name=r1.StartStop and r1.EndStop=r2.StartStop and r2.EndStop=est.name order by r2.StopCount set @count=@@rowcount --查询“乘车-步行”路线 insert @result select sst.name as StartStop, r1.Route as Route1, r1.EndStop as TransStop, '从'+r2.StartStop+'步行到'+r2.EndStop as Route2, est.name as EndStop, r1.StopCount as StopCount from @ss_tab sst, @es_tab est, RouteT0 r1, (select * from WalkRoute where StartStop not in (select name from @stops)) r2 where sst.name=r1.StartStop and r1.EndStop=r2.StartStop and r2.EndStop=est.name order by r1.StopCount set @count=@count+@@rowcount if(@count=0) begin --查询“乘车-乘车”路线 insert @result select sst.name as StartStop, r1.Route as Route1, r1.EndStop as TransStop, r2.Route as Route2, est.name as EndStop, r1.StopCount+r2.StopCount as StopCount from @ss_tab sst, @es_tab est, (select * from RouteT0 where EndStop not in (select name from @stops)) r1, RouteT0 r2 where sst.name=r1.StartStop and r1.EndStop=r2.StartStop and r2.EndStop=est.name and r1.Router2.Route order by r1.StopCount+r2.StopCount end select StartStop as 起始站点, Route1 as 路线1, TransStop as 中转站点, Route2 as 路线2, EndStop as 目的站点, StopCount as 总站点数 from @result end
篇2:公交车路线查询系统后台数据库设计――查询算法
1. 公交车路线信息在数据库中的存储方式
显然,如果在数据库中简单的使用表bus_route(路线名,路线经过的站点,费用)来保存公交车路线的线 路信息,则很难使用查询语句实现乘车线路查询,因此,应该对线路的信息进行处理后再保存到数据库中 ,笔者使用的方法是用站点-路线关系表stop_route(站点,路线名,站点在路线中的位置)来存储公交车路 线,例如,如果有以下3条路线
R1:S1->S2->S3->S4->S5R2:S6->S7->S2->S8R3:S8->S9->S10
则对应的站点-路线关系表stop_route为
StopRoutePosition S1R11 S2R12 S3R13 S4R14 S5R15 S6R21 S7R22 S2R23 S8R24 S8R31 S9R32 S10R33注:Stop为站点名,Route为路线名,Position为站点在路线中的位置
2.直达乘车路线查询算法
基于表stop_route可以很方便实现直达乘车路线的查询,以下是用于查询直达乘车路线的存储过程 InquiryT0:
create proc InquiryT0(@StartStop varchar(32),@EndStop varchar(32))asbegin select sr1.Stop as 启始站点, sr2.Stop as 目的站点, sr1.Route as 乘坐线路, sr2.Position-sr1.Position as 经过的站点数 from stop_route sr1, stop_route sr2 where sr1.Route=sr2.Route and sr1.Position 3.查询换乘路线算法 (1)直达路线视图 直达路线视图可以理解为一张存储了所有直达路线的表(如果两个站点之间存在直达路线,那么在直达 路线视图中就有一行与之相对应) create view RouteT0as select sr1.Stop as StartStop, --启始站点 sr2.Stop as EndStop, --目的站点 sr1.Route as Route, --乘坐线路 sr2.Position-sr1.Position as StopCount --经过的站点数 from stop_route sr1, stop_route sr2 where sr1.Route=sr2.Route and sr1.Position (2)换乘路线算法 显然,一条换乘路线由若干段直达路线组成,因此,基于直达路线视图RouteT0可以很方便实现换乘查 询,以下是实现一次换乘查询的存储过程InquiryT1: create proc InquiryT1(@StartStop varchar(32),@EndStop varchar(32))asbegin select r1.StartStop as 启始站点, r1.Route as 乘坐路线1, r1.EndStop as 中转站点, r2.Route as 乘坐路线2, r2.EndStop as 目的站点, r1.StopCount+r2.StopCount as 总站点数 from RouteT0 r1, RouteT0 r2 where r1.StartStop=@StartStop and r1.EndStop=r2.StartStop and r2.EndStop=@EndStopend 同理可以得到二次换乘的查询语句 create proc InquiryT2(@StartStop varchar(32),@EndStop varchar(32))asbegin select r1.StartStop as 启始站点, r1.Route as 乘坐路线1, r1.EndStop as 中转站点1, r2.Route as 乘坐路线2, r2.EndStop as 中转站点2, r3.Route as 乘坐路线3, r3.EndStop as 目的站点, r1.StopCount+r2.StopCount+r3.StopCount as 总站点数 from RouteT0 r1, RouteT0 r2, RouteT0 r3 where r1.StartStop=@StartStop and r1.EndStop=r2.StartStop and r2.EndStop=r3.StartStop and r3.EndStop=@EndStopend 4.测试 exec InquiryT0 'S1','S2'exec InquiryT1 'S1','S8'exec InquiryT2 'S1','S9' 运行结果: 本文配套源码:www.bianceng.net/other/201212/803.htm 国际化学品安全卡(中文版)网络数据库查询系统的设计与实现 概述了国际化学品安全卡(中文版)网络查询系统的建设、主要内容及其查询方法.重点介绍了系统的设计思想,采用ASP编程技术实现了该查询系统的'设计和运行. ★ 技术路线 范文 ★ 认识路线教案 ★ 红军长征路线体会篇3:国际化学品安全卡(中文版)网络数据库查询系统的设计与实现
公交车路线查询系统后台数据库设计――引入步行路线(精选3篇)