Upload
nguyenthu
View
225
Download
0
Embed Size (px)
Citation preview
©
Christian Jacob
Chapter Overview
Chapter 5
Problem Solving
before
Programming
5.1 Problem-Solving Strategies
5.2 Algorithms as Paths Through “Problem Spaces”
5.3 Givens, Goals, and Resources
5.4 Analysing and Exploring Problem Spaces
5.5 From Blind Search to Informed Search
5.6 Analytical Reasoning
5.7 The Analogical Approach
5.8 References
Page 2
Chapter 5: Problem Solving before Programming © Christian Jacob
Prev Next Last
oblems is like
o already solved
First Back TOC
5.1 Problem-Solving Strategies
Finding algorithmic solutions to programming prsolving mysteries in detective stories.
• Analytical problem-solving:
- the “Hercule Poirot” approach
- careful laying out of the evidence
- logically putting together little clues
• Analogical approach:
- the “Jane Marple” approach
- finding solutions by analogy or comparison tproblems
Page 3 Chapter 5: Problem Solving before Programming © Christian Jacob
Prev Next Last
— at least for
First Back TOC
• Trial and error, hacking:
This approach is, of course, less recommended beginners.
Page 4
Chapter 5: Problem Solving
before
Programming
© Christian Jacob
Prev Next Last
Problem
viour intended to
into a particular
at a computer can e steps or
First Back TOC Algorithms as Paths Through “Problem Spaces”
5.2 Algorithms as Paths Through “Spaces”
Algorithm: a precise specification of a behasolve a well-defined problem
Coding: the translation of an algorithmprogramming language
Program: a step-by-step execution plan thperform as a sequence of simplinstructions
Page 5
Chapter 5: Problem Solving
before
Programming
©
Christian Jacob
Prev Next Last
es.
computer
e Noun
First Back TOC Algorithms as Paths Through “Problem Spaces”
Sequences can have complex underlying structur
Example: sentences
Dagwood likes his fast
Name Verb Pronoun Adjectiv
Subject Predicate Object
Sentence
Page 6
Chapter 5: Problem Solving before Programming © Christian Jacob
Prev Next Last
s and goals.
transform a
givens to goals in a
different problems nments).
First Back TOC Givens, Goals, and Resources
5.3 Givens, Goals, and Resources
• Givens: initial conditions of the problem(the way things are)
• Goals: desired state(s)(the way things should be)
Any problem can be formulated at least as given
•
Resources
: the means or methods that canproblem state into another,in order to move the solver fromstep-by-step manner
Differences in givens, goals, and resources make (example: different levels of programming enviro
Page 7 Chapter 5: Problem Solving before Programming © Christian Jacob
Prev Next Last
lities
: the givens, goals, r.
ogramming
First Back TOC Givens, Goals, and Resources
Examples:
• Game playing
- Given: initial game setup
- Goal: win!
- Resources: possible moves
• Preparing a meal
- Givens: available ingredients and cookin faci
- Goal: end up with something to eat
- Resources: recipe, the cook’s experience, ...
Note
: Many of our daily problems are ill-definedresources, or combinations of the three, is
unclea
Example: client — application programmer — prlanguage — computer
Page 8 Chapter 5: Problem Solving before Programming © Christian Jacob
Prev Next Last
em Spaces
s, generated by or moves, which en state to a goal
F C / P G F G / P C
P F C / G P F G / C
G / P F C F / P G C
P G / F C P F / G C
/ P F G C
First Back TOC Analysing and Exploring Problem Spaces
5.4 Analysing and Exploring Probl
Problem space: a complete set of possible stateexploring all the possible steps,may or may not lead from a givstate.
P F G C /
F G C / P G C / P F
P G C / F
C / P F G
P C / F G
Page 9
Chapter 5: Problem Solving
before
Programming © Christian Jacob
Prev Next Last
of a problem?
them?
on?
s and other states
eces?
y independent or
oal? How can they
lution?
First Back TOC Analysing and Exploring Problem Spaces
What should we know for a preliminary analysis
• What are the givens? Do we really have all of
- Are the givens specific to a particular situati
- Can we generalize
?
- Is there a
notation
that represents the givensuccinctly?
• What is the
goal
?
- Is there are single goal, or are there several?
- If there is a single goal, can it be split into pi
- If there are several goals or subgoals, are theare they connected?
- Are there obstacles to overcome to reach a gbe overcome?
- Are there any constraints on developing a so
Page 10 Chapter 5: Problem Solving before Programming © Christian Jacob
Prev Next Last
cedures, rules,
reconditions, to be
ces that meet the
source, what
esource, what stays
roblem?
First Back TOC Analysing and Exploring Problem Spaces
• What are the resources (moves, operators, protransformations)?
- For each resource, are there constraints, or paddressed before applying it?
- If so, are there other, possibly simpler, resourpreconditions?
- What are the variants? When you apply a rechanges?
- What are the invariants? When you apply a rthe same?
- Are there more powerful resources for this p
- Would someone else know these resources?
- ...
Page 11
Chapter 5: Problem Solving
before
Programming
© Christian Jacob
Prev Next Last
Search
P F G C / P F G / C
F G / P C
First Back TOC From Blind Search to Informed Search
5.5 From Blind Search to Informed
Example: the FOX-CORN-GOOSE problem
Search tree (for two actions)
P F G C /
F G C / P
P F G C / P F G C / P G C / F P F G C / P F C / G
G C / P F F C / P G
Page 12
Chapter 5: Problem Solving
before Programming © Christian Jacob
Prev Next Last
blem
F G / P C
P F G / C
F / P G C
P F / G C
First Back TOC From Blind Search to Informed Search
State space graph for the FOX-CORN-GOOSE pro
P F G C /
F G C / P G C / P F F C / P G
P G C / F P F C / G
C / P F G G / P F C
P C / F G P G / F C
/ P F G C
Page 13
Chapter 5: Problem Solving
before
Programming
©
Christian Jacob
Prev Next Last
(1)
(4)
(8)(8)
(4)(5)
(1)
(2)(3)
(12)
(2)(3)(3)
(3) / (7)
First Back TOC Analytical Reasoning
5.6 Analytical Reasoning
Example: Planning a menu for a meal
I. Preceding Courses:
A. Soup course:1. Cream of lettice2. Light sherry
B. Fish course:
1. Filet of sole Veronique
II.
Main Course:
A.
Main dish:
1.
Cornish game hen à l’orange
2. Red wine
B.
Accompanying dishes:
1.
Creamed spinach
2.
Wild rice
3. Beverage : dry white wine
Page 14 Chapter 5: Problem Solving before Programming © Christian Jacob
Prev Next Last
(1)
(5)
(9)(10)
(5)
(10)(11)
like planning a
eveloped in a top-
ttom-up
First Back TOC Analytical Reasoning
III. Following Courses:
A. Salad course:1. Assorted green2. Vinaigrette dressing
B. Dessert:1. Mandarin orange tart2. Sweet, heavier white whine
Laying out an algorithm or a problem solution ismenu.
The different parts of the problem solution are d
down
fashion.
An alternative approach would be to develop
bo
(e.g., starting from the ingredients).
Page 15 Chapter 5: Problem Solving before Programming © Christian Jacob
Prev Next Last
rugcessful
yes
yes
no
no
no
yes
?
First Back TOC The Analogical Approach
5.7 The Analogical Approach
Patient VomitingAbdominal
painFever Pulse
Dsuc
A yes yes high elevated
B yes yes no
normal
C
yes
no high normal
D no yes high elevated
E no no high elevated
F
yes yes
no elevated
Newpatient
yes yes low normal
Page 16 Chapter 5: Problem Solving before Programming © Christian Jacob
Prev Next Last
, Boston, MA: WCB/
First Back TOC References
5.8 References
• G. Blank and R. Barnes, The Universal MachineMcGraw-Hill, 1998. Chapters 2.1 through 2.5.