Anda di halaman 1dari 38

Strategi Penyelesaian Masalah

Strategi Penyelesaian Masalah


Untuk membangunkan sistem yang dapat meyelesaikan sesuatu masalah, perlu bbrp strategi:
Takrifkan Analisis

masalah secara tepat

Masalah

Asingkan

dan wakilkan pengetahuan yang perlu untuk penyelesaian masalah kaedah penyelesaian masalah yang terbaik

Pilih

Persoalan terhadap strategi penyelesaian


Adakah penyelesai masalah terjamin mendapat penyelesaian?? Adalah penyelesai masalah selalunya menamatkan pencarian atau terperangkap dalam keadaan tak terhingga?? Apabila penyelesaian ditemui, adakah penyelesaian itu optimum?

Apakah kekompleksan proses carian? Bagaimana mengurangkannya? Bagaimana mendapatkan pewakilan keadaan yang terbaik?

Graf Ruang Keadaan


Salah satu alatan utama dalam penyelesaian masalah mewakilkan masalah dalam bentuk graf ruang keadaan. menggunakan teori graf dalam analisis struktur dan kekompleksan masalah dan proses carian.

Graf Ruang Keadaan


Graf terdiri daripada nod dan lintasan/pautan yang menghubungkan pasangan nod. Micro-world Problems

Graf Ruang Keadaan: Contoh Bridges of Konisberg Problem


Bandar Konisberg menggunakan dua tebing dan dua pulau bagi satu sungai. Pulau dan tebing sungai dihubungkan dengan tujuh jambatan seperti gambarajah. Masalah jambatan2 Konisberg ialah adakah terdapat laluan mengelilingi bandar yang melintasi setiap jambatan hanya sekali.

Masalah Bandar Konisberg


Riverbank 1

2 Island 1 5

3 1

Island 2

Riverbank 2

Masalah Bandar Konisberg

The people wondered whether or not one could walk around the city in a way that would involve crossing each bridge exactly once.

Masalah Bandar Konisberg

Leonhard Euler proposed a problem about this city, a sort of brain teaser: Walk around the city, crossing each bridge exactly once while ending where you started

Masalah Bandar Konisberg

Problem 1 Try it. Sketch the above map of the city on a sheet of paper and try to 'plan your journey' with a pencil in such a way that you trace over each bridge once and only once and you complete the 'plan' with one continuous pencil stroke.

Having trouble? That's okay, so did Euler. It doesn't seem possible to cross every bridge exactly once. In fact it isn't. To find out why, go to Some failed attempts to solve the problem:

Euler realized that all problems of this form could be represented by replacing areas of land by points (he called them vertices), and the bridges to and from them by arcs. For Konigsberg, let us represent land with red dots and bridges with black curves:

In order to solve the problem, to prove that it was not possible to do this, Euler developed a formal mathematical representation which has the first definition of a graph.

The graph for the city:

B C D

Graf Sistem Jambatan Kronisberg


rb1 b2 b4 b1 b6 b7 b5

i1

i2

rb2

Knowledge Representation: Predicate Calculus


connect(i1, i2, b1) connect(rb1, i1, b2) connect(rb1, i1, b3) connect(rb1, i2, b4) connect(rb2, i1, b5) connect(rb2, i1, b6) connect(rb2, i2, b7)

connect(i2, i1, b1) connect(i1, rb1, b2) connect(i1, rb1, b3) connect(i2, rb1, b4) connect(i1, rb2, b5) connect(i1, rb2, b6) connect(i2, rb2, b7)

connect(X, Y, Z)=connect(Y, X, Z)

A Water Jug Problem


You are given two jugs, a 4-gallon one and a 3gallon one. Neither has any measuring markers on it. There is a pump that can be used to fill the jugs with water. How can you get exactly 2 gallons of water into the 4-gallon jug.

A Water Jug Problem:


The state space

Can be described as set of ordered pairs of integers


(x, y) x = 0, 1, 2, 3 or 4 x number of gallons of water in the 4 - gallon jug y = 0, 1, 2, or 3 y the quantity of water in the 3 - g allon jug

A Water Jug Problem:


The state space

(x, y) start state : (0, 0) goal state : (2, n) for any value of n

A Water Jug Problem:


The representation
Rules representation e.g. (x, y) (4, y) if x<4

current state

new state

A Water Jug Problem:


Assumption

can fill a jug from the pump can pour water out of a jug into the ground can pour water from one jug to another there are no other measuring devices

A Water Jug Problem:


Rules
1 2 3 4 5 6 (x, y) if (x < 4) (x, y) if (y < 3) (x, y) if (x > 0) (x, y) if (y > 0) (x, y) if(x > 0) (x, y) if (y > 0) (4, y) (x, 3) (x d, y) (x, y - d) (0, y) (x, 0) Fill the 4-gallon jug Fill the 3-gallon jug Pour some water out of the 4gallon jug Pour some water out of 3-gallon jug Empty the 4-gallon jug on the ground Empty the 3-gallon jug on the ground

A Water Jug Problem:


Rules
7 (x, y) if (x+y) 4 and y > 0 (4, y-(4-x)) Pour water from the 3-gallon jug into the 4-gallon jug until the 4-gallon jug is full Pour water from the 4-gallon jug into the 3-gallon jug until the 3-gallon jug is full Pour all water from 3-gallon jug into 4-gallon jug

(x, y) if (x+y) 3 and x > 0

(x-(3-y), 3)

(x, y) if (x+y) 4 and y > 0

(x+y,0)

A Water Jug Problem:


Rules
10 (x, y) if (x+y) 3 and x > 0 (0, x+y) Pour all water from 4-gallon jug into 3-gallon jug Pour 2 gallons from 3-gallon jug into 4-gallon jug Empty the 2 gallons in the 4gallon jug on the ground

11

(0, 2)

(2,0)

12

(2, y)

(0,y)

One solution to the Water Jug Problem


Gallons in the 4 Gallon Jug 0 0 3 3 4 0 2 Gallons in the 3 Gallon Jug 0 3 0 3 2 2 0 Rule Applied

2 9 2 7 5 or 12 9 or 11

Here, the first jug is full (with 20 litres), and the target is to fill the last jug with exactly 4 litres. The two other jugs (of capacity 8 and 5 litres respectively) can be used as intermediate storage.

The Water Jugs Problem

The Water Jugs Problem

Our study of planning and learning will parallel the study of problem solving. You will first modify and extend the rules you wrote for the Water Jug problem and then the Missionaries and Cannibals problem.

The Traveling Salesman Problem


A 75 E 100 125 C D 100 125 100 B 125 75 50

Seorang jurujual mempunyai 5 bandar untuk dilawati dan mesti pulang keasal. Gol bagi masalah ini ialah mencari laluan terpendek untuk pengembaraan jurujual , melawati setiap bandar dan pulang ke bandar permulaan.

50

The Traveling Salesman Problem


A 75 E 100 125 C D 100 125 100 B 125 75 50

nod graf mewakili bandar setiap lintasan dilabel dengan nilai pemberat menandakan kos melalui lintasan tersebut kos ini boleh mewakili jarak yang perlu utk laluan kereta atau kos laluan penerbangan antara dua bandar

50

The Traveling Salesman Problem


A 75 E 100 125 C D 100 125 100 B 125 75 50

laluan [A, D, C, B, E, A] dengan kos 450 km adalah satu contoh litar yang mungkin. Gol memerlukan satu litar yang lengkap dengan kos yang minimum

50

The Traveling Salesman Problem


Kemungkinan Penyelesaian
A

B C B

C D E

D E

E D

C E

The Traveling Salesman Problem


Kemungkinan Penyelesaian

Application: Optimization and Scheduling problems

Monkey & Banana Problems


There is a monkey at the door into a room. In the middle of the room a banana is hanging from the ceiling. The monkey is hungry and wants to get the banana, but he cannot stretch high enough from the floor. At the window of the room there is a box that the monkey can use. The monkey can perform the following actions: walk on the floor, climb the box, push the box around (if he is already at it), and grasp the banana if he is standing on the box and directly underneath the banana. Can the monkey grasp the banana?
http://www.compapp.dcu.ie/~alex/LOGIC/monkey.html

Monkey & Banana Problems


The monkey and banana problem is a famous problem studied in the community of logical programming. Instead of the programmer explicitly specifying the path for the monkey to reach the banana, the computer actually reasons out a possible way that the monkey reaches the banana. grab to get the banana climb to get onto the box walk for the monkey to move push to push the box to some other position. move( initial state, type of move, resulting state )

The 8 Puzzle

1 2 3 8 4

7 6 5

The 8 Puzzle Ruang Keadaan


1 7 5 8 4 3 6 2

up
1 7 5 4 8 3 6 2

right down
1 7 5 4 8 3 6 2 1 7 5 4 6 8 2 3

left
1 4 7 5 8 3 6 2

left
1 7 5 4 8 3 6 2 1 7 5 3 4 8

right
4 6 2 1 5 7 8

up
3 6 2 1 5

down
4 7 8 3 6 2 1 7

left
4 8 5 3 6 2 1 7 5

right
4 8 2 3 6 1 7 5

up
4 6 8 3 2 1 7 5

down
4 6 8 3 2

Strategi Carian Ruang Keadaan Carian Data-Driven Carian Goal-Driven Carian Dalam Dahulu (Depth First) Carian Melebar Dahulu (Breadth First) Carian Heuristik

Anda mungkin juga menyukai