5

What would be a good heuristic to use to solve the following challenge?

Quality Blimps Inc. is looking to expand their sales to other cities (N), so they hired you as a salesman to fly to other cities to sell blimps. Blimps can be expensive to travel with, so you will need to determine how many blimps to take along with you on each trip and when to return to headquarters to get more. Quality Blimps has an unlimited supply of blimps.

You will be able to sell only one blimp in each city you visit, but you do not need to visit every city, since some have expensive travel costs. Each city has an initial price that blimps sell for, but this goes down by a certain percentage as more blimps are sold (and the novelty wears off). Find a good route that will maximize profits.

https://www.hackerrank.com/codesprint4/challenges/tbsp

This challenge is similar to the standard Travelling Salesman Problem, but with some extra twists: The salesman needs to track both his own travel costs and the blimps'. Each city has different prices which blimps sell for, but these prices go down over his journey. What would be a fast algorithm (i.e. n log n ) to use to maximize profit?

The prices of transporting the items in a way makes the TSP simpler. If the salesman is in city A and wants to go to B, he can compare The costs of going directly to B vs. costs of going back to Headquarters first to pick up more blimps. I.e. is it cheaper to take an extra blimp to B via A or to go back in-between. This check will create a series of looped trips, which the salesman could then go through in order of highest revenue. But what would be a good way to determine these loops in the first place?

Ari
  • 1,974
  • 19
  • 30
  • Not necessarily loops. The salesman may decide to go for example `HQ->A->B->C->D->C->B->E->B->A->HQ` if the cost of back tracking is less than continuing to another city. – Shahbaz Feb 04 '13 at 16:27
  • Traveling Salesman and O(nlogn) does not go well together (unless P=NP, and then who knows). However the problem smells more like a [spanning tree](http://en.wikipedia.org/wiki/Spanning_tree) to me. – amit Feb 04 '13 at 16:36
  • 1
    @amit, if P=NP, an `O(nlogn)` solution to TSP would really embarrass everyone – Shahbaz Feb 04 '13 at 17:05
  • @Shahbaz, you can only sell one unit in a city, so you cannot return to the same city twice. – Ari Feb 04 '13 at 22:59
  • @amit, its just an approximate solution, and i think it needs to be in less than O(n^2) to finish in given time. – Ari Feb 04 '13 at 23:04
  • @Ari The problem description puts a lower cost (0.2-0.4) to move a balloon than the cost for salesman to move (1.0). So, as long as the angle BAC<90 it should be optimal to visit both destinations at once (where A is the origin, B is the first destination and C is the second destination. The 90 degree threshold is the lower limit. – ElKamina Feb 05 '13 at 01:38
  • @ElKamina, Its 0.2 ≤ C ≤ *4*. I.e. the blimps can cost 4x the person's cost. – Ari Feb 05 '13 at 02:30

4 Answers4

3

This is a search problem. Assuming the network is larger than can be solved by brute force, the best algorithm would be Monte Carlo Tree Search.

Tyler Durden
  • 11,156
  • 9
  • 64
  • 126
3

Algorithms for such problems are usually of the "run the solution lots of times, choose the best one" kind. Also, to choose what solution to try next, use results of previous iterations.

As for a specific algorithm, try backtracking with pruning, simulated annealing, tabu search, genetic algorithms, neural networks (in order of what I find relevant). Also, the monte carlo tree search idea proposed by Tyler Durden looks pretty cool.

maniek
  • 7,087
  • 2
  • 20
  • 43
0

I have read the original problem. Since the number of cities is large, it is impossible to get the exact answer. Approximation algorithm is the only choice. As @maniek mentioned, there are many choices of AA. If you have experience with AA before, that would be best, you can choose one the those which you are familar with and get a approximate answer. However, if you didn't do AA before, maybe you can start with backtracking with pruning.

As for this problem, you can easily get these pruning rules:

  1. Bring as few blimps as possible. That means when you start from HQ and visit city A,B,C..., and then return to HQ(you can regard it as a single round), the number of blimps you brought is the same as the cities you will visit.
  2. With the sale price gets lower, when it becomes lower than the travel expense, the city will never be visited. That gives the ending of backtracking method.

You can even apply KNN first to cluster several cities which located nearby. Then start from HQ and visit each group.

To sum up, this is indeed an open problem. There is no best answer. Maybe in case 1, using backtracking gives the best answer while in case 2, simulated annealing is the best. Just calculate the approximate answer is enough and there are so many ways to achive this goal. All in all, the really best approach is to write as many AAs as you can, and then compare these results and output the best one.

songlj
  • 927
  • 1
  • 6
  • 10
0

This looks like a classic optimization problem, which I know can be handled with the simulated annealing algorithm (having worked on what I think was the first commercial use of simulated annealing, the Wintek electronic CAD autoplacement program back in the 1980's). Most optimization algorithms can handle problems of many variables like yours -- the question is setting up the fitness algorithm correctly so you get the optimum solution (in your case, lowest cost).

Other optimization algorithms may be worth a look -- I just have experience in implementing the simulated annealing algorithm.

(If you go the simulated annealing route, you might want to get "Simulated Annealing: Theory and Applications (Mathematics and Its Applications" by P.J. van Laarhoven and E.H. Aarts, but you will have to hunt it down since it is out of print (it might even be the book I used back in the 1980's).)

Mark Leighton Fisher
  • 5,609
  • 2
  • 18
  • 29