CS代考 CSC429/629-Spring 2022

% Homework 2 (hw2.txt)-CSC429/629-Spring 2022
% Due: on Canvas Feb. 25, 2020 11:59 pm.
% Total points: 5
% Lateness penalty: -1 per day.

Copyright By PowCoder代写 加微信 powcoder

% This is a 1 or 2 person assignment. Type your name(s) below:
% If 2 persons work on this, they only need to turn in
% one paper copy, but both of you should submit a
% duplicate copy on Canvas under each of your names.
% You may not collaborate with anyone except your partner.
% By submitting this assignment, you implicitly agree to
% abide by the Academic Integrity Policy.

% Edit this file to add your solution in Step 1 and 2 below.
% Make your solution readable using indentation and white
% space. Do not use a line length that will wrap when printed.
% To run this file, rename it with a .pl extension if your are
% using SWI Prolog, or the proper extension for whatever Prolog
% you are using. (You may use any standard Prolog interpreter.)

% What to turn in:
% 1. Submit a copy of your program on Canvas named hw2.txt.
% The digital copy will be used in case the grader needs to
% run your program to verify that it works, and to determine
% the submission time if late. Each student on a team should
% submit a duplicate copy on Canvas under his/her own name.
% 2. Submit a copy of your screen shots on Canvas as
% a .pdf file. Turn in one document with all
% screen shots. Do not use a phone to photograph the screen.
% Eact student on a team should submit a copy on Canvas
% under his/her own name.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This homework uses a forward-chaining (FC) rule interpreter.

% Instructions for using the FC rule interpreter:
% 1. Copy fig15_7_mod_1.6.17.pl (my version of Bratko’s)
% from Canvas to your computer. (The ‘not’ operator
% has been fixed.)
% 2. Start Prolog on your HW2 program. Before running HW2,
% you need to tell Prolog to also use fig15_7_mod_1.6.17.pl
% (in SWI Prolog, you would use menu commands: File
% menu -> Consult -> fig15_7_mod_1.6.17.pl)
% 3. Warnings: if you run the program more than once,
% retract the facts, or just QUIT prolog and start
% over to flush the facts from memory. Also, note that
% the right-hand side of the expert system rules may not
% contain ‘and’, ‘or’, or ‘not’!

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Problem: Implement a forward-chaining expert system in Prolog
% that uses the FC rule interpreter in fig15_7_mod_1.6.17.pl. The
% system plans a 2-day trip. First the system should ask the user
% questions: which of moutain or beach the user prefers, a high
% budget or a low one, have kid(s) or not. Then it should use the
% answers to plan a suitable trip for the user. Start the program
% with a predicate called “trip”. See emamples below.

% There are a few requirements/notes here.

% 1. Plans for different user answers must be different. In the
% screenshot, please include output for all possible user answers.
% In the given example, there are 3 questions and thus 8 possible
% answers.

%2. The plan for each day should contain at least 3 activities and
% thus 3 rules in Step 2.

%3. Do not write one big rule for each plan. That is, there must be
% at least one rule that are used across different plans. Also use
% the connective “or” at least once.

%4. Your designed trips are NOT necessarily the same as the given
% examples. But please keep the steps “plan day1”, “day1 finish”,
% “plan day2”, and “day2 finish”. You may change any other activity.
% Please also do not change the set of questions.

% Examples (Include these and other examples in screen shots):

% ?- trip.
% mountain or beach (m or b)?: b.
% high budget or low? (h or l): l.
% have kid(s)? (y or n): y.
%Derived: plan day1
%Derived: drive to myrtle beach
%Derived: enjoy the sunshine on the beach
%Derived: dinner at IHOP
%Derived: day1 finish
%Derived: plan day2
%Derived: bycling
%Derived: enjoy sunshine on the beach again
%Derived: drive home
%Derived: day2 finish
%No more facts

% ?- trip.
% mountain or beach (m or b)?: b.
% high budget or low? (h or l): h.
% have kid(s)? (y or n): n.
%Derived: plan day1
%Derived: drive to myrtle beach
%Derived: enjoy sunshine on the beach
%Derived: dinner at an italian restaurant
%Derived: day1 finish
%Derived: plan day2
%Derived: helicoper adventures
%Derived: broadway show
%Derived: drive home
%Derived: day2 finish
%No more facts

% ?- trip.
% mountain or beach (m or b)?: m.
% high budget or low? (h or l): l.
% have kid(s)? (y or n): n.
%Derived: plan day1
%Derived: drive to gatlinburg
%Derived: hiking
%Derived: drive through for dinner
%Derived: camping
%Derived: day1 finish
%Derived: plan day2
%Derived: laurel falls trail
%Derived: Popeyes
%Derived: drive home
%Derived: day2 finish
%No more facts

% ?- trip.
% mountain or beach (m or b)?: m.
% high budget or low? (h or l): h.
% have kid(s)? (y or n): y.
%Derived: plan day1
%Derived: drive to gatlinburg
%Derived: dollywood
%Derived: find a local restaurent for dinner
%Derived: day1 finish
%Derived: plan day2
%Derived: ripley’s aquarium
%Derived: cades cove
%Derived: drive home
%Derived: day2 finish
%No more facts

%%%%%%%%%% Implementation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Directives (must be at the top of your SWI Prolog program.
% Syntax may differ in other Prolog interpreters. This is
% needed so the program can assert the fact predicate.
:- dynamic fact/1 .

% Operator definitions needed for forward chaining if-then rules.
:- op(800,fx,if).
:- op(700,xfx,then).
:- op(300,xfy,or).
:- op(200,xfy,and).

% The following line should be included in your program:
trip :- dialogue, forward.

% Then you can start your program by typing this:
% ?- trip.
% Define ‘dialogue’ in Step 1 below.
% ‘forward’ starts Bratko’s forward chaining
% rule interpreter on your rules in step 2.

% Step 1 (2 points):
% Implement the predicate dialogue in Prolog.
% dialogue asks questions, reads in the answers, and
% asserts the user’s answers as facts.

% Type your solution to step 1 here:

% Step 2 (3 points): Type your FC rules HERE:
% Warning: ‘and’, ‘or’, and ‘not’ can only be used in the
% ‘if’ part (condition) of the expert system rule. If
% you put them in the ‘then’ part, you probably will
% not get an error/warning, but your rules won’t work correctly!
% See Canvas lecture notes for more info on rule syntax.
% Don’t forget to use consult to load Bratko’s FC rule interpreter
% before running your program. Don’t forget to clear memory
% before each run by restarting Prolog and then consult again.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com