I have my A* pathfinding algorithm right now working such that given a graph it can find the route from one starting node to one goal node.
This works well for many problems, but sometimes I find that multiple goal nodes are valid.
For example, in a game, an NPC might have to go to a switch to shut a door. If there are multiple switches that shut the door in question, it doesn't matter which switch it goes to - it just needs to go to one of them.
How can I augment my pathfinding algorithm to find the path to the best goal (the shortest path)? As in, the algorithm searches for multiple goals and when it finds just one, it returns the path to that one.
One solution would be to run the algorithm as many times as there are valid goals, but you can guess why that might be inefficient.