简体   繁体   English

在图形中找到最安全的路线,但要防止最快路线的旅行时间增加一倍?

[英]Find safest route in graph but prevent doubling the travel time of the fastest route?

my university project is to design a route planner of the city i live in, calculating the shortest routes between streets. 我的大学项目是设计我所居住城市的路线规划器,计算街道之间的最短路线。 (traveling salesman) (旅行推销员)

In C#, im using a graph to store all the streets. 在C#中,即时通讯使用图形存储所有街道。 Currently i can find the shortest route between two streets in the weighted graph using Dijkstra's algorithm, first section done :) 目前,我可以使用Dijkstra算法在加权图中找到两条街道之间的最短路线,第一部分完成了:)

My next task is, to calculate the safest route with a twist. 我的下一个任务是计算最安全的路线。 Each street has a crash percentage on it (eg 0.4% chance of a car crash based on roads crash history). 每条街道上都有一个碰撞百分比(例如,基于道路碰撞历史记录,有0.4%发生车祸的可能性)。 I need to calculate the safest route HOWEVER solve the problem of if a user would like to travel the safest route possible, but not double their travel time as opposed to the fastest route. 我需要计算最安全的路线,但是,如何解决用户是否想骑行最安全的路线这一问题,而不是使旅行时间比最快的路线增加一倍。

Could anyone give me any ideas of what they think would be the best method to do this? 谁能给我他们认为将是最好的方法的任何想法?

One method i came up with was to take the last street visited before the end destination is reached, remove that node and calculate a route without that, and do so for 10 routes and choose the one with the lowest accumulated crash percentage, however that also sounds like the worst possible way of doing it. 我想出的一种方法是在到达最终目的地之前,走最后一条经过的街道,删除该节点并计算一条没有该路径的路线,然后对10条路线进行选择,并选择累积崩溃率最低的一条路线,但是听起来可能是最糟糕的方式。

What maths/logic/algorithms can you guys give me? 你们能给我什么数学/逻辑/算法? Anything the user should input? 用户应该输入什么? such as a threshold of how much slower they are willing to go? 例如他们愿意走多慢的门槛? C#, java, pseudocode C#,Java,伪代码

Thanks so much guys 非常感谢你们

You could start by running a normal Dijkstra's algorithm so you know what the fastest route is so that you know when the safest route exceeds this cost by some factor. 您可以从运行正常的Dijkstra算法开始,这样您就知道最快的路线是什么,以便您知道最安全的路线何时超过此成本某个因素。

You could then run it again with safety as the main cost function, but also calculating the distances to rule out some routes. 然后,您可以将安全性作为主要成本函数再次运行它,而且还可以计算距离以排除某些路线。 At first I thought this could be done like the normal Dijkstra's algorithm but by storing an ordered list for each node (previous node, cost, and safety value). 最初,我认为可以像普通的Dijkstra算法一样完成此操作,但可以通过为每个节点存储一个有序列表(先前的节点,成本和安全值)来实现。 The issue with this is that as distance and safety are apparently independent (in reality there's some sort of correlation but not one we know how to model). 问题在于距离和安全性显然是独立的(实际上存在某种相关性,但我们不知道如何建模)。 This is an issue as you need to prevent long distances early in the route wrongly leading you to rejecting options later in the route. 这是一个问题,因为您需要防止在路线的尽头长途行驶,从而错误地导致您在路线的较晚地点拒绝选择。

This need not be a problem if you could can apply the distance limit on partial routes. 如果可以在部分路径上应用距离限制,则不必担心。 That is you don't accept a route to any intermediate node if it longer than twice the shortest route from the start to that node. 那就是说,如果到任何中间节点的路由的长度比从起始节点到该节点的最短路由的两倍长,则您不接受该路由。 I know that this isn't exactly as you stated because you asked about restricting only the route length to the final node, but maybe it still helps you in thinking about the overall solution. 我知道这与您所说的不完全一样,因为您询问仅限制到最终节点的路由长度,但是也许它仍然可以帮助您考虑整个解决方案。 For what its worth it might also be more realistic. 对于它的价值,它也可能更现实。

Remember to combine the crash probability correctly, you can't just add it up. 请记住,要正确组合崩溃概率,您不能仅仅将其相加。 If we assume the journey stops at the first crash then you'd be calculating the probability of the crash as probability of crash on road 1 plus (probability of not crashing on road 1 * probability of crashing on road 2) plus (probability of getting to road 3 safely * probability of crash on road 3) etc (sorry if that's obvious). 如果我们假设旅程在第一次撞车时停止,那么您将把撞车的概率计算为在1号公路上撞车的概率加上(在1号公路上撞车的概率*在2号公路上撞车的概率)加上(得到的概率安全地到达3号公路* 3号公路发生撞车的可能性)(抱歉)。


Given your comment, I'll explain more on the probability (and it is probability and not odds you'd be best looking up) 根据您的评论,我将详细介绍概率(这是概率,而不是您最好查找的几率)

If you want an overall measure of safety that allowed for continuing after a crash then it gets more complex. 如果您希望在碰撞后继续进行总体安全措施,那么它将变得更加复杂。 If you stop when there's a crash then its a matter of calculating probability of crashing exactly once. 如果您在发生碰撞时停下来,那么只需计算一次碰撞概率就可以了。 So a route has a crash if: 因此,如果发生以下情况,路线将发生崩溃:

you crash on the first road (probability p1) OR 您在第一条道路上撞车(概率p1)或

you don't crash on the first road ( probability 1-p1) but you do crash on the second (probability p2). 您不会在第一条道路上撞车(概率为1-p1),但在第二条道路上撞车(概率为p2)。 OR 要么

... you don't crash on roads n-1 (1-running total as above) but you do crash on road n (probability pn) ...您没有在n-1公路上发生撞车(如上所述,共有1条路行驶),但是在n公路上发生了撞车(概率pn)

This way you don't get cases where a 50% chance of crash on roads 1&2 doesn't add up to an overall 100% chance - and you'd never get greater than that either. 这样一来,您就不会遇到在1号和2号公路上发生撞车的50%的可能性加起来不会达到总100%的机会的情况,而且您也永远不会比这更大。

In reality lots of crashes happen at junctions, and there will be a different probability of crash depending on whether you turn left or right - so the probability is not (in reality) just dependent on the safety factor of the roads between the junctions but also how the route combines them. 在现实中,路口会发生很多交通事故,根据您向左还是向右转弯,发生撞车的可能性会有所不同-因此,概率(实际上)不仅仅取决于路口之间道路的安全系数,而且还取决于路线如何将它们结合在一起。

The probabilities should be weighted according to use (lookup conditional probabilities) so if there were 20 crashes on a rarely used road that may need to be modelled a having a higher crash probability as a busy road with 50 crashes in the same time period. 应根据使用情况对概率进行加权(查找条件概率),因此,如果在极少使用的道路上发生20次碰撞,则可能需要将其建模为具有较高碰撞概率的繁忙道路,而在同一时间段内,繁忙路段发生50次碰撞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM