楼主: 〇〇

一个求最短总路径的问题

[复制链接]
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
21#
 楼主| 发表于 2021-8-8 20:36 | 只看该作者
笛卡尔积太大了
pop=# select to_id,count(*)cnt from p group by to_id;
to_id | cnt
-------+-----
    34 |  75
   125 |  13
     1 | 541
   145 |  13
    23 |  75

使用道具 举报

回复
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
22#
发表于 2021-8-9 08:24 来自手机 | 只看该作者
这种暴力法也就只能玩玩小数据,认真你就输了。

使用道具 举报

回复
论坛徽章:
0
23#
发表于 2021-8-10 02:45 来自手机 | 只看该作者
Here is my question for group trip with Dijkstra algorithm.  Consider 2 people starts at point 1234 and ends at 1 and 4.  How to choose the first step, given D(234)<D(123)<D(124)<D(134)<...<... (other possible direct connecting points)?  If one takes D(234) and one D(123) separately the total is D(234)+D(123)=D1.  If both take D(134) the total is D(134) (free share).  Now if D(234)+D(123) < D(134), how to choose for the very first step, branching or sharing?  If branching, in following steps, both can no longer share paths (implying possible larger distance in fatal).  If sharing in the first step, it is possible to keep sharing to the point 14 and then branching to point 1 and point 4 separately (implying the total distance may be much shortened due to the following shared steps).  So my question is, in order to take greedy choice in the first step as in the Dijkstra algorithm, wether or not we give up the choice of sharing path?  This is all about the first step (nothing else).

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
24#
 楼主| 发表于 2021-8-12 12:48 | 只看该作者

使用道具 举报

回复
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
25#
发表于 2021-8-13 02:41 | 只看该作者
jihuyao 发表于 2021-8-10 02:45
Here is my question for group trip with Dijkstra algorithm.  Consider 2 people starts at point 1234  ...

必须穷尽所有分支,没有办法。

使用道具 举报

回复
论坛徽章:
0
26#
发表于 2021-8-13 02:59 来自手机 | 只看该作者
The simplest one I caught from the link is one walks through all points and comes back to starting point, which is different from group trip involving share factor.  If constraints can be applied, as in current topic such that Dx+Dy>Dz (always true for the same level stops), the shared stop will be preferred in the very first step.  The we have to deal with the second step as in the algorithm (have not thought about the 2nd step so far, maybe not so hard as being scared).  Forget how complicated the real problems may be.  Now something in common reminds me of the N Card problem.  One is the problem itself how to place all cards back in sequence together efficiently.  My feel is that we can still take the greedy choice (this has to consider both cost and potential benefit) for each step (even for group sharing factor involved).  The second common is the N Card problem is much like the opposite problem of group trip, after 2 people reach their end points 1 and 4, how they come back to the start point 1234 efficiently, that is, one person waits somewhere for the other person in order to share path to come back together to the start point (compare to the 5 cards problem, can not always perform in the same way such as 4 to 5, 3 to 4/5, 2 to 3/4/5, and finally 1 to 2/3/4/5, individually).  Anyway, cooperative greedy choice for each step in group trip is an interesting attempt.  Compared to all path links, for each step one only considers all the direct next paths to evaluate the whole group cost and benefits).  Particularly for larger N levels group trip, this will avoid all unnecessary cross joins as in sql for only one step.

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
27#
 楼主| 发表于 2021-8-13 12:32 | 只看该作者
newkid 发表于 2021-8-13 02:41
必须穷尽所有分支,没有办法。

如果先求出一个较短的5个人的总距离,在拼接过程中能把比它大的过滤掉

使用道具 举报

回复
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
28#
发表于 2021-8-13 21:26 | 只看该作者
我前面说的那个方法,第一步就是求出所有点到点的最短距离,以那个作为基准。如果发现更短路径就替换这个基准。如果有些点之间不可达,剪起来就更快了。但是人员的所有分组方法还是都得尝试。

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
29#
 楼主| 发表于 2021-8-15 22:10 来自手机 | 只看该作者
https://m.mysmth.net/article/ITExpress/2297371 这个有点厉害

使用道具 举报

回复
论坛徽章:
14
2009新春纪念徽章
日期:2009-01-04 14:52:28沸羊羊
日期:2015-03-04 14:51:52优秀写手
日期:2014-03-14 06:00:13马上有房
日期:2014-02-18 16:42:022014年新春福章
日期:2014-02-18 16:42:022013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:08:15蜘蛛蛋
日期:2012-06-27 21:08:142012新春纪念徽章
日期:2012-01-04 11:53:29ITPUB十周年纪念徽章
日期:2011-11-01 16:23:26
30#
发表于 2021-8-24 12:45 | 只看该作者
这个让sql做,勉为其难了吧。
还是数据库存数据,用编程语言做好一些。

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表