-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Tree-Search-and-Graph-Search.md
Testing out a new GENERIC-SEARCH pseudocode for 4e. @MrDupin @ctjoreilly @redblobgames you've looked at search -- what do you think of this approach?
- Loading branch information
Showing
1 changed file
with
10 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44e38dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the new version.
From my understanding, there is some added cost in computation (since the cost of a path needs to be calculated each time, in
cost(c)
andcost(solution)
- although I can see that we can store the cost to each path without much hassle), and it also seems that there is an added memory cost (storing paths instead of nodes).Despite that, I think this is a more "complete" algorithm, since we not only get the cost of the solution, but the path itself. In most search algorithms, to find the final path there needs to be employed some sort of auxiliary functionality (usually setting the parent of each node and then backtracking from the final node). Here we return the path, and the cost can be calculated later using the
cost
function. This is neat.Also, I feel like this approach is closer to what search in general entails. We want to search for the best path in a set of possible paths, and this approach does that in a cleaner way. Previously we were basically expanding nodes and keeping score of the cost-so-far, which is conceptually a bit further away from the problem at hand.
Regarding Python, this will be easy to implement + we get to print the path to the goal state instead of just its cost, without the use of external functions. This, I feel, will be beneficial to students.
Finally, and this is just a personal anecdote, when I was studying search algorithms I always wondered why didn't we store paths instead of nodes, since it seemed easier.
All in all, I am for this change.
44e38dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the new version somewhat better except it's unclear to me what 'path' means. The frontier contains nodes, right? What is the node 'state'? Where do we get the "previous path to child's state"? (I haven't seen the text of the 4e book yet so maybe it's explained there)
Some A* code will not “add child to frontier” if there was a previous path to it, but instead reprioritize the existing node. I don't do this in practice but it is a reasonable way of handling the situation so that you don't re-evaluate the node with the worse path after you've evaluated the node with the better path.
44e38dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, reading the “code like” version you added after this commit answers some of my questions. Those two versions are pretty similar and seem like they could be merged. I was confused in part because in my code I put the state into the frontier and store the path externally.
The
c
is returned bysuccessors(parent)
. Isc
a state or a path? If it's a state, thenc.state
doesn't make sense. If it's a path, thenc not in reached
doesn't make sense, asreached
is a map of states. Maybe you meanc.state not in reached
andreached[c.state] <-- c
andif c.state is a goal
. Static typing ftw :)44e38dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the "what is
c
" thing, I assumed it was actually both a state and a path, and that it is written a bit "fluidly". Thesuccessors(parent)
method extends the path in all possible ways. That means, it adds a state to the path whenever adding a state is possible. What it returns is both the extended path and the state.If that is indeed the case, maybe it needs to be written more clearly? Maybe something like
for path, state in successors(parent)
or assumec
is an object andc.path
andc.state
its properties. That would clear things up. Re-reading the pseudocode I also got a bit confused as to whatc
is.