next up previous
Next: Creating an instance and Up: Using Plansim to solve Previous: Goals

Evaluating a state

In order to use the informed search algorithms, we need to define a way to evaluate a simulator state, it terms of a given goal. This concept is represented by the plansim::evaluation class. In our example we have a single goal, represented by the hanoi::all_disks_in_rightmost_tower class, and define as a very simple evaluation simply counting the number of disks correctly positioned in the goal.

We will call this class hanoi::disks_in_place. It is derived from plansim::evaluation. We will take as basis the evaluation_template.hpp and evaluation_template.cpp files under the examples/templates directory. These files will be used to create the disks_in_place.hpp and disks_in_place.cpp, respectively. All occurrences of $domain$ in these files are replaced by 'hanoi', and all occurrences of $object$ in these files are replaced by the class name, in our case 'disks_in_place'.

The evaluation itself is done by defining the evaluation::evaluate_current_simulator_state method. Plansim considers that smaller evaluation states are better. So in our case, the final code looks like:

double
disks_in_place::
evaluate_current_simulator_state( const plansim::simulator* s,
                                  const plansim::evaluated_goal* goal )
  const
{
  // Downcasts to domain goal and simulator, for instance
  const simulator* cs =
    dynamic_cast<const simulator*>( s );
  // Now we may use simulator and goal objects to compute the
  // evaluation
  return( static_cast<double>( cs->get_total_number_of_disks() - 
                               cs->number_of_correctly_positioned_disks() ) );

}

Note that for this class we chose not to make it a hanoi::simulator friend, but instead we create the supporting methods in hanoi::simulator and call them from hanoi::disk_in_place.


next up previous
Next: Creating an instance and Up: Using Plansim to solve Previous: Goals
2005-04-08