.


:




:

































 

 

 

 





. 17.1. (. 11). , , .

 

   
 

, 17.1. , : . - . ( ) ()


, . ; () . "" . , . , , . , : (Block, object) clear(Object)

, Object ( ). , , , , ( ), , . obiect . , , 1, 2, 3 '■■ . (. . 17.1} : [ clear(2), ciear(4), cleart b), Cleart ), on [ a, I), on(b, 3), on f c, a)]

, . , on (, ) , .. on, on, , .

. , .

1. - , , .

2. - , ; , ,

3. , .
:

can(Action, Cond)

, Action , Cond. :

AddReis , Action. Action AddRels . , DelRels - , Action. , Action.

: move (Block, From,

Block - , From - , - . 17.1.

384 II. Prolog


17.1.

% move (Block, From, To) _

I can(Action, Condition!:

% Action , Condition

can(move{ Block, From, To), [ Clear! Block), clear! To), on [ Block, From!]):-

is_block(Block), %

objects To), % To -

\== Block, %

object(From), % From -

From \== , %

Block \==From. %

% addst Action, Relationships):

% Action Relationships

adds(move(X,From,To), [ on(xrTo), clear(From)]).

I deletest Action, Relationships):

% Action Relationships

deletes(move(X,From,To), [ on (X, Fro.".:), clear(To)]).

object (X): - % X ,

placet X) % -

; 4

is_block(X). 'i x -
i

is_block (). is_blockt b).

is_block().

place (1). place (2). place(3). place(4).

%

i

%

fe a b

% 123 4

statel ([ clear(2), clear(4), cleat(b), clearCc), on(a,l), on(b,3), on[c,a) ]).

, .


,
.

. 17.2
.
, ..
. -
: , -
17. 385


, , , , . , , :

[ slot_closed< battery), slot_closed{ film), in< battery), ok(battery), in! film), film_at_start, film_unused]

17.2.

%

%

can{ open_casef [camera__in_case]).

adds (open_case, [camera_o"utside_case]).

deletes (open_case, [camera_in_case]).

%

(close_case, [camera_outside_case, slot_closed(film),

slot closed! battery)]). addM clo~e_case, [earnera_in_case]). deletesf close_case, icamera_outside_case]).

i

cant open_slot(X), [camera_outside_case, slot_closed(X)]). adds[ cpen_slc::; X),:slot_open { X)]). deletes! open_slot (X), "!slot_closed (X) ]).

%

cant close_slot(x), [canera_cutside_case, slot_open{ X)]). adds! close_slot£ x), [slot_closed (X) ] }. deletes! close_slot(X), [slot_open(X)]).

I

cani rewind, [camera_cutside_case, ln(film), i ilm_at_end]). adds [ rewind, [ f iim_at_start]). deletes! rewind, [ f ilm_at_end]).

% -can (remove! battery), [slot_open battery), in! battery)]). can! remove! film), [slot_open (film!, in! film), film_at_start]). adda(remove! x}, (slot_empty(X)]). deletes! remove* x), [in( X) ]).

%

can! insert_new< X), [slot_open! X!, slot_empty(X)]).

adds! ir.sert_new; battery), [in (battery), ok (battery) ]).

adds [ insert_new(film), [in(film), f ilm at_start, film_unused]) -

deletes! ir.sert_new(x), [slot_empty{ x) |J.~

%

can! tke_piCtures, [in film), film at_start, fi.lm_unused,

in[ battery), ok< battery), siot_cTosed[ film), slot_closed { battery)]). adds (take__pictures, [ film_at_endj). deletes! take_pictures, [film_at_start, film_urmsed]).

% , , * (. , % ok; battery) .)

statel([canera_in_case, slot_clOSed(film), slot_closed(battery), inf film!, film_at_endr in E battery)]).


386


II. Prolog


, . (. . 17.1) : 1 on! , ), (b, }]

, , , :

[ in[ film), film at start, film unused, in(battery), ok< battery), Slot_cTo3ed< film)7 slot_closed< battery)]

, , " ", .

17.1. , 17.1, , , . " " . , ; , ( ).

17.2. (. 2), "walk" (), "push" (), "climb" () "grasp" ().

(. . 17.1). , ; on (, b}. , {.. ), . , .

1. , on (, ).
adds ,

move(a, From, b)

From. , , , .

2. move (a, From, ).
, .
:

[ clear(a), clearf b), on(a. From)]

clear(b) on (a, From) ( From = 1), clear { ). clear () , .

3. adds, ,
clear { ). - :

move (Block, a, To!

: [ clear Block), clear (To), on; Block, a}]


17.



, :

Block = - = 2

move (, , 2), . :

, move (, , 2);

, .

:

[ clear[ a), clear { ), clear [ ), clea{ ), o n { , 1), on (b, 3), (-, 2)]

move (, 1, ), on { , ). :

[ move (, , 2), move (, 1, b) ]

. , . , , - . , , . , , . , .

. 17.2. , .

Condition Goal Goals

O

PrePlar j^~n Ac lion /""" PostPlan----------- /■\
---------- 4J <J ----------- -O

State MnlSialel MidStote2 FinalStale

.. 17.2.

State Goals, FinalState, .

Goals State , FinalState = State. .

1. Goals Goal, .

2. Action, Goal .

3. Action, Condition Action, MidStatel.

4. Action MidStatel Midstate2 ( MidState2 Goal ).

5. Goals MidState2, FinalState.

388 II. Prolog


Prolog, 17.3, : plan(State, Goals, elan, FinalState)

State FinalState , Goals , a Plan , . , , , .. - . . .

17.3.

% % plant State, Goals, Plan, FinalState)

plant State, Goals, [], State!; - %

satisfied! State, Goals). % E Stale Goals

& ,

% cone, , Preplan,

'.- Action, ,

% ,

%

-Ian! State, Goals, Plan, FinalState):-

conc(Preplan, [Action ] PostPlan], Plan), %

select (State, Goals, Goal), Is

achieves; Action, Goal), 4

can(Action, Condition),

plant State, Condition, Preplan, MidStatel), \

% Action

apply! MidStatel, Action, MidState2), \ Action

plan(Mid5tate2, Goals, PostPlan, FinalState). %

% satisfied! State, Goals}: State Goals

satisfied (State, []).

satisfied (State, (Goal | Goals!):-

member (Goal, State), satisfied(State, Goals).

select(State, Goals, Goal):-
membert Goal, Goals),
not member; Goal, State), % Goal

% achieves! Action, Goal): Goal - Action

achieves! Action, Goal):-adds! Action, Goals), member! Goal, Goals).

% apply! State, Action, NewState):

% Action, State,

I NewState

apply! State, Action, NewState):-deletes! Action, DelList), delete_ali(State, DelList, Statel),!, adds! Action, AddList), cone! AddList, Statel, NewState),

% delete_all{ LI, L2, Diff):


17.



% Diff - , L1

delete_all< [ ], _, []).

delete all I [X | LI], L2, Diff):-member! X, L2),!, deiete_ailf Ll, L2, Diff).

delete_all(PJ.1: L2, [X ' Diff]):-

, , . 17.1, :

?- Start - [ clear(2), clear{ 4), Clear(), clear) ), (, 1), on (, 3),

oni , ) ], plan! Start, (on { , b)],Plan, FinState).

Plan - [ move (, a, 2), nove { a, 1, to} 1

FinState- [ on! a, b), clear(1), on[ c, 2).clear{ a), clear [ 4), clear{ c),

on f b, 3) ]

, , , . , FixBattery, , FixCamera.

?- Start = [ camera in case, slot closed! film;, slot closed (battery),

in(film), film at e"nd," in{ battery)],

plan(start, [ ok ("battery)!, FixBattery, _).

FixBattery = [ open_case, open_slot(battery), remove (battery),

?-SStarte= [ acame7a in case, slot c.lo5ed(film), slot closed ( battery),

in< film), film_at_e-nd,-in[ battery)],

can [ takejictures, CameraReady), 1

plant Start, CameraReady, FixCamera, FinState).

CameraReady = [ in (film), filM_at_Start, film_unused, in! battery),

ok(battery), slot closed(film), slot closed* battery)]

FixCamera - [ open_case, rewind, oPen_slot< film), remove! film),

insert new! film), open slot! battery), remove! battery),

insert>w(battery), close slot (film,,, close slot! battery)]

Finstate = [ slot_closed(battery), slot closed! film), in! battery),

okf battery), in{ film), film_at_start, film_unused, camera_outside_case;

, . . .





:


: 2015-10-01; !; : 526 |


:

:

, ; , .
==> ...

1577 - | 1365 -


© 2015-2024 lektsii.org - -

: 0.072 .