|
回复:(wjlone)高手请上座,小弟有礼了
iuhxq(小灰) ( ) 信誉:1002006-3-21 17:09:03得分: 0
if exists (select * from dbo.sysobjects where id = object_id(N‘[dbo].[t]‘) and OBJECTPROPERTY(id, N‘IsUserTable‘) = 1)
drop table [dbo].[t]
GO
CREATE TABLE [dbo].[t] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[lid] [nvarchar] (50) ,
[name] [nvarchar] (50) ,
[type] [int] NOT NULL
)
GO
insert into t (lid,[name],[type])
select "11","城站火车站",0
union all select "11","葵巷建国路口",0
union all select "11","菜市桥",0
union all select "11","潮鸣寺巷",0
union all select "11","宝善桥建国路口",0
union all select "11","宝善桥",0
union all select "11","市体育馆",0
union all select "11","武林广场",0
union all select "11","武林门",0
union all select "11","武林们马塍路口",0
union all select "11","八字桥",0
union all select "11","浙大西溪校区",0
union all select "11","庆丰村",0
union all select "11","教工路口",0
union all select "11","花园新村",0
union all select "11","浙江工商大学",0
union all select "11","电子科技大学",0
union all select "11","翠苑新村",0
union all select "57","大关小区",0
union all select "57","通信市场",0
union all select "57","德胜新村",0
union all select "57","潮王路口",0
union all select "57","朝晖五区",0
union all select "57","朝晖三区",0
union all select "57","西湖文化广场东",0
union all select "57","武林广场",0
union all select "57","武林小广场",0
union all select "57","半道红",0
union all select "57","文三路口",0
union all select "57","上宁桥",0
union all select "57","花园新村",0
union all select "57","浙江工商大学",0
union all select "57","文一路口",0
union all select "57","教工路北口",0
union all select "57","大关桥西",0
union all select "57","上塘路口",0
union all select "57","大关西六苑",0
union all select "57","香积寺路口",0
union all select "57","大关小区",0
union all select "14","武林小广场",0
union all select "14","昌化新村",0
union all select "14","长寿桥",0
union all select "14","延安路口",0
union all select "14","中大广场",0
union all select "14","众安桥",0
union all select "14","浙一医院",0
union all select "14","大学路北口",0
union all select "14","庆春门",0
union all select "14","金衙庄",0
union all select "14","总管塘",0
union all select "14","华东家具市场",0
union all select "14","近江村",0
union all select "14","汽车南站",0
union all select "14","汽车南站",1
union all select "14","近江村",1
union all select "14","华东家具市场",1
union all select "14","总管塘",1
union all select "14","金衙庄",1
union all select "14","庆春门",1
union all select "14","大学路北口",1
union all select "14","浙一医院",1
union all select "14","众安桥",1
union all select "14","中大广场",1
union all select "14","延安路口",1
union all select "14","长寿桥",1
union all select "14","昌化新村",1
iuhxq(小灰) ( ) 信誉:1002006-3-21 17:09:19得分: 0
union all select "14","武林小广场",1
union all select "K105","火车东站",0
union all select "K105","汽车东站",0
union all select "K105","严家弄",0
union all select "K105","景芳五区",0
union all select "K105","景御路口",0
union all select "K105","庆春东路",0
union all select "K105","采荷新村",0
union all select "K105","观音塘小区",0
union all select "K105","总管塘",0
union all select "K105","章家桥",0
union all select "K105","浙二医院",0
union all select "K105","官巷口",0
union all select "K105","湖滨",0
union all select "K105","胜利剧院",0
union all select "K105","孩儿巷",0
union all select "K105","延安新村",0
union all select "K105","武林小广场",0
union all select "K105","杭州大厦",0
union all select "K105","中北桥",0
union all select "K105","施家桥",0
union all select "K105","建国北路文晖路口",0
union all select "K105","文晖大桥东",0
union all select "K105","机神村",0
union all select "K105","天城路口",0
union all select "K105","新塘路口",0
union all select "K105","火车东站",0
union all select "39","闸口",0
union all select "39","水澄桥",0
union all select "39","海月桥",0
union all select "39","美政桥",0
union all select "39","复兴路北口",0
union all select "39","三廊庙",0
union all select "39","木材新村",0
union all select "39","二凉亭",0
union all select "39","望江门外",0
union all select "39","汽车南站",0
union all select "39","近江村",0
union all select "39","华东家具市场",0
union all select "39","总管塘",0
union all select "39","城站火车站",0
union all select "K101","城站火车站",0
union all select "K101","总管塘",0
union all select "K101","观音塘小区",0
union all select "K101","采荷新村",0
union all select "K101","红菱新村",0
union all select "K101","凤起东路口",0
union all select "K101","双菱路北口",0
union all select "K101","市红会医院",0
union all select "K101","建国路口",0
union all select "K101","新华路口",0
union all select "K101","中北路口",0
union all select "K101","延安路口",0
union all select "K101","浙大湖滨校区",0
union all select "K101","昌化新村",0
union all select "K101","市府大楼",0
union all select "K101","武林门马塍路口",0
union all select "K101","八字桥",0
union all select "K101","浙大西溪校区",0
union all select "K101","庆丰村",0
union all select "K101","玉古路天目山路口",0
union all select "K101","西湖体育馆",0
union all select "21/K21","城站火车站",0
union all select "21/K21","章家桥",0
union all select "21/K21","新城隧道东口",0
union all select "21/K21","解放路秋涛路口",0
union all select "21/K21","采荷新村",0
union all select "21/K21","红菱新村",0
union all select "21/K21","双菱路北口",0
union all select "21/K21","市红会医院",0
union all select "21/K21","建国路口",0
union all select "21/K21","新华路口",0
union all select "21/K21","中北路口",0
union all select "21/K21","延安路口",0
union all select "21/K21","浙大湖滨校区",0
union all select "21/K21","昌化新村",0
union all select "21/K21","市府大楼",0
union all select "21/K21","武林门马塍路口",0
union all select "21/K21","八字桥",0
union all select "21/K21","浙大西溪校区",0
union all select "21/K21","庆丰村",0
union all select "21/K21","跑马场",0
union all select "21/K21","黄龙体育中心",0
union all select "21/K21","浙大附中",0
union all select "21/K21","求是路",0
union all select "21/K21","西湖体育馆",0
union all select "58/K58","大关小区",0
union all select "58/K58","上塘路香积寺路口",0
union all select "58/K58","大关西六苑",0
union all select "58/K58","上塘路口",0
union all select "58/K58","大关桥西",0
union all select "58/K58","教工路北口",0
union all select "58/K58","文一路口",0
union all select "58/K58","浙江工商大学",0
union all select "58/K58","花园新村",0
union all select "58/K58","上宁桥",0
union all select "58/K58","文三新村",0
union all select "58/K58","八字桥",0
union all select "58/K58","武林门马塍路口",0
union all select "58/K58","武林小广场",0
union all select "58/K58","武林广场",0
union all select "58/K58","中北桥",0
union all select "58/K58","朝晖一区",0
union all select "58/K58","朝晖三区",0
union all select "58/K58","朝晖五区",0
union all select "58/K58","潮王路口",0
union all select "58/K58","德胜新村",0
union all select "58/K58","通信市场",0
iuhxq(小灰) ( ) 信誉:1002006-3-21 17:09:28得分: 0
union all select "58/K58","大关小区",0
union all select "K101","西湖体育馆",1
union all select "K101","玉古路天目山路口",1
union all select "K101","庆丰村",1
union all select "K101","浙大西溪校区",1
union all select "K101","八字桥",1
union all select "K101","武林门马塍路口",1
union all select "K101","市府大楼",1
union all select "K101","昌化新村",1
union all select "K101","浙大湖滨校区",1
union all select "K101","延安路口",1
union all select "K101","中北路口",1
union all select "K101","新华路口",1
union all select "K101","建国路口",1
union all select "K101","市红会医院",1
union all select "K101","双菱路北口",1
union all select "K101","凤起东路口",1
union all select "K101","红菱新村",1
union all select "K101","采荷新村",1
union all select "K101","观音塘小区",1
union all select "K101","总管塘",1
union all select "K101","城站火车站",1
/****** Object:Stored Procedure dbo.SearchScript Date: 2005-9-8 10:28:35 ******/
if exists (select * from dbo.sysobjects where id = object_id(N‘[dbo].[Search]‘) and OBJECTPROPERTY(id, N‘IsProcedure‘) = 1)
drop procedure [dbo].[Search]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
/****** Object:Stored Procedure dbo.SearchScript Date: 2005-9-8 10:28:35 ******/
CREATE proc Search
@name1 nvarchar(50),
@name2 nvarchar(50)
as
--中转站
create table #tmp
(
tmp_id int identity(1,1),
tmp_name NVARCHAR(50)
)
--站点队列
create table #tmp1
(
tmp1_id int identity(1,1),
tmp1_name NVARCHAR(50)
)
--查找结果
create table #result
(
r_id int,
r_lid nvarchar(50),
r_name nvarchar(50),
r_type int
)
--直达
insert into #result
select c.*from t a,t b,t c where
a.lid=b.lid and a.[type]=b.[type] and a.idand a.[name] = @name1 and b.[name] = @name2
and c.id>=a.id and c.id<=b.id order by c.id
if @@rowcount>0 begin
select * from #result
end
else begin
--换车
DECLARE @CurrenName NVARCHAR(50)
SET @CurrenName = @name1
change:
/*
--车次入栈
insert into #tmp (tmp_lid)
select distinct lid from t where [name] = @CurrenName
DECLARE @CurrenBus NVARCHAR(50)
SELECT 1 @CurrenBus = tmp_lid FROM #tmp
*/
INSERT INTO #tmp1 (tmp1_name)
SELECT DISTINCT b.[name] FROM t a,t b WHERE a.[name] = @CurrenName AND b.lid = a.lid AND b.[name] <> @CurrenName
INSERT INTO #tmp (tmp_name)
select d.[tmp1_name]from t a,t b,t c, #tmp1 d where
a.lid=b.lid and a.[type]=b.[type] and a.idand a.[name] = d.[tmp1_name] and b.[name] = @name2
and c.id>=a.id and c.id<=b.id
IF @@rowcount>0 BEGIN
select distinct c.*from t a,t b,t c,#tmp d where
a.lid=b.lid and a.[type]=b.[type] and a.id and a.[name] = @name1 and b.[name] = d.tmp_name
and c.id>=a.id and c.id<=b.id order by c.id
select distinct c.*from t a,t b,t c,#tmp d where
a.lid=b.lid and a.[type]=b.[type] and a.id and a.[name] = d.tmp_name and b.[name] = @name2
and c.id>=a.id and c.id<=b.id order by c.id
END
--SELECT * FROM #tmp
end
drop table #result
drop table #tmp1
drop table #tmp
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
exec search ‘文一路口‘,‘总管塘‘
cime63(归去来) ( ) 信誉:1002006-3-21 17:17:44得分: 0
http://community.csdn.net/Expert ... 8.xml?temp=.1395227
http://www.gistime.com/ReadNews.asp?NewsID=210
http://www.gistime.com/ReadNews.asp?NewsID=209
http://blog.csdn.net/bfbd/archive/2005/03/16/321216.aspx
http://topic.csdn.net/t/20050107/13/3706990.html
http://hnqyyz.com/aosai/bak/www. ... list.asp@id=368.htm
http://www.programfan.com/club/old_showbbs.asp?id=38154
http://www.3s2go.com/oldbbs/viewthread.php?tid=6978
http://www.it023.com/software/de ... 079583853d4755.html
=================================================
上面是我搜到的相关内容
小灰那个能讲讲思路吗?
另:早就知道小灰这个人了,不过今天才知道是个女孩子
iuhxq(小灰) ( ) 信誉:1002006-3-21 17:32:46得分: 0
to cime63(归去来) :
本人性别:男
换车思路:
从起点站寻找所有可以到达的站点,然后从这些站点找到达目的地的路线
cime63(归去来) ( ) 信誉:1002006-3-21 20:09:48得分: 0
呵呵
你博客上有人叫姐呢
或者那不是你的博客
cime63(归去来) ( ) 信誉:1002006-3-21 23:35:52得分: 0
我准备写个COM组件
然后调用
这样会不会好些呢?有没有跟我讨论一下?
cime63(归去来) ( ) 信誉:1002006-3-22 8:00:14得分: 0
顶上去
昨晚看了下COM的写法今晚再把算法写成COM吧
zlz_212() ( ) 信誉:1002006-3-22 8:08:44得分: 0
http://community.csdn.net/Expert ... 5.xml?temp=.8170587
hdt(倦怠) ( ) 信誉:1202006-3-22 8:25:12得分: 0
好好看看数据结构里 图 那一章
boylez(boylez) ( ) 信誉:1002006-3-22 8:27:53得分: 0
mark
cime63(归去来) ( ) 信誉:1002006-3-22 8:35:45得分: 0
呵呵
我要一直顶下去
直到解决这个问题
然后在不影响我朋友毕业答辩的情况下公开源代码
大家多提供点思路
谢谢哈
zmacro(zmacro) ( ) 信誉:972006-3-22 8:38:11得分: 0
up
liuyan55(ayan) ( ) 信誉:952006-3-22 8:38:26得分: 0
看!
tiaoci(我挑刺,我快乐) ( ) 信誉:1002006-3-22 8:50:47得分: 0
首先要对公交线路建立模型,
至于用CS 还是用 BS并不是很总要
像小灰这样乱写代码是没有用处的
最简单的:比方公交车上行和下行的线路可能不一样
iuhxq(小灰) ( ) 信誉:1002006-3-22 8:52:34得分: 0
支持开源!
tiaoci(我挑刺,我快乐) ( ) 信誉:1002006-3-22 8:54:50得分: 0
站点之间的路况可能不同(短的路线可能需要开的时间反而长)
tiaoci(我挑刺,我快乐) ( ) 信誉:1002006-3-22 8:56:31得分: 0
搜索结果要看你是需要最省钱还是最快到达
tiaoci(我挑刺,我快乐) ( ) 信誉:1002006-3-22 9:00:13得分: 0
不同公交路线站点可能同一个,但是站名不一致,
yzujjcb() ( ) 信誉:1002006-3-22 9:05:08得分: 0
Mark,学习学习
cime63(归去来) ( ) 信誉:1002006-3-22 9:05:34得分: 0
我想适当简单化处理
走的站点数就认为是时间,或者说长度
当然上行线路和下行线路的确可能是不一样的
hdt(倦怠) ( ) 信誉:1202006-3-22 9:06:47得分: 0
其实就是个有向图嘛
iuhxq(小灰) ( ) 信誉:1002006-3-22 9:11:03得分: 0
如果考虑时间或者路程,那就要加权了
计算各条通路的权值,取最小的。
kent3721(Kent) ( ) 信誉:992006-3-22 9:44:10得分: 0
有向图的问题。在存储过程里实现,b/s和C/s都是一样的!
cime63(归去来) ( ) 信誉:1002006-3-22 9:50:52得分: 0
我在CSDN里搜索过,邹建(MSSQL区的版主???)写过一个存储过程来实现,可是有人说记录达到9000条的时候,搜索整整用了三十多分钟
那样根本不行嘛
pbwf(书生) ( ) 信誉:1002006-3-22 9:58:38得分: 0
俺学习.
hdt(倦怠) ( ) 信誉:1202006-3-22 10:06:04得分: 0
关键看你的数据库设计,和算法。
nameone(萨达姆) ( ) 信誉:992006-3-22 10:36:39得分: 0
UP
net205(向MVP学习!) ( ) 信誉:1002006-3-22 10:59:41得分: 0
好帖,学习.....
[ 本帖最后由 风花雪月 于 2007-4-2 10:01 编辑 ] |
|