存在下面的情况吗
A     B    80
B     C    90
A     M    ..
M     C    ..

解决方案 »

  1.   

    A   D  : 80 * 90 * 50 + 60 =..存在路经:
    A     D    60                 -- 60A     B    80
    B     C    90
    C     D    50                 --80*90*50A     C    50
    C     D    50                 --?为什么这个路经没有?
      

  2.   

    是不是单向的?A   C  : 50 + 80*90 = ..
    存在路经:
    A     C    50                 -- 50A     B    80
    B     C    90                 --80*90A     D    60                 
    C     D    50                 --这条有反向的算不算?
      

  3.   

    当单向图计算--建立源表
    declare @b table(
    [From] varchar(10),  
    [To]  varchar(10),
    [Percent] numeric(18,2)
    )--源表数据
    insert @b select
    'A',     'B',    80
    union all select
    'A',     'C',    50
    union all select
    'A',     'D',    60
    union all select
    'B',     'C',    90
    union all select
    'C',     'D',    50
    --计算结果表
    declare @t table(
    [From] varchar(10),  
    [To]  varchar(10),
    [Percent] numeric(18,2),
    [Path] varchar(1000)
    )--搜索所有路经
    insert @t
    select *,[From]+','+[To] from @bwhile exists (
    select 1 from @t t,@b b 
    where t.[To]=b.[From]
    and not exists (
    select 1 from @t where [Path]=t.[Path]+','+b.[To]
    )
    )
    insert @t
    select t.[From],b.[To],t.[Percent]*b.[Percent],t.[Path]+','+b.[To] from @t t,@b b 
    where t.[To]=b.[From]
    and not exists (
    select 1 from @t where [Path]=t.[Path]+','+b.[To]
    )--测试数据
    declare @From varchar(10)
    declare @To varchar(10)set @From='A'
    set @To='C'--看路经
    select * from @t 
    where [From]=@From
    and [To]=@To--最终结果
    select sum([Percent]) as [Percent]
    from @t
    where [From]=@From
    and [To]=@To
      

  4.   

    参考http://community.csdn.net/Expert/topic/4929/4929112.xml?temp=.6055414
      

  5.   

    数据检索规则不完整.比如
     fcuandy(现在流行散分) ( ) 信誉:100  2006-08-16 09:33:00  得分: 0  
     
     
       AC不是50吗?为什么还要算?
      
     还是即有 AC, 还有 A-B, B-C 所以再多算出一个AC?
      

  6.   

    我估计这里Percent80代表80%
    这样:
    A   B  : 80%
    A   C  : 50% + 80*90% = 122%
    A   D  : 80% * 90% * 50% + 60% =96%
      

  7.   

    --------------------------------------------------------------
    您好,我们是“2006中国杰出数据库工程师评选”活动组委会。
    您的帖子已经被我们转载到本次评选官方网站的“专家在线答疑”区。
    http://www.bestdba.cn/match_discussion.aspx在那里,进入本次评选终选的30位数据库工程师将与您展开积极的互动。他们会为您的问题提供满意的答案,此外,您还可以在“专家在线答疑”区提出新的问题并参与讨论。您的帖子位于:
    http://www.bestdba.cn/match_discussion3.aspx?pointid=552&pointid2=1&pointid3=5&pcount=stc
    非常感谢您对本次活动的支持!
      

  8.   

    写SQL做不嫌麻烦么?
    把数据加载出来,然后根据数据构造一个图,然后再遍历这个图,随意计算两个点之间的路径权值如果数据量过大,那么适当采取一些规则来做到小范围的查找。
      

  9.   

    有点复杂呢。不过基本是做个迭代算法,在算法中增加约束,以减少CPU的执行次,比如计算环路
    而进入死循环。
      

  10.   

    .NET-Club-9  (20152522)!.NET开发俱乐部仅提供开发交流平台,实现资源互补,共同进步!谢绝聊天!
    进群需有.NET开发经验
    欢迎广大。NET开发者踊跃加入
      

  11.   

    感觉你的问题没说太具体,不知道你的数据具体是什么样子的你看看这种思路符合你的要求么AG有效Percent = AG + AB*BC*CD*DE*EF*FG
    如果是这样,那用函数做简单的ASC码操作就很容易实现了不过建议你这种算法问题,如果考虑效率,按道理来说,应该是取到C里然后计算,如果非要用SQL计算,最好用上临时表,把数据放内存里计算。