Call us +96895672917 | +917736882141

Project Description

Question 1

We use Prolog for logical coding, computation ( symbolic ). Relations are mentioned here mainly in functional form.

It is worth learning to show how minimal some design could be. It have a great essence in AI.

People using these languages are not major . But we have specialized international expert who work on these rare task and have high skills and trained input to make each project successful and interesting.

Q3

 

 

% There are two jugs, one holding 3 and the other 5 litres of water.
% A number of things can be done with the jugs: they can be filled, emptied,
% and dumped one into the other either until the poured-into jug is full or until the poured-out-of jug is empty.
% Devise a sequence of actions that will produce 4 litres of water in the larger jug. (Hint: use only integers.)

% —————————————————————————————————————-

fill(K,0,K):- write(‘ Fill ‘), write(K), writeln(‘-liter jug’),!.
fill(_,X,X).
empty(K,K,0):- write(‘ Empty ‘), write(K), writeln(‘-liter jug’),!.
empty(_,X,X).

pour(K1,A,A1,K2,B,K2):- A+B>K2,A1 is A+B-K2,!,
write(‘ Fill ‘), write(K2), write(‘-liter jug from ‘), write(K1), writeln(‘-liter jug’).
pour(K1,A,0,K2,B,B1):- B1 is A+B,!,
write(‘ Pour in ‘), write(K2), write(‘-liter jug from ‘), write(K1), writeln(‘-liter jug’).

main:- find(5,3,4).

find(K1,K2,X):-
find1(K1,0,K2,0,X).

find1(_,X,_,_,X):-!.
find1(K1,A,K2,B,X):-
fill(K1,A,A1),
empty(K2,B,B1),
pour(K1,A1,A2,K2,B1,B2),!,
find1(K1,A2,K2,B2,X).

[/teaser]

 

Question 2

Click here 
Q4

;===========================
; Function, a user-defined arbitrary questions and receive answers from a given set of correct answers
(deffunction ask-question (?question $?allowed-values)
(printout t ?question)
(bind ?answer (read))
(if (lexemep ?answer)
then
(bind ?answer (lowcase ?answer)))
(while (not (member ?answer ?allowed-values)) do
(printout t ?question)
(bind ?answer (read))
(if (lexemep ?answer)
then
(bind ?answer (lowcase ?answer))))
?answer
)

;========================
; The function prompts the user and allows a response in the form of yes / no
(deffunction yes-or-no-p (?question)
(bind ?response (ask-question ?question yes no y n))
(if (or (eq ?response yes) (eq ?response y))
then
TRUE
else
FALSE)
)
;=========================================================================

(defrule determine-road_Long_road “”
(not (road Long ?))
(not (road Short ?))
(not (repair ?))
=>
(if (yes-or-no-p “Do you prefer the country located far (yes/no)? “)
then
(assert (road Long selected ))
else
(assert (road Long not_selected ))
)
)

(defrule determine-road_Short_road “”
(road Long not_selected)
(not (road Short ?))
(not (repair ?))
=>
(if (yes-or-no-p “Do you prefer the country located not far away (yes/no)? “)
then
(assert (road Short selected ))
else
(assert (road Short not_selected ))
)
)

;=========================================================================
(defrule determine-geographical-position_Western_Europ “”
(road Short selected)
(not (stay in Western Europe ?))
(not (stay in Eastern Europe ?))
(not (stay in Russia ?))
(not (repair ?))
=>
(if (yes-or-no-p “Prefer to stay in Western Europe (yes/no)? “)
then
(assert (stay in Western Europe selected ))
else
(assert (stay in Western Europe not_selected ))
)
)

(defrule determine-geographical-position_Eastern_Europ “”
(road Short selected)
(stay in Western Europe not_selected)
(not (stay in Eastern Europe ?))
(not (stay in Russia ?))
(not (repair ?))
=>
(if (yes-or-no-p “Prefer to stay in Eastern Europe (yes/no)? “)
then
(assert (stay in Eastern Europe selected ))
else
(assert (stay in Eastern Europe not_selected ))
)
)

(defrule determine-geographical-position_Russia “”
(road Short selected)
(stay in Western Europe not_selected)
(stay in Eastern Europe not_selected)
(not (stay in Russia ?))
(not (repair ?))
=>
(if (yes-or-no-p “Prefer to stay in Russia (yes/no)? “)
then
(assert (stay in Russia selected ))
else
(assert (stay in Russia not_selected ))
)
)

;=========================================================================
(defrule determine-geographical-position_North_America “”
(road Long selected)
(not (stay in North America ?))
(not (stay in South-East Asia ?))
(not (stay in South America ?))
(not (stay in Australia ?))
(not (repair ?))
=>
(if (yes-or-no-p “Prefer a vacation in North America (yes/no)? “)
then
(assert (stay in North America selected ))
else
(assert (stay in North America not_selected ))
)
)

(defrule determine-geographical-position_South_East_Asia “”
(road Long selected)
(stay in North America not_selected)
(not (stay in South-East Asia ?))
(not (stay in South America ?))
(not (stay in Australia ?))
(not (repair ?))
=>
(if (yes-or-no-p “Prefer a vacation in South-East Asia (yes/no)? “)
then
(assert (stay in South-East Asia selected ))
else
(assert (stay in South-East Asia not_selected ))
)
)

(defrule determine-geographical-position_South_America “”
(road Long selected)
(stay in North America not_selected)
(stay in South-East Asia not_selected)
(not (stay in South America ?))
(not (stay in Australia ?))
(not (repair ?))
=>
(if (yes-or-no-p “Prefer a vacation in South America (yes/no)? “)
then
(assert (stay in South America selected ))
else
(assert (stay in South America not_selected ))
)
)

(defrule determine-geographical-position_Australia “”
(road Long selected)
(stay in North America not_selected)
(stay in South-East Asia not_selected)
(stay in South America not_selected)
(not (stay in Australia ?))
(not (repair ?))
=>
(if (yes-or-no-p “Prefer a vacation in Australia (yes/no)? “)
then
(assert (stay in Australia selected ))
else
(assert (stay in Australia not_selected ))
)
)

;=========================================================================
(defrule determine-cost_High “”
(not (price high ?))
(not (price average ?))
(not (price small ?))
(not (repair ?))
=>
(if (yes-or-no-p “You can spend on the trip > = 1000$ (yes/no)? “)
then
(assert (price high selected ))
else
(assert (price high not_selected ))
)
)

(defrule determine-cost_Average “”
(price high not_selected)
(not (price average ?))
(not (price small ?))
(not (repair ?))
=>
(if (yes-or-no-p “You can spend on the trip > 500$ & < 1000$ (yes/no)? “)
then
(assert (price average selected ))
else
(assert (price average not_selected ))
)
)

(defrule determine-cost_Small “”
(price high not_selected)
(price average not_selected)
(not (price small ?))
(not (repair ?))
=>
(if (yes-or-no-p “You can spend on the trip <= 500$ (yes/no)? “)
then
(assert (price small selected ))
else
(assert (price small not_selected ))
)
)

;=========================================================================
(defrule determine-cost_Nature “”
(not (nature ?))
(not (town ?))
(not (repair ?))
=>
(if (yes-or-no-p “You are going to rest on the nature (yes/no)? “)
then
(assert (nature selected ))
else
(assert (nature not_selected ))
)
)

(defrule determine-cost_City “”
(nature not_selected)
(not (town ?))
(not (repair ?))
=>
(if (yes-or-no-p “Are you going to travel around the city (yes/no)? “)
then
(assert (town selected ))
else
(assert (town not_selected ))
)
)

;=========================================================================
(defrule determine-state_1 “”
(stay in Eastern Europe selected)
(price small selected)
(town selected)
(not (repair ?))
=>
(if (yes-or-no-p “You are going to have a rest in the winter at a ski resort (yes/no)? “)
then
(assert (repair “Poland.”))
)
)

(defrule determine-state_2 “”
(stay in Western Europe selected)
(price high selected)
(town selected)
(not (repair ?))
=>
(if (yes-or-no-p “You are going to have a rest in the winter at a ski resort (yes/no)? “)
then
(assert (repair “Switzerland.”))
)
)

(defrule determine-state_3 “”
(stay in North America selected)
(price high selected)
(nature selected)
(not (repair ?))
=>
(if (yes-or-no-p “Do you prefer to relax in the summer sea (yes/no)? “)
then
(if (yes-or-no-p “Do you prefer a vacation on the East Coast (yes/no)? “)
then
(assert (repair “USA, Florida.”))
)
)
)

(defrule determine-state_4 “”
(stay in South America selected)
(price high selected)
(nature selected)
(not (repair ?))
=>

(if (yes-or-no-p “Do you prefer to relax in the summer sea (yes/no)? “)
then
(if (yes-or-no-p “Do you prefer a vacation on the East Coast (yes/no)? “)
then
(assert (repair “Brazil.”))
)
)
)

(defrule determine-state_5 “”
(stay in South-East Asia selected)
(price high selected)
(nature selected)
(not (repair ?))
=>
(if (yes-or-no-p “Do you prefer to relax in the summer sea (yes/no)? “)
then
(assert (repair “Indonesia.”))
)
)

;==========================================================================
; Rule system-banner displays the name of the expert system
; with each new start.
(defrule system-banner “The Turist Expert System ”
(declare (salience 20) )
=> ; with each new start.
(printout t crlf crlf)
(printout t “***************************************************************” crlf)
(printout t “* An expert system for choosing the country for a trip *” crlf)
(printout t “****************************************************************” crlf)
(printout t “* *” crlf)
(printout t crlf crlf)
)

;=======================================

;- – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
; Rule print-repair displays a message
; on the proposed routes,
(defrule print-repair “”
(declare (salience 20))
(repair ?item)
=>
(printout t crlf)
(printout t “Proposed country for a trip: “)
(format t “%s%n%n” ?item)
)

.

Project Details

  • Date November 20, 2015
  • Tags Prolog and Clisp