Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suggest an algorithm (graph - possibly NP-Complete)

There is a network of towns, connected by roads of various integer lengths.

A traveler wishes to travel in his car from one town to another. However, he does not want to minimize distance traveled; instead he wishes to minimize the petrol cost of the journey. Petrol can be bought in any city, however each city supplies petrol at various (integer) prices (hence why the shortest route is not necessarily the cheapest). 1 unit of petrol enables him to drive for 1 unit of distance. His car can only hold so much petrol in the tank, and he can choose how many units of petrol to purchase at each city he travels through. Find the minimum petrol cost.

Does anyone know an efficient algorithm that could be used to solve this problem? Even the name of this type of problem would be useful so that I can research it myself! Obviously it's not quite the same as a shortest path problem. Any other tips appreciated!

EDIT - the actual problem I have states that there will be <1000 cities; <10000 roads; and the petrol tank capacity will be somewhere between 1 and 100.

like image 413
Andrew Wills Avatar asked Aug 17 '12 16:08

Andrew Wills


People also ask

What is NP-complete in graph?

A problem is called NP (nondeterministic polynomial) if its solution can be guessed and verified in polynomial time; nondeterministic means that no particular rule is followed to make the guess. If a problem is NP and all other NP problems are polynomial-time reducible to it, the problem is NP-complete.

How do you prove an algorithm is NP-complete?

We say X is NP-complete if: X ∈ NP • for all Y ∈ NP, Y ≤P X. If these hold, then X can be used to solve every problem in NP. Therefore, X is definitely at least as hard as every problem in NP.

What does it mean for an algorithm to be NP-complete?

(definition) Definition: The complexity class of decision problems for which answers can be checked for correctness, given a certificate, by an algorithm whose run time is polynomial in the size of the input (that is, it is NP) and no other NP problem is more than a polynomial factor harder.

What is NP completeness give an example for NP-complete problem?

A problem X is NP-Complete if there is an NP problem Y, such that Y is reducible to X in polynomial time. NP-Complete problems are as hard as NP problems. A problem is NP-Complete if it is a part of both NP and NP-Hard Problem. A non-deterministic Turing machine can solve NP-Complete problem in polynomial time.


2 Answers

You could solve this directly using Djikstra's algorithm if you are happy to increase the size of the graph.

Suppose your petrol tank could hold from 0 to 9 units of petrol.

The idea would be to split each town into 10 nodes, with node x for town t representing being at town t with x units of petrol in the tank.

You can then construct zero-cost edges on this expanded graph to represent travelling between different towns (using up petrol in the process so you would go from a level 8 node to a level 5 node if the distance was 3), and more edges to represent filling up the tank at each town with one unit of petrol (with cost depending on the town).

Then applying Djikstra should give the lowest cost path from the start to the end.

like image 199
Peter de Rivaz Avatar answered Oct 07 '22 13:10

Peter de Rivaz


I think the question is: Is there a chance the petrol stuff makes the underlying traveling salesman problem computationally more feasible? If not, there is no efficient non-approximating algorithm.

Of course, you can find efficient solutions for edge cases, and there might be more edge cases with the petrol condition, as in, always take this city first because the petrol is so cheap.

like image 31
Nicolas78 Avatar answered Oct 07 '22 13:10

Nicolas78