views:

235

answers:

4

Hi folks,

I want to solve the following problem:

I have a DAG which contains cities and jobs between them that needs to be done. The jobs are for trucks which can load a definied limit. The more the truck is loaded the better is the tour. Some jobs are for loading something in and some are for loading defined things out. You can always drive from city a to b even if there is no job to be done between them. The last restriction is that I always need to start in city a and return to a because there is the home of the trucks :)

I first thought of Dijkstra's shortest path algorithm. I could easly turn that into longest path calculation. My problem in mind is now that all these algorithms are for calculating a shortest or longest path from vertex a to b, but I need it from a returning to a - in a circle.

Has some one some kicks for my mind?

Thanks for your feedback!

Marco

+2  A: 

This crazy combination of knapsack and travelling salesman is surely NP-hard.

Virtually everywhere, when you want to load your agent with optimal job schedule, or when you want to build a route through all vertexes in the graph, or when you feel that you need to look for a "longest path*", you most likely run into an NP-complete or an NP-hard problem.

That means, that there is no known fast and exact solution to the problem, i.e. the one that runs in a polynomial time.

So you have to create approximations and implement non-optimal algorithms based on your particular conditions. What time loss is acceptable? Are there additional patterns the trucks can drive? Do you know more about the graph (e.g. is the area divided into distant dense regions)? Answer these questions and you'll find a non-strict heuristics that satisfies your customers.


*yes, searching for longest paths is not as easy as you think. Longest path problem is NP-complete, given that your graph is not acyclic.

Pavel Shved
Knapsack is a good hint. I forgot about that theory.
Marco
yeah longest path is NP-Complete as well
Claudiu
Here are the restrictions:1. Different load types (pallets, canisters)2. Cooling restrictions3. Driver time (9h driving time + breaks per day)The graph can be complete. There are no dense regions.But I think I will build the graph for each truck containing only the jobs that match the truck (cooling, etc.).
Marco
@Marco, sorry, but it's your job to devise a complete algorithm :). What I meant is only that, when dealing with NP-complete stuff, **restrictions are your friends**. NP-c problems are hard only on generic graphs, those without restrictions.
Pavel Shved
I didn't expect you guys to implement the algorithm :) And - sorry - thanks for all the quick answers. I am just searching for hints that can lead me to some solutions... :)
Marco
A: 

You can adjust the traveling sales man problem dynamic programming algorithm to do what you want.

The classic approach says that you want to maximize the optimum function from all cities but you can take in consideration, at each step also the possibility of returning home.

And like Pavel mentioned, this problem is definitively NP-hard. Do you have some upper bounds for the number of cities or maximum number of objects that can be loaded in a truck?

PS: Do you want the BEST solution (maximum profit - might not be realistic in terms of processing time) or you accept some approximation?

Victor Hurdugaci
I accept an approximation. I am aware of the complexity and I am hoping that I can come up with a solution.I think that there will be about 300 to 400 jobs going to various number of cities. The client it self drives to about 1000 destination which could be the end point of one of these jobs.
Marco
Some PTAS algo for Knapsack http://www-math.mit.edu/~goemans/18434/knapsack-katherine.pdf and some for TFS: http://hal.archives-ouvertes.fr/docs/00/02/87/55/PDF/tspshort_prelim.pdf . Maybe this will improve your final algorithm. 1000 destinations is not really realistic even for TFS alone. For TFS + Knapsack + ... well... you get it
Victor Hurdugaci
But. I only have to visit lets say 200 to 300 cities because there are no jobs connecting the others...
Marco
+1  A: 

You're trying to find the smallest possible way to get everything done? This reminds me of a max-flow/min-cut problem. You might be able to approximate the best answer by:

  • Connect all terminal nodes to a final end node.
  • Run one of the various maximum flow algorithms to find the max flow between a and end.
  • Return to city a. Update the graph to reflect what you just did. Repeat until all jobs are done.

The idea is that you get the most bang for every trip. Each trip after the 1st will be less efficient and less efficient, but that's to be expected.

Note: This only works because you have a DAG. Travelling salesman wouldn't be NP-Complete on a DAG, either, and it will likely be impossible to even hit all nodes on the graph. Re-reading your problem, it seems like you don't have a DAG, since you can return to city a - is that true?

Claudiu
Yeah I can return to city a. I thought it's directed because the job defines a direction. I have to weight to edges with a value and a direction... don't I?
Marco
You have a directed graph, but it's not acyclic. If it were acyclic, you'd know that once you left city B, you wouldn't be able to come back to it, so the decision on what to do upon leaving B is easy. But with cycles the problem becomes harder
Claudiu
A: 

Isn't this a Transportation problem?

Depending on the trucks number and starting points, you could add a fake transporations or add costs in order to satisfy your restrictions.

I'd also ask about truck restrictions:

  • are they all based in the same city?
  • do you have a fixed number of them?
  • and what you win if you use less then you have?
  • is there a cycle time restriction?
Victor Sergienko