Goal Directed Planning
Definition
GOAL DIRECTED PLANNING is the problem solving strategy of:
- identifying a goal
- determining the information needed to achieve the goal
- establish as subgoals the problems of securing the information needed to achieve the goal.
- ``recursively'' applying this same method to the problems established as subgoals.
Goal directed planning is a ``procedural'' variant of problem decomposition.
Problem
Given a congruent figure made up of squares with a collective area that is 187.32 square units determine the perimeter of the figure?
Solving the perimeter problem by means of goal directed planning:
- To determine the perimeter of the figure you need to know the length of the small square side, and the number of such sides.
- To determine the length of the small square side we need to know the area of the square.
- To determine the area of one small square we need to know the number of small squares, and the total area of the figure.
An approach to writing the program...
Working in a ``bottom-up'' fashion either:
- record an item of information
- compute the value
Thus....
- record the total area
- record the number of small squares
- compute the area of a small square
- compute the length of one side
- record the number of small sides around the perimeter
- compute the perimeter
This is the solution to the problem using goal directed planning.
? class ---- PerimeterApp
? Program
/ /Compute the perimeter
double totalArea = 187.32;
int nrSquares = 15;
double squareArea = totalArea /nrSquares;
double sideLength = Math.sqrt (squareArea);
int nrExternalSides = 20;
double perimeter = sideLength * nrExternalSides;
/ /Display the results
IO.print (``The perimeter is ``);
IO.print (perimeter);
IO.print (``square units.'');
IO.println ();
|
The Math Class
Form: math.sqrt (< double >) -- < double >
Meaning: Compute the square root of the perimeter.
Example: double value = Math.sqrt (16.0);
value -- 4
Form: Math.PI -- < double >
Meaning: Reference the classic greek constant 3.141 ...
Example: double r = 5.8;
double a = r * r * Math.PI;
Form: Math.pow (< double >, < double >) -- < double >
Meaning: Raise the first value to the power of the second.
Example: Math.pow (3.0, 2)
value -- 9.0
Note on Arithmetic
< int > + < int > -- < int >
< double > + < double > -- < double >
< int > + < double > -- < double >
|
Similarly for * - /
Example:
IO.println (5 / 2) -- 2
IO.println (5.0 / 2.0) -- 2.5
|