简体   繁体   English

如何找到最长的路线?

[英]How to find the longest possible route?

Following problem: 以下问题:

An engine (for instance a car) starts its journey on a straight road. 发动机(例如汽车)在直线路上开始行驶。 Its consumption is directly proportional to the distance (for instance 480 km uses one unit of fuel and thus 48km uses a tenth unit of fuel). 它的消耗量与距离成正比(例如480公里使用一单位燃料,因此48公里使用十分一单位燃料)。 This engine can transport at most one unit of fuel. 该发动机最多可以运输一单位燃料。

At the start point is a supply of n0 fuel units. 首先是供应n0个燃料单元。 At different points on the route, are fuel depots (for instance n1 @ d1, n2 @ d2 etc.) and the driver can unload fuel anywhere on the route. 在路线的不同点上有燃料库(例如n1 @ d1,n2 @ d2等),驾驶员可以在路线上的任何地方卸载燃料。 For instance, with the values 480 km for one unit, the driver could drive for 160km create a depot with 1/3 units of fuel and drive back to the starting point to refuel his engine. 例如,对于一个单位,值为480 km,驾驶员可以行驶160 km,创建一个包含1/3单位燃料的仓库,然后开车返回起点为其引擎加油。

I'm looking for an algorithm (or some ideas to find one) to find the maximum distance that can be achieved depending on the starting fuel and the depots on the route. 我正在寻找一种算法(或一些想法来寻找一种算法),以根据起始燃料和路线上的仓库找到可以实现的最大距离。

By intuition a greedy algorithm should be optimal, ie by maximizing the amount of fuel available at each depot, you are maximizing the possible route. 通过直觉,贪婪算法应该是最佳的,即,通过最大化每个仓库的可用燃料量,您正在最大化可能的路线。 This is just my opinion, and I assume that "anywhere on the route" is "actually at any depot". 这只是我的意见,我认为“路线上的任何地方”实际上是“任何仓库”。

How will a greedy algorithm work? 贪婪算法将如何工作? At each point of time, you have only two decision to take : "move forward" or "go back to the previous depot to refill". 在每个时间点,您只有两个决定:“前进”或“返回到先前的仓库进行加油”。 The greedy will always move back as long as it will increase the current depot reserve. 只要增加当前仓库的储备量,贪婪的人就会一直向后移动。

I think that you could also "invert" the "<=" comparison used in your a*, dijkstra method. 我认为您也可以“反转” a *,dijkstra方法中使用的“ <=”比较。

Or add a logic parameter (best, worst) path. 或添加逻辑参数(最佳,最差)路径。

So you can keep the same path search without repeated code. 因此,您无需重复代码即可保持相同的路径搜索。

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

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