I have three Java model classes: Map, Room, Object. These are mapped from the following XML file using JAXB:
<map>
<room id="1" name="Stairway" east="2"/>
<room id="2" name="Kitchen" north="4" south="3" west="1">
<object name="Hat"/>
</room>
<room id="3" name="Hallway" east="1" south="4">
<object name="Money"/>
</room>
<room id="4" name="Bathroom" south="2"/>
</map>
A Map contains Rooms and a Room can contain Objects. Each Room has attributes indicating which other Rooms can be reached from there (north/east/west/south).
E.g. possible directions from room 3:
room 1 (east)
room 4 (south)
There is also a seperate list of Objects, let's call them targets.
The goal is to "collect" all targets, meaning create a path through the Rooms which contain the targets.
You can think of it as a graph (Map) with nodes (Room) and edges (directions north/east/west/south that lead to another Room).
public Route findRoute(Map map, Room startRoom, List<Object> targets) {
// walk through the map, find all targets
// once found them all return the route
}
So basically I am looking for a clean way/algorithm to create a path through that graph where each node contains an Object from my target list.
I know the Dijkstra algorithm but I think it does not fit my use case as I have a condition that must be met (a Room must contain a specific Object). There are few other path finding algorithms, but I couldn't figure out a solution for my particular problem.
Any help appreciated.
EDIT:
Any path will do (shortest path is a nice-to-have, but not mandatory) and the order of which the targets are collected does not matter.