在加油站问题中,我们给了个城市以及它们之间的道路。每条道路都有长度,每个城市都定义了燃料价格。一单位的道路需要一单位的燃料。我们的目标是以最便宜的方式从货源到目的地。我们的战车受到一些价值的限制。
我试图理解算法,所以我手动写下了计算解决方案的步骤。不幸的是,我被卡住了-在某些时候没有考虑的余地,我不知道为什么,也许我错过了一些东西。
示例:
道路:
0 ----------- 1 ------------ 2 -------------- 3
(不一定要这么简单,可以是任何图形,即0-> 2、0-> 3、1-> 3之间的道路等)
来源:0,目的地:3,坦克:10单位
燃油价格:0:10单位,1:10单位,2:20单位,3:12单位
长度:0-> 1:9单位,1-> 2:1单位,2-> 3:7单位
最佳解决方案:以0填充9个单位,以1填充8个单位,则总成本为170个单位(9 * 10 + 8 * 10)。
GV[u] is defined as:
GV[u] = { TankCapacity - length[w][u] | w in Cities and fuelPrice[w] < fuelPrice[v] and length[w][u] <= TankCapacity } U {0}
so in my case:
GV[0] = {0}
GV[1] = {0}
GV[2] = {0, 3, 9}
GV[3] = {0}
D(u,g) - minimum cost to get from u to t starting with g units of fuel in tank:
D(t,0) = 0, otherwise:
D(u,g) = min (foreach length[u][v] <= TankCapacity)
{
D(v,0) + (length[u][v] - g) * fuelPrice[u] : if fuelPrice[v] <= fuelPrice[u] and g <= length[u][v]
D(v, TankCapacity - length[u][v]) + (TankCapacity - g) * fuelPrice[u] : if fuelPrice[v] > fuelPrice[u]
}
so in my case:
D(0,0) = min { D(1,0) + 9*10 } - D(0,0) should contain minimum cost from 0->3
D(1,0) = min { D(2,9) + 10*10 } - in OPT we should tank here only 8 units :(
D(2,9) = min { ??? - no edges which follows the condition from the reccurence
Nevertheless D(0,0) = 90 + 100 + smth, so it's already too much.
To achieve the optimal solution algorithm should calculate D(2,7) because the optimal route is:
(0,0) -> (1,0) -> (2, 7) -> (3, 0) [(v, g): v - city, g - fuel in tank].
If we look at G[2] there is no "7", so algorithm doesn't even assume to calculate D(2,7),
so how can it return optimal solutions?
文档中的重复出现似乎无效,或者更有可能是我做错了。
有人可以帮我吗?