Heuristics in Graph Traversal - algorithm

I'm trying to use A* to find the optimal path in a Graph.
The context is that a tourist starts at his hotel, visits landmarks and returns to his hotel at the end of the day. The nodes (landmarks) have two values: importance and time spent. Edges have two values: time spent and cost(currency).
I want to minimize cost, maximize importance and make sure total time is under a certain value. I could find a balance between cost, importance and time for the past path-cost. But what about the future cost? I know how to do it with simpler pathfinding, but is there a method I could follow to find the heuristic I need?

You have a multi-dimensional objective (cost and importance) and so your problem is ill-posed because you haven't defined how to trade off cost and importance while you are "minimizing" cost and "maximizing" importance. You'll only get a partial ordering on sites to vist, because some pairs of sites may be incomparable because one site may have a higher cost and higher importance, while the other may have lower cost and lower importance. Look up multi-objective knapsack problem if you want concrete ways to formalize and solve your problem. And beware -- it can get a bit hairy the deeper you go into the literature.

Related

What is an optimal strategy for an user of hungarian algorithm?

I wonder what is the optimal strategy for a player to adopt when dealing with a distribution using a Hungarian algorithm.(https://en.wikipedia.org/wiki/Hungarian_algorithm)
The situation is that of a pairing between n persons and m objects, where the persons make some ordered vows concerning their favorite object.
In the total absence of information on wishes of n-1 other people, I guess the optimal strategy to maximize one’s contentment is to actually order the vows according to one’s real preferences.
However, if you know the wishes of others, or if you have an estimate of the number of times each item is asked for, I think there may be an optimal “barrage” strategy to maximize your chance of getting the first wish by placing items in high demand afterwards.
However, since weights are linear in a Hungarian algorithm, I think this dam strategy is ineffective (compared to square weights in the wish index) and potentially risky.
After a little research, I could not find any documentation on the subject. Do you have good sources describing optimal strategies to deal with this kind of algorithm?
Thank you in advance!

Improving A* algorithm

Say I am finding a path in a house using A* algorithm. Now the running time could be O(n^2).
I was thinking will it improve the performance if I knew which doors to follow and according I shall apply A* on it i.e. if I have the starting position S and final position as F, and instead of applying the A* on these two end points, will be be better if I applied the A* on
`S` and `A1`
`A1` and `A2`
`A2` and F.
Where A1 and A2 are my intermediates(doors) that shall be followed for the shortest path? Will it be worth the improvement to find the intermediates and then follow the path and not just apply A* directly on starting and ending.
Considering it takes linear time to find the intermediates.
Yes, that will help a lot in case the algorithm takes O(n^2) behavior at runtime. Instead of one big problem you get two smaller problems with each being 1/4 as expensive to compute.
I'm sure there are pathological cases where it doesn't help or even hurt but in your scenario (house) it would probably help a lot.
I imagine that you are using the fact that one has to go up an elevator or stairs to change floors. That would help A* a lot because the cost function now has to work only within a single floor. It will be very representative of the real cost. In contrast to that the cost function would be greatly underestimating the distance if you wanted to move into the same room but one floor higher. Euclidean distance would fail totally in that case (and the algorithm would degrade into an exhaustive search). First moving to the stairs and then moving from the stairs to the desired room would work much better.

Bin packing algorithm

I have a kitchen heating meals from frozen, they need to produce meals to a head count order. The meals come in frozen sizes of portions such as 4's, 6's etc. The larger sizes have a lower cost per unit. So allowing waste, how do I calculate the sizes to complete an order at the lowest cost.
This problem kind of sounds like the knapsack problem to me. I'm assuming that a greedy algorithm will not work here because there appear to be overlapping subproblems. You will probably have to use a dynamic programming algorithm which determines the minimum cost for a given head count by calculating the cost for all possible combinations of meal portions satisfying that head count.
I only pointed you in the right direction because this sounds like it might be homework. Either way this problem sounds like it can be reduced to one with a well-known solution.

How to design an optimal trip planner

I'm developing a trip planer program. Each city has a property called rateOfInterest. Each road between two cities has a time cost. The problem is, given the start city, and the specific amount of time we want to spend, how to output a path which is most interesting (i.e. the sum of the cities' rateOfInterest). I'm thinking using some greedy algorithm, but is there any algorithm that can guarantee an optimal path?
EDIT Just as #robotking said, we allow visit places multiple times and it's only interesting the first visit. We have 50 cities, and each city approximately has 5 adjacent cities. The cost function on each edge is either time or distance. We don't have to visit all cities, just with the given cost function, we need to return an optimal partial trip with highest ROI. I hope this makes the problem clearer!
This sounds very much like an instance of a TSP in a weighted manner meaning there is some vertices that are more desirable than other...
Now you could find an optimal path trying every possible permutation (using backtracking with some pruning to make it faster) depending on the number of cities we are talking about. See the TSP problem is a n! problem so after n > 10 you can forget it...
If your number of cities is not that small then finding an optimal path won't be doable so drop the idea... however there is most likely a good enough heuristic algorithm to approximate a good enough solution.
Steven Skiena recommends "Simulated Annealing" as the heuristics of choice to approximate such hard problem. It is very much like a "Hill Climbing" method but in a more flexible or forgiving way. What I mean is that while in "Hill Climbing" you always only accept changes that improve your solution, in "Simulated Annealing" there is some cases where you actually accept a change even if it makes your solution worse locally hoping that down the road you get your money back...
Either way, whatever is used to approximate a TSP-like problem is applicable here.
From http://en.wikipedia.org/wiki/Travelling_salesman_problem, note that the decision problem version is "(where, given a length L, the task is to decide whether any tour is shorter than L)". If somebody gives me a travelling salesman problem to solve I can set all the cities to have the same rate of interest and then the decision problem is whether a most interesting path for time L actually visits all the cities and returns.
So if there was an efficient solution for your problem there would be an efficient solution for the travelling salesman problem, which is unlikely.
If you want to go further than a greedy search, some of the approaches of the travelling salesman problem may be applicable - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.26.5150 describes "Iterated Local Search" which looks interesting, with reference to the TSP.
If you want optimality, use a brute force exhaustive search where the leaves are the one where the time run out. As long as the expected depth of the search tree is less than 10 and worst case less than 15 you can produce a practical algorithm.
Now if you think about the future and expect your city network to grow, then you cannot ensure optimality. In this case you are dealing with a local search problem.

better heuristic then A*

I am enrolled in Stanford's ai-class.com and have just learned in my first week of lecture about a* algorithm and how it's better used then other search algo.
I also show one of my class mate implement it on 4x4 sliding block puzzle which he has published at: http://george.mitsuoka.org/StanfordAI/slidingBlocks/
While i very much appreciate and thank George to implement A* and publishing the result for our amusement.
I (and he also) were wondering if there is any way to make the process more optimized or if there is a better heuristic A*, like better heuristic function than the max of "number of blocks out of place" or "sum of distances to goals" that would speed things up?
and Also if there is a better algo then A* for such problems, i would like to know about them as well.
Thanks for the help and in case of discrepancies, before down grading my profile please allow me a chance to upgrade my approach or even if req to delete the question, as am still learning the ways of stackoverflow.
It depends on your heuristic function. for example, if you have a perfect heuristic [h*], then a greedy algorithm(*), will yield better result then A*, and will still be optimal [since your heuristic is perfect!]. It will develop only the nodes needed for the solution. Unfortunately, it is seldom the case that you have a perfect heuristic.
(*)greedy algorithm: always develop the node with the lowest h value.
However, if your heuristic is very bad: h=0, then A* is actually a BFS! And A* in this case will develop O(B^d) nodes, where B is the branch factor and d is the number of steps required for solving.
In this case, since you have a single target function, a bi-directional search (*) will be more efficient, since it needs to develop only O(2*B^(d/2))=O(B^(d/2)) nodes, which is much less then what A* will develop.
bi directional search: (*)run BFS from the target and from the start nodes, each iteration is one step from each side, the algorithm ends when there is a common vertex in both fronts.
For the average case, if you have a heuristic which is not perfect, but not completely terrbile, A* will probably perform better then both solutions.
Possible optimization for average case: You also can run bi-directional search with A*: from the start side, you can run A* with your heuristic, and a regular BFS from the target side. Will it get a solution faster? no idea, you should probably benchmark the two possibilities and find which is better. However, the solution found with this algorithm will also be optimal, like BFS and A*.
The performance of A* is based on the quality of the expected cost heuristic, as you learned in the videos. Getting your expected cost heuristic to match as closely as possible to the actual cost from that state will reduce the total number of states that need to be expanded. There are also a number of variations that perform better under certain circumstances, like for instance when faced with hardware restrictions in large state space searching.

Resources