Hi I have an optimization problem where I have n days to travel to k cities and I have to plan my travel such that my total cost of travel is minimized.
The cost of travel between any 2 cities u and v, is dependent on the day when i decide to travel( so cost of travel between u and v is a function f(u,v,n) with n being the day when I am travelling) and I can travel only once a day.
I can also choose to stay in the same city.
Is there a way to solve this through a shortest path algorithm?
This is an NP-Complete problem (since it reduces from the Hamiltonian Path). The only major difference between this and the standard Traveling Salesman Problem is that the edge weights are dynamic. This means that you face a one time preprocessing cost of O(VVE!) complexity and that the entire cycle can be solved in a O(V^3) worst case time.
I was able to find some details of a similar problem in this paper published in IEEE, which describes the Intelligent Transportation-TSP problem.
Related
I'm taking the Algorithms: Design and Analysis II class, one of the questions asks:
Which of the following statements is true?
Consider a TSP instance in which every edge cost is either 1 or 2. Then an optimal tour can be computed in polynomial time.
Consider a TSP instance in which every edge cost is negative. The dynamic programming algorithm covered in the video lectures might not
correctly compute the optimal (i.e., minimum sum of edge lengths) tour
of this instance.
Consider a TSP instance in which every edge cost is negative. Deleting a vertex and all of its incident edges cannot increase the
cost of the optimal (i.e., minimum sum of edge lengths) tour.
Consider a TSP instance in which every edge cost is the Euclidean distance between two points in the place (just like in Programming
Assignment #5). Deleting a vertex and all of its incident edges cannot
increase the cost of the optimal (i.e., minimum sum of edge lengths)
tour.
I argue as follows:
The DP algorithm doesn't make any assumptions on the edge costs, so option 2 is incorrect.
If all edge weights are negative, then deleting a vertex and all of its incident edges can certainly increase the minimum sum because in effect, that edge weight is now added to the previous minimum. Thus, option 3 is incorrect.
Take the optimal tour in the original instance. Now, instead of visiting the deleted vertex v, skip straight from v's predecessor to its successor on the tour. Because Euclidean distance satisfies the "Triangle Inequality", this shortcut only decreases the overall distance traveled. The best tour can of course only be better. Thus, option 4 is correct.
However, I'm not able to find any significance for TSP problems with unit edge costs. Is option 1 merely a trick, or is there more to it?
OP here:
Papadimitriou and Yannakakis have shown that it is possible to approximate the TSP problem 1 in polynomial time within accuracy 7/6. This guarantee has been further improved by Bläser and Shankar Ram to 65/56. However, no matter how good those results are, those are still approximations, and not an optimal solution. Thus, option 1 is incorrect.
I have a graph that represents a city. I know the location of places of interest (nodes, which have a Importance value), the location of the hotel I'm staying in, how the nodes are connected, the traversal time between them and have acess to latitude and longitude. There are no issues converting from time to distance and vice-versa.
The objective is to tour the city, maximizing the importance per day but limiting one day of travel to 10 hours. A day begins and ends at the hotel. I have a working A* algorithm that chooses the lowest value but with no heuristic yet, which I guess makes it a BB for now. With that in mind:
Since I have access to Lat/Long, my first stab at an heuristic, while
only dealing with times, would be the distance as the crow flies
between a node and the hotel. Would this be an admissible heuristic?
It gives me the shortest possible distance and time, so it wouldn't
overestimate.
Now let's say the Importance of a node is between 1-4. In order to factor it in, one idea could be g(neighbor) = g(current) + (edge_cost / Importance^2). Assuming this would be valid (if not, why?):
But now the heuristic values would be in a different unit. Could a solution to this simply be give the Hotel Importance = 1? If the value is the same, will it still be admissible? EDIT: I think this will end up giving me problems because of the difference in scale.
I still have to restrict the total amount of time. Should each node keep track of the total time spent, in order to compare to the limit, plus the g() and h() values, because of the different units?
And finally:
Since I have to start and end in the same node, what comes to mind is to explore a node and should I find the hotel see if I still have time to explore the neighbors instead of going back. However, if I still have time to expand to one more node, but time runs out and I can't get to the hotel from there, I'm assuming I'll have to backtrack to the parent.
I can't help but see similarities to the knapsack problem. Even though I have to use A*, is there any lesson I can take from it?
Must my heuristic be consistent in this case? If so, why?
By the way, the purpose here is pathfinding first, optimizations second.
This actually looks like a combination of the travelling salesman problem (TSP) and knapsack problem (KP). It's KP in this respect: the knapsack capacity is 10 (for total hours available in a day) and the locations are the items. The item value equals the location value. The item weight is equal to the time it takes to travel to the location (plus the location's portion of the trip back to the hotel). The challenge arises from the fact that an item's weight is unknown until you solve the optimal tour through the selected locations--enter the TSP and Pathfinding.
One approach might be to use a pathfinding algorithm (e.g. A*, Bellman–Ford, or Dijkstra's algorithm) primarily to compute a distance matrix between each node. The distance matrix can then be leveraged while solving the TSP portion of the problem: finding a tour through the locations and using the total time as the weight.
The next step is up to you. If you are looking for an approximate solution, many heuristics exist for both TSP and KP: See Christofides TSP Heuristic, or the Minimum TSP and Maximum Knapsack entries at the Compendium of NP Optimization problems.
If on the other hand you seek an optimal solution, you may be out of luck. Still I recommend you find a copy of Graph Theory. An Algorithmic Approach by Nicos Christofides (ISBN-13: 978-0121743505). It provides heuristics for early backtracking in a Depth-First-Search that expedite the search for optimal solutions to several NP-Complete problems.
I want to solve a variation of shortest path algorithm. I can't figure out how to deal with additional constraints.
Few cities (<=50) are given along with two (N * N) matrices
denoting travel time between cities and toll between cities. Now given
a time t (<10000), we have to choose a path to reach from city 0
to city N-1 such that toll cost is minimum and we complete travel
within given time t.
I know that with only one parameter such as only time, we can use shortest path algorithm such as Bellman–Ford algorithm or Dijkstra's algorithm. But how to modify it so to include two constraints? How can we formulate Dynamic Programming solution for the problem?
I am trying to solve it with DP + complete search. Am I in right direction, or are there better algorithms than these approach?
It is possible to use Dijkstra for this problem, first you need to create a graph of state, with each state
represents the city and time left. So between each state (city A, time t ) and state (city B , time t1), there can only be an edge if you can move from city A to city B with the given time is (t1 - t). And the value for each edges will be the toll. Solving this using standard Dijkstra is simple.
Let's say we have a problem where there are several cities with variable path costs (in time taken) between them, and we have 2 salesmen that must visit every city at least once, between the two of them.
Now, suppose we have an algorithm that given a salesman and a set of cities, can devise an optimal path for that salesman. What we want to do is split up the cities in such a way that assigning one set to the first salesman and the other set to the other salesman gives us a solution that allows the total time taken to be as low as possible. What is a good way to do this? We want a solution thats good, but not necessarily optimal.
My thought was that we could use some sort of heuristic to determine whether a given split was good or bad, but there are a lot of cities and so picking the split is hard. I'm not entirely sure how to go about this.
To clarify: each city must be visited by at least one salesman, not both.
Edit: its more a Hamiltonian path, we don't need to return to the origin city.
I would start by running Kruskal's algorithm to find the minimum spanning tree. Then cut each edge in turn. Since Kruskal's algorithm finds the minimum spanning tree, cutting an edge should always result in two sets of cities. Check the total spanning distance for the two sets of cities. If the total spanning distance is approximately equal, then the split is worth considering, and you can run the traveling salesman (TS) algorithm on the two sets. If the TS algorithm results in two times that are approximately equal, then that's a good solution. Otherwise, continue cutting edges on the minimum spanning tree.
In a connected graph, there are n points where hungry people are standing. Every hungry person wants to go one of the k restaurants in the graph. The travel distance should be within a 1 km distance for each person. A restaurant can fit no more than CEILING[n/k] guests.
Provided the points of these hungry people and the restaurants in the area, is there an efficient algorithm that runs in polynomial time that tells whether EVERY guest can be accommodated (as in True or False)?
This sort of reminds me of the Travelling Salesman problem so is it just a modified version of it?
This is an example of a matching problem on a bipartite graph. This is much easier to solve than the travelling salesman problem and can be done in O((n+k)^3).
There are two subproblems:
Find which people can reach each restaurant
Find how to match people to restaurants to avoid overflowing the constraints
Reaching Restaurants
It is possible to compute the shortest path between any pair of points in O(n^3) by using, for example, the Floyd-Warshall algorithm.
The allowed matchings are then the connections of distance less than 1 km.
Matching people to restaurants
This matching problem can be solved by constructing a graph and then solving for the maximum flow.
An appropriate graph is to have a source node, a sink node, and a node for each person and each restaurant.
Connect the source to each person with capacity 1
Connect each person to each restaurant within 1km with capacity 1
Connect each restaurant to the sink node with capacity Ceil(n/k).
Then compute the maximum flow through this graph. Every guest can be accomodated if and only if the maximum flow is n.
There are many algorithms to compute the maximum flow. One example would be push-relabel with complexity O(V^3) where V is the number of vertices (V=n+k+2 in this problem).