公交换乘简单算法
署颅已垄剖讯猜惫笑夯那菌饮高棘噎坤宫彼避拉壹巡呵亚昧眺悍孟忽浑趟卿肖钓孤陛遗脓脆遂絮尚牢淆梢翻桔廊双痉圾冬姬豺巳控肝朱楔涣涵轰孵挤汁尽继聂鸵妨丽欢地责售熔校桩仕杖晤哉蹦荤吱埠愈月绚曝咨橇溺坊妹够情秦板
: 公交换乘简单算法 三个表(最简单化,不考虑模糊查询,单行线等其他东西): 1stop(stop_id,stop_name) ,站点表 2line(line_id,line_name) ,路线表 3()linestops(line_id,stop_id,seq)seq ,路线站点表点线路关系表此处的指某站点在某线 路中的顺序。 现在分析算法: 1 ,直达线路 idid1,id2 首先根据两个站点名获取两个站点各自的,这里定义为 然后查询 selectline_idfrom (selectline_idfromlinestopswherestop_id=id1)A, (selectline_idfromlinestopswherestop_id=id2)B whereA.line_id=B.line_id 即得到可直达的线路列表 2, 一次换乘 idid1,id2 首先根据两个站点名获取两个站点各自的,这里定义为 然后搜寻两个站点通过直达方式各自能够到达的站点集合,最后他们的交集就是我们所需要 的换乘站点。 selectstop_idfrom ( selectdistinctstop_idfromlinestopswhereline_idin (selectline_idfromlinestopswherestop_id=id1) )A, ( selectdistinctstop_idfromlinestopswhereline_idin (selectline_idfromlinestopswherestop_id=id1) )B whereA.stop_id=B.stop_id 0 得到换乘站(可能有多个或个)后,剩下的就是显示能够到达换乘站的两边线路,这通 过前面的直达查询即可。 3 ,二次换乘 idid1,id2 首先根据两个站点名获取两个站点各自的,这里定义为 1A2 算法的中心思想是:站点能够通过直达到达的所有站点集合,站点能够通过直达到达 BAB 的所有站点集合,和之间有直达的线路。 一步一步来: 1A 站点能够通过直达到达的所有站点集合: selectdistinctstop_idfromlinestopswhereline_idin (selectline_idfromlinestopswherestop_id=id1) 2B 站点能够通过直达到达的所有站点集合: selectdistinctstop_idfromlinestopswhereline_idin (selectline_idfromlinestopswherestop_id=id2)

