Assignment Search Framework
|
This page is not intended to teach you C++, but can give you some quick tips on things that may be unfamiliar. Most of these will not matter for the implementation work you will have to do for the assignment, but may help when reading the code.
First, be aware that the code is intended to allow for quickly implementing new domains and running existing algorithms on them. As such, there is extensive use of templates. Classes that use templates begin their class definition with 'template<class T>'. This means that the defined code can be used for various different types. 'T' is just a standin for whatever type you will use. For example, the vector class is defined as vector<T> since it is a container that can hold just about anything. To create a vector for 'double' values, you would write vector<double>. Our class definitions would work similarly.
Of particular note, you may recall that in C one usually puts the function definition in a header file and the function implentation in another file (usually a '.c' file). Templated functions and classes don't allow for this (the reason why is technical), so the implmentations of these will be in the header file for such templated cases.
The codebase also uses inheritance to separate parts of the search algorithms that are in common. For example, in best_first_search.h, you can see the following:
template<class state_t, class action_t>
class BestFirstSearch: public SearchEngine<state_t, action_t>
This says that the BestFirstSearch class inherits from SearchEngine using template types state_t and action_t.
You will see functions designated as 'virtual', which means that the function can be overloaded in a child class, and when this is done, call the child's version of the function by default. If the function definition has '= 0' at the end, this means it is an abstract function in an abstract class.
Of note, mixing inheritance and templates can get a bit ugly at times. In particular, while one can usually access the parents protected or public member variables or functions from a child, you have to be a bit more explicit when templates are involved. For example, at the beginning of the definition of best_first_search.h you will see the following:
using SearchEngine<state_t, action_t>::goal_test;
This means that when 'goal_test' is used to in the BestFirstSearch code, it refers to the member variable 'goal_test' from the parent class SearchEngine.
This section just contains a number of particular quick notes.