Artificial Intelligence COMP717

Assignment 1: Fuzzy Logic Control (50%)

You have a choice of topic for your fuzzy logic controller: a washing machine time controller (A), or driverless car speed controller (B). Attempt only one.

A: Washing machine time controller (Option A)

1. Your task is to implement a simple washing machine time controller based on the amount of dirt and type of dirt on clothes. There are two input variables and one output variable. First, open Matlab and enter ‘fuzzy’ in the Command Window.

2. The amount of dirt is specified by the following membership functions for ‘small’, ‘average/medium’ and ‘large’. Enter these membership functions using the graph in Figure 1 as a guideline. You don’t have to be entirely accurate with respect to the figure below. You will need to pay attention to the type of membership function and the range. You can interpret the range as a percentage:

Figure 1: Membership functions for amount of dirt

3. The type of dirt is specified by the following membership functions for ‘not greasy’, ‘medium greasy’ and ‘greasy’ (Figure 2). You can interpret the range as a percentage:

Figure 2: Membership functions for type of dirt

4. The wash time (output variable) has five membership functions (‘very short’, ‘short’, ‘medium’, ‘long’ and ‘very long’. You can interpret the range as minutes. You can specify your own output membership function ranges if you are not happy with these below (Figure 3), but make clear in your report what you have done.

Figure 3: Membership functions for wash time

5. The full set of rules for deriving output is:

1. If dirtiness_of_clothes is Large and type_of_dirt is Greasy then wash_time is VeryLong;

2. If dirtiness_of_clothes is Medium and type_of_dirt is Greasy then wash_time is Long;

3. If dirtiness_of_clothes is Small and type_of_dirt is Greasy then wash_time is Long;

4. If dirtiness_of_clothes is Large and type_of_dirt is Medium then wash_time is Long;

5. If dirtiness_of_clothes is Medium and type_of_dirt is Medium then wash_time is Medium;

6. If dirtiness_of_clothes is Small and type_of_dirt is Medium then wash_time is Medium;

7. If dirtiness_of_clothes is Large and type_of_dirt is NotGreasy then wash_time is Medium;

8. If dirtiness_of_clothes is Medium and type_of_dirt is NotGreasy then wash_time is Short;

9. If dirtiness_of_clothes is Small and type_of_dirt is NotGreasy then wash_time is VeryShort

6. Once you have implemented this fuzzy logic controller, answer the following questions:

Question set A:

(a) What is the rule surface for the system? Do you see any discontinuities? Are you happy with the surface?

(b) What is the wash time, in minutes, for the following loads?

(i) Dirtiness=70; Type=50.

(ii) Dirtiness=0; Type=50.

(iii) Dirtiness=100; Type=100.

(iv) You have clothes that are 100% greasy. What is the minimum length of wash irrespective of amount of dirt?

(v) You have clothes that are 100% dirty. What is the minimum length of wash irrespective of type of dirt?

7. You will now add Temperature of water as a third input variable to your controller. The general principle is: the colder the water, the longer the wash. So, the hotter the temperature, the less time the wash. You can assume that water temperature has a range from 20 degrees C to 60 degrees C. Add the following:

• A third input variable called ‘Temperature’;

• Three membership functions for ‘Temperature’: cold; warm; hot. You can specify these three membership functions any way you wish (as triangular, trapezoidal, Gaussian…).

• Add at least one ’And’ rule involving all three antecedents Dirtiness, Type and Temperature, with one rule consequent for Wash Time.

• Add at least one ‘Or’ rule involving all three antecedents Dirtiness, Type and Temperature, with one rule consequent for Wash Time

• Add at least one rule using the ‘not’ option in the Rule Editor. You can use as many antecedents as you wish (minimum one).

After you have implemented the third input variable Temperature as specified above, answer the following questions:

Question set B:

(c) How plausible or intuitively correct are your added rules?

(d) What is the shape of your new rule surface and how does it compare with your previous rule surface?

(e) What is the wash time for the following loads?

(v) Maximum amount of dirt, maximum greasiness, hottest water.

(vi) Maximum amount of dirt, maximum greasiness, coldest water.

8. Write a report using the IEEE format available in the assignment folder consisting of 6 pages maximum. The report is to be structured as follows (after your name and ID number at the top of the page):

• Part A: Membership function descriptions for each of your two input and one output variable; answers to Question Set A.

• Part B: membership function description for your third input variable (water temperature); answers to Question Set B;

• Part C: your conclusion and lessons learnt (if you could start the assignment again, would you do anything differently?)

An example report will be made available to you to help you construct your own report. The marksheet for this assignment is on the next page.

(Note: this assignment is based on material taken from http://softcomputing.tripod.com/sample_termpaper.pdf )

This concludes the first option for Assignment 1. Look at the next page for the second option for Assignment 1.

B: Driverless car speed controller (Option B)

1. This assignment is based on the material in lecture 3 and involves implementing the functions for determining car speed based on two input variables. Workshop 4 will help you prepare for this option if you need it. So, you will need to implement (or apply your own versions, with full descriptions):

2. There are two rules, as follows:

(i) If it’s freezing and overcast, drive slow.

(ii) If it’s hot and sunny, drive fast.

Now ensure that the following are answered in your assignment report.

Question (a): How fast should the car go if it is 40 degrees and 75% cloud cover? Your answers may vary from the workshop 4 answers.

3.The temperature goes up to 50 degrees but there is still 75% cloud cover. We also have a new rule:

(iii) If it is cool and overcast, drive moderately.

The membership function for Moderately is as follows:

MPH Moderately

10 0.0

20 0.0

30 0.2

40 0.6

50 1.0

60 0.6

70 0.2

80 0.0

90 0.0

100 0.0

Add this function to the Output Variable Speed.

Question (b): How fast should the car go if it is 40 degrees and 75% cloud cover, with and without the new, third rule implemented? How does the third rule affect the rule surface?

4. Now, your next assignment task is to introduce a third input variable representing the sensor ‘distance to the car in front’. The general principles are

(i) the closer to the car in front, the more the car slows down;

(ii) the further to the car in front, the more the car can go faster.

Your final task is to implement this third input sensor and add the two principles above to the rule set. You may find it useful to think of at least two membership functions: close to the car in front, and far to the car in front. You will need to decide whether you need more membership functions and what type they should be.

Then answer the following questions in your assignment report.

Question set (c)-(e):

(c) How did you implement the new, third sensor variable for distance to car in front in terms range and type of membership functions? Why those particular choices?

(d) What is the shape of your new rule surface with the third input sensor and how does it compare with your previous rule surface consisting of two sensors?

(e) What is the speed for the following conditions?

(i) Minimum temperature, minimum cover, minimum distance?

(ii) Maximum temperature, maximum cover, maximum distance?

(iii)Moderate temperature, moderate cover, moderate distance?

5. Write a report using the IEEE format available in the assignment folder consisting of 6 pages maximum. The report is to be structured as follows (after your name and ID number at the top of the page):

• Part A: Membership function descriptions for each of your two input and one output variable, including new rule; answers to Questions (a) and (b).

• Part B: membership function description and new rules for your new third input variable (distance to car in front); answers to Questions (c), (d) and (e);

• Part C: your conclusion and lessons learnt (if you could start the assignment again, would you do anything differently?)

This concludes the second option for Assignment 1.

Example reports will be made available to you to help you construct your own report. The marksheet for this assignment is on the next page.

Marksheet for Artificial Intelligence Coursework – Assignment 1 (Fuzzy Logic Controller)

1. Introduction and background to fuzzy logic controller architecture (20 marks)

2. Fuzzifier: Description, justification and explanation of input and output variables membership functions (20 marks)

3. Inference engine and defuzzification: Description, justification and explanation (20 marks)

4. Simulations and example outputs: Description, presentation and explanation (20 marks)

5. Evaluation and conclusion (20 marks)

Marker’s summary of Assignment 1 (total mark out of 100 for assignment 1 which will be converted to a mark out of 50 when calculating your overall paper mark):