jump to navigation

AUTO SCANNING VEHICLE (TESTING) December 14, 2009

Posted by integereuler in TESTING.
1 comment so far

This posting is about testing the expert system that we defined earlier.

As one of user, we will input some of the database on our own. We’ll declare the data from some of Information System students in ITS, and their vehicle license plate :

Dion owns Vehicle with number ‘P 4500 TJ’ declared as ?-plate(‘P 4500 TJ’,Dion).

Dino own Vehicle with number ‘W 5683 XD’ declared as ?-plate(‘W 5683 XD’,Dino).

Hendra owns Vehicle with number ‘P 5783 VC’ declared as ?-plate(‘P 5783 VC’,Hendra).

Anggoro owns Vehicle with number ‘AE 4088 TG’ declared as ?-plate(‘AE 4088 TG’,Anggoro).

As defined earlier, use create a predicate to run it, to search the database, and to make it looping forever.

The program  would be :

The output of the program :

AUTO SCANNING VEHICLE DEVELOPMENT December 14, 2009

Posted by integereuler in DEVELOPMENT.
add a comment

As we defined before, that this expert-system works  by scanning license plate and scanning the face of the rider. If it match, the door will open, and print to the user : ‘Thank You’.  If it isn’t, the door will closed and print to the user : ‘Show your license number’.

We’ll try this system using PROLOG. The system is defined by first inputting the database, both is the license plate and the face (in this program, we defined the ‘face’ as a ‘name’).  The database of this program may be exampled like below :

plat(‘P 1234 PP’,dion).
plat(‘B 1234 ABC’,dino).
plat(‘W 1234 WW’,hendra).
plat(‘N 1234 NN’,anggoro).
plat(‘K 1234 KK’,bayu).
plat(‘AB 1234 AB’,yoga).
plat(‘A 1234 AA’,bunga).
plat(‘DK 1234 DK’,mawar).
plat(‘D 1234 DD’,indah).
plat(‘AG 1234 AG’,harum).

Then we’ll need to defined a predicate to search within the database, as ?-nomerplat.

We’ll try to make this usefull by making this looping forever.

The program  ‘example’ would be :

LOOPING using PROLOG December 7, 2009

Posted by integereuler in TUTORIAL.
add a comment

Now, we will discuss about Looping in PROLOG. As we know, most of conventional programming languages have a looping facility that enables a set of instructions to b executed for a several times, or until a condition is met. Although, PROLOG has no looping facilities, similar looping effects can be done in some several ways, using backtracking, recursion, built-in predicates, or a combination of them.

1. Looping a Fixed Number of Times

Unlike java, which has for-loops facilities to enable a set of instructions to be executed a fixed numbers of times, PROLOG is unavailable to do that (directly), but a similar effect can be obtained using recursion, such as :

testloop(0).
testloop(N) :- N>0, write(‘Number : ‘), write(N), nl, M is N-1, testloop(M).

The testloop predicate is defined as ‘loop from N, write the value of N, then subtract one to give to M, then loop from M’. ‘And by the first clause, is defined as ‘if the argument is zero, do nothing(stop!)’.
test of the program :

?- testloop(3).
Number : 3
Number :2
Number :1
yes

2. Looping until a Condition is Satisfied

This example below shows the use of recursion to read terms entered by the user from the keyboard and output them to the screen, until a word end is encountered, using ‘disjunctive goal’(word=end).

test :- write(‘Type the word : ‘), read(word), write(‘Input was ‘), write(word), nl, (word=end; test).

?- test.
Type the word : Hello.
Input was Hello
Type the word : ITS.
Input was ITS
Type the word : end.
Input was end.
yes

3. Backtracking with Failure

As the name implies, the predicate fail, always fail, whether on ‘standard’ evaluation left to right or on backtracking. By combining it with PROLOG automatic backtracking, to search through the database to find all the clause with a special property, we can have automated looping.

This example of program below is designed to search database containing clauses representing the name, age, places of residence, and occupation of a number of people.

The database contains these values :

person(john,smith,45,london,doctor).

person(martin,williams,33,birmingham,teacher).

person(henry,smith,26,manchester,plumber).

person(jane,wilson,62,london,teacher).

person(mary,smith,29,glasgow,surveyor).

The predicate somepeople below is to search the person in the database which surname is smith

somepeople :- person(Forename, Surname, _, _, _), Surname =smith, write(Forename), write(‘ ‘), write(Surname), nl, fail.

somepeople.

The fail in somepeople predicate is used as a backtracking, which find all the database in the program.

Output of program would be :

?- somepeople.

john smith

henry smith

mary smith

yes

This below exercise would help you understand more about Looping in PROLOG.

These are taken from practical exercise 6 form book Logic Programming Using PROLOG.

Exercise number 1 :

First, indicate, how many times the program should loop. As X is N2-N1+1 (as N1 is included)

Then for N1, print the squares of N1(Nsquare), as Nsquare is N1*N1, then add N by 1, and subtract X by 1. Defined as N is N1+1, X1 is X-1

And last, loop from N and X1 as defined process(N,X1)

The program should be :

The output of program should be :

Exercise number 2 :

The program should be :

The program takes no arguments that all input from user, until the new line (end of record/ASCII number 10) or ? (ASCII number 63).

The looping is shown at predicate process(Y).

The output of program should be :

Exercise number 3 :

First create the person database like Part 3 from this chapter.

Then create a predicate that takes no argument, age40 and have it read the person database on the Age and Profession only. As person(_,_,Age,_,Profession).

It will only takes which age is greater than 40.

The program should be :

The output of the program :

IE 😉

Input and Output in PROLOG (Exercise) November 25, 2009

Posted by integereuler in TUTORIAL.
add a comment

this exercise will help you more understand about Input and Output in Prolog.
These are taken from practical exercise 5 form book Logic Programming Using PROLOG.
Exercise 1

Remember that upper case letters ASCII number is 65-90 for A-Z and 97-122 for a-z.
First determine the upper case number (X) is 64<X64,Y<91,upper(Y);lower(Y)),makelower.
If the ASCII number is between 64-91(A-Z), then add it by 32 to make it between 97-122(a-z).
The PROLOG program would be like :

Output of program :

Exercise 2 :

First, use predicates to change input and output stream (as define earlier). The point for this exercise is every terms in the output is separated by dot(.) in every line as end mark. Since the ASCII number for dot(.) is 46, the program would be :

Now test the program, first make the Input file, name it ‘in copyterms.txt’ :

Test your PROLOG program by inputting this :

The output file should appear with the name ‘out copyterms.txt’ :

Exercise 3 :

As defined before, you can read END_OF_FILE or END_OF_RECORD with negative ASCII number (-1). Therefore, the program would be :

First create the input file, name it ‘tesla.txt’ :

Test your PROLOG program :

Exercise 4 :

The combine predicate takes 2 file to be read, so first make new 2 predicates combine1(for file 1) and combine2(for file2). And have the program to read it and put seen and told in combine2 only. The PROLOG program should be :

Now make the input file, ‘in1.txt’ and ‘in2.txt’ :

Test your program :

Output of Program ‘in1+in2.txt’ :

Exercise 5 :

The last is compare predicates, first read 2 file like the combine predicates in previous number. Read all file and if the ASCII number is the same until the end of file, the both file is the same. If not then it’s not the same.

Now make 2 file which is not the same name it ‘compare1.txt’ and ‘compare2.txt’.

Test your PROLOG program, the output should be NOT SAME.

Now try to change ‘compare2.txt’ into the same file like ‘compare1.txt’

Test your PROLOG program again, the output should be SAME.

IE
😉

Input and Output in PROLOG November 24, 2009

Posted by integereuler in TUTORIAL.
add a comment

Input and Output

Prolog has facilities to enable input and output either of terms or of characters. Using terms is simpler and will be described first. Initially, it will be assumed that all output is to the user’s screen and all input is from the user’s keyboard. Input and output using external files, e.g. on a hard disk or CD-ROM. Note that, like many other built-in predicates, those for input and output described in this chapter are all unresatisfiable, i.e. they always fail when backtracking.

 

Outputting Terms

The write predicate takes a single argument, which must be a valid Prolog term. Evaluating the predicate causes the term to be written to the current output stream, which by default is the user’s screen. The built-in predicate nl has also been used many times previously in this book. It takes no arguments. Evaluating a nl goal causes a new line to be output to the current output stream.

For example :

?- write(‘Integer’), nl, write(‘Euler’).

Integer

Euler

Yes

 

Inputting Terms

The built-in predicate read is provided to input terms. It takes a single argument, which must be a variable. In the input stream, the term must be followed by a dot (‘.’) and at least one white space character, such as space or newline. The dot and white space characters are read in but are not considered part of the term. When a read goal is evaluated, the input term is unified with the argument variable. If the variable is unbound (which is usually the case) it is bound to the input value.

?- read(X).

| : Dion.

X = Dion

 

Input and Output Using Characters

Although input and output of terms is straightforward, the use of quotes and full stops can be cumbersome and is not always suitable. It would be tedious to define a predicate (using read). A much better approach for problems of this kind is to input a character at a time. To do this it is first necessary to know about the ASCII value of a character.

All printing characters and many non-printing characters (such as space and tab) have a corresponding ASCII (American Standard Code for Information Interchange) value, which is an integer from 0 to 255.

As shown in the table below :

 

Outputting Characters

Characters are output using the built-in predicate put. The predicate takes a

single argument, which must be a number from 0 to 255 or an expression that

evaluates to an integer in that range.

Evaluating a put goal causes a single character to be output to the current

output stream. This is the character corresponding to the numerical value (ASCII

value) of its argument.

For example :

?- put(92), nl, put(122).

\

Z

Yes

 

Inputting Characters

Two built-in predicates are provided to input a single character: get0 and get. The get0 predicate takes a single argument, which must be a variable. Evaluating a get0 goal causes a character to be read from the current input stream. The variable is then unified with the ASCII value of this character.

For example :

?- get(X).

|: Z

X = 90

?- get0(X).

|: Z

X = 90

 

File Output: Changing the Current Output Stream

The current output stream can be changed using the tell predicate. This takes a single argument, which is an atom or variable representing a file name, e.g.

tell(‘outfile.txt’).

Evaluating a tell goal causes the named file to become the current output stream. If the file is not already open, a file with the specified name is first created(any existing file with the same name is deleted).

The built-in predicate told takes no arguments. Evaluating a told goal causes the current output file to be closed and the current output stream to be reset to user, i.e. the user’s terminal.

The built-in predicate telling takes one argument, which must be a variable and will normally be unbound. Evaluating a telling goal causes the variable to be bound to the name of the current output stream.

 

File Input: Changing the Current Input Stream

The current input stream can be changed using the see predicate. This takes asingle argument, which is an atom or variable representing a file name, e.g.

see(‘myfile.txt’).

Evaluating a see goal causes the named file to become the current input stream. If the file is not already open it is first opened (for read access only). If it is not possible to open a file with the given name, an error will be generated.

The built-in predicate seen takes no arguments. Evaluating a see goal causes the current input file to be closed and the current input stream to be reset to user, i.e. the user’s terminal.

The built-in predicate seeing takes one argument, which must be a variable and will normally be unbound. Evaluating a seeing goal causes the variable to be bound to the name of the current input stream.

IE

😉

Auto Scanning Vehicle (ASV) November 24, 2009

Posted by integereuler in Expert System Design.
add a comment

Vehicle robbery problem has increased from time to time. Even in the State University, for example our beloved ITS. It really worries us as one of the students. The robber, usually change the vehicle number with the new one and they have the exact STNK according to it’s type. The parking system in this time, really slow and not safe. Usually some students in University, have to wait a long time to get out from the parking lot. Because of some checking (parking ticket, etc.) that takes some time. Although it may be possible that they have some important matter to do.
We need a new system to develop this situation, and as one of students who need to change the old system, our team manage to develop a new parking system. We call this Auto Scanning Vehicle (ASV). In hope with this system, parking would be more effective and safer.
This system works by scanning the outgoing vehicle by using some sensor to determine the vehicle type and number. The system would have the database to be checked with the vehicle type and number. If it was true (means checked and True) the parking door would be open, if not, the door would close itself and have it the double checked by the officer.
What about the quest? There would be no data in the database system right?
well, for this our team suggest the usage of some ‘special’ parking lot and will be checked manually.
By using the ASV system, it would be more effective because we can easily and faster for parking check. Because we will no more have to wait before getting out from the parking lot. Aside that, it would be a lot safer because the sensor will also record the face of it’s driver.

OPERATOR AND ARITHMETIC in Prolog November 11, 2009

Posted by integereuler in TUTORIAL.
add a comment

Last time, we discussed about FACTS, RULES, PREDICATE and VARIABLE. Our topic now is about OPERATOR AND ARITHMETIC.

Up to now, the function we used is still the standard one. As an alternative, we can convert a predicate to be written without parenthesis by using operator by entering a goal using op predicate. for example :

?- op(150,xfy,couple)

first argument (150) means operator precedence. It’s Integer ranged from 0 to 150. The lower the number, the higher the precedence.

second argument (xfy) is one of the following atoms :

xfy meaning that the predicate is binary (consist of 2 arguments) and is to be converted to an infix operator, as exampled below :

?-op(150,xfy,couple_with).
bill couple_with margaret.

fy meaning that the predicate is unary (consist of 1 arguments) and is to be converted to an prefix operator, for example :

?-op(150,fy,is_male).
is_male bill.

xf meaning that the predicate is unary (consist of 1 arguments) and is to be converted to an postfix operator, for example :

?-op(150,fy,is_female).
margaret is_female.

the third argument (couple) is the name of arguments that is to be converted as an operator.

it’s clearly easier using operator like bill couple_with margaret rather than predicate couple_with(bill,margaret)

Prolog also has arithmatic using a notation similiar as from algebra, as shown from table below :

1

For Example :

?- X is 24, Y is 6, Z is X*Y+X/Y.

X = 24

Y = 6

Z = 148

this exercise will help you more understand about Operator an Arithmetics in Prolog.

These are taken from practical exercise 4 form book Logic Programming Using PROLOG.

2

let’s convert all the predicates using operator which convert :

dog(fido) fido isa_dog by using ?- op(150,xf,isa_dog).

cat(mary) mary isa_cat by using ?- op(150,xf,isa_cat).

large(mary) mary is_large by using ?- op(150,xf,is_large).

small(rover) rover is_small by using ?- op(150,xf,is_small).

large_dog(X) X isa_large_dog by using ?- op(150,xf,isa_large_dog).

small_animal(A) A isa_small_animal by using ?- op(150,xf,isa_small_animal).

chases(X,Y) X chases Y by using ?- op(150,xfy,chases).

3

Output of program :

4

for the second exercise :

5

We’ll need to configure each part:

average, we can define it as AVG is (X+Y)/2

square root of each product, we can define it as SRX is sqrt(X) and SRY is sqrt(Y)

larger is defined by Z is X,X>=Y,write(Z);write(Y) means the greater one would be printed.

6

Output of program :

7

IE
😉

FACTS, RULES, PREDICATE and VARIABLE October 20, 2009

Posted by integereuler in TUTORIAL.
add a comment

Allright, back with us, The Integer Euler 😉

at the last post, we told you about How to list all possible combination using PROLOG. Here we’ll try to practice about FACTS, RULES, PREDICATE and VARIABLE.

We will give an example from the book Logic Programming Using PROLOG by Max Bramer, page 27.

Practical Exercises no.1 :

40

We know from the Question, there are 3 kinds of animal (mammal, bird, reptile) 8 different animals ( tiger, hyena, lion, zebra, eagle, sparrow, snake, lizard ) . and different attributes (such as : carnivore,herbivore, scavenger, stripes, etc).

Then, we’ll have to Devise and test goals to find some problem.

Let’s try to solve this, first enter the facts into Notepad/Wordpad.

41

Then save the file and name it animal.pl

42

Now Load the file. Earlier we told you to open it using ProLog program and choose File Consult pick the file you saved earlier. Now you can open it by just double click on it, in the Explorer.

43

Pay attention in the first line, if it show “xxxx.pl compiled in xxx sec, xxxx bytes” then your program is correct.

44

Now, to list all the mammals just type :

?- animals (mammal,X,_,_).

45

To list all all the carnivores that are mammals just type :

?- animals (mammal,X,carnivore,_).

46

To list all the mammals with stripes just type :

?- animals (mammal,X,_,stripes).

47

To list whether there is a reptile that has a mane just type :

?- animals (reptile,X,_,mane).

48

The underscore character ( _ ) denotes a special variable, called the anonymous variable. This is used when the user does not care about the value of the variable.

Practical Exercises no.2 :

50

We know from the Question, there are 6 persons with 3 Male (bill, george, alfred) and 3 Female (carol, margaret, jane). And we need to Extend the program with a rule that defines a predicate couple.

Since Couple means 1 Male and 1 Female, the predicate couple should be :

couple(M,F) :- person(M,male), person(F,female).

Now, let’s try to solve this, first enter the facts and the predicates couple into Notepad/Wordpad.

51

Then save the file and name it person.pl

52

Now Load the file from File Explorer.

53

Now, to list all the possible combination couple, just type :

?- couple (MALE,FEMALE).

55

If you want to list all all the possible couple for “ bill ” just type :

?- couple (bill,FEMALE).

56

If you want to list all all the possible couple for “ margaret ” just type :

?- couple (MALE,margaret).

57

If you want to check whether “ bill ” and “ margaret ” would make a couple just type :

?- couple (bill,margaret).

58

😉

IE

Rule – Based Expert System October 20, 2009

Posted by integereuler in Literature Review.
add a comment

First, we need to know What is an Expert System.

An expert system is software that attempts to provide an answer to a problem, or clarify uncertainties where normally one or more human experts would need to be consulted. Expert systems are most common in a specific problem domain, and is a traditional application and/or subfield of artificial intelligence. A wide variety of methods can be used to simulate the performance of the expert however common to most or all are 1) the creation of a so-called “knowledgebase” which uses some knowledge representation formalism to capture the Subject Matter Expert’s (SME) knowledge and 2) a process of gathering that knowledge from the SME and codifying it according to the formalism, which is called knowledge engineering. Expert systems may or may not have learning components but a third common element is that once the system is developed it is proven by being placed in the same real world problem solving situation as the human SME, typically as an aid to human workers or a supplement to some information system.

There are two main methods of reasoning when using inference rules: backward chaining and forward chaining.

Forward chaining starts with the data available and uses the inference rules to conclude more data until a desired goal is reached. An inference engine using forward chaining searches the inference rules until it finds one in which the if clause is known to be true. It then concludes the then clause and adds this information to its data. It would continue to do this until a goal is reached. Because the data available determines which inference rules are used, this method is also called data driven.

Backward chaining starts with a list of goals and works backwards to see if there is data which will allow it to conclude any of these goals. An inference engine using backward chaining would search the inference rules until it finds one which has a then clause that matches a desired goal. If the if clause of that inference rule is not known to be true, then it is added to the list of goals. For example, suppose a rule base contains :

  1. If Fritz is green then Fritz is a frog.

  2. If Fritz is a frog then Fritz hops.

Suppose a goal is to conclude that Fritz hops. The rule base would be searched and rule (2) would be selected because its conclusion (the then clause) matches the goal. It is not known that Fritz is a frog, so this “if” statement is added to the goal list. The rule base is again searched and this time rule (1) is selected because its then clause matches the new goal just added to the list. This time, the if clause (Fritz is green) is known to be true and the goal that Fritz hops is concluded. Because the list of goals determines which rules are selected and used, this method is called goal driven.

This Backward Chaining method is called Rule-Based Expert System.

So, what is Rule – Based Expert System ?

It is an expert system based on a set of rules that a human expert would follow in diagnosing a problem. Rule – Based Expert System contrast with model-based expert system (An expert system based on fundamental knowledge of the design and function of an object. Such systems are used to diagnose equipment problems, for example).

As a premiere application of computing and artificial intelligence, the topic of expert systems has many points of contact with general systems theory, operations research, business process reengineering and various topics in applied mathematics and management science.

( http://en.wikipedia.org/wiki/Expert_system )


IE

How to list all possible combination using PROLOG! October 14, 2009

Posted by integereuler in TUTORIAL.
add a comment

Although there are other Logic Programming languages, by far the most widely used is Prolog. The name stands for Programming in Logic.

In this blog, we’ll give you some tutorial to use ProLog. For now, we’ll give you some tutorial about How to list all possible combination using PROLOG.

First, we’ll have to declare statement. For example we’ll ilustrated if an instuctor teaches student if they are in the same class :

(To input some facts, use Notepad/Wordpad )

  1. dosen(mukhlason,matdis).

  2. dosen(feby,alpro).

  3. dosen(holil,sfb).

  4. kuliah(adityo,matdis).

  5. kuliah(hendra,matdis).

  6. kuliah(hendra,alpro).

  7. kuliah(hendra,sfb).

  8. kuliah(dino,alpro).

  9. kuliah(dino,matdis).

  10. kuliah(anggoro,alpro).

  11. kuliah(anggoro,sfb).

  12. mengajar(D,M) :- dosen(D,K), kuliah(M,K).

1

Line 1 – 11 are FACTS that show dosen mukhlason teaches matdis class and so on, while student adityo kuliah matdis class and so on. While Line 12 is called RULE saying that instructor D teaches student M if instructor D teaches class K and student M takes class K.

If done, save the file using the with an extension .pl (for example tes.pl)

2

Now, load the file. By opening the ProLog program and choose File Consult pick the file you saved earlier.

3

4

Having loaded the program, the user is then faced with the two character symbol ?- which is called the system prompt. Now to list all the possible combination either instructor D teach student M type the dialog :

?- mengajar(D,M).

And to see all possible combination keep type semicolon ( ; ) until dialouge No is shown.

5

IE