2

Given a directed graph, starting point, ending point and a time limit. At each vertices, there's a "value" that represents how much attractive this location is. There's also a cost of traveling from vertices to another.

What i need is to find a path that is within the time limit and has the maximum "value".

4
  • Does the path permit repetition of vertices or edges? Commented Mar 21, 2017 at 11:36
  • nope. should not visit a vertices that is already visited Commented Mar 21, 2017 at 12:20
  • This question may be more appropriate for code golf-- you've given us no code you're having trouble with or a language to work in. Commented Mar 21, 2017 at 13:00
  • What i need is perhaps a suggestion on any algorithm i could use rather than a concrete solution. Commented Mar 21, 2017 at 13:18

1 Answer 1

1

To answer the question in part, note that the considered problem is NP-hard as it contains the Knapsack problem as a subproblem using the following reduction.

Given an instance of the Knapsack problem given by n items defined by profits p_1,...,p_n and weights w_1,...,w_n and a target capacity C, define a graph as follows.

To the left there is a source node s and a terminal node t to the right. For the i-th item define two nodes yes_i and no_i, which correspond to selecting and not selecting the respective item. The attractiveness of the yes-nodes is p_i and the attractiveness of the no-nodes is zero.

The pairs of nodes can be imagined as arranged in columns between the source and the terminal. Each node has in two in-edges from the previous column (except for the first colum, which is connected to the source). The weight of each of these edges is w_i if and only if they are the in-edges of a yes-node and zero if they are in-edges of a no-node. The last column is connected to the terminal.

Each path from s to t must column-wise decide whether or not to select the item of the respective colum; likewise, any selection of items corresponds to a path from s to t. By definition of the edge weights, the total weight of the path is equal to the total weight of the selection of items, while the total weight of the selected yes-nodes is equal to the the total weight of the selected items.

In total, we obtain a bijection of the feasible solutions of the Knapsack instance and the constructed instance of the described path problem. In total, this means that the problem in the question is NP-hard as it contains the Knapsack problem (which is known to be NP-hard) as a subproblem.

Alternatively the NP-hardness can be seen by setting the attractiveness of all locations in a complete graph to one; this special case of the problem is the decision version of the Hamiltonian Path problem, which is known to be NP-complete.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.