Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Artificial Intelligence: The Water Jugs Problem - Prof. sag, Assignments of Computer Science

A classic logic puzzle known as the water jugs problem. The problem involves three jugs with capacities of 16 liters, 7 liters, and 5 liters, and the goal is to find a sequence of actions (filling, emptying, and transferring water between jugs) that results in exactly a target amount of water (g liters) in one of the jugs. Detailed instructions for three questions related to this problem, including finding solutions for target values of 1 and 2 liters, discussing the possibility of achieving other target values, and implementing the problem as a search problem using various uninformed search algorithms. Intended for students enrolled in the cmpt 317 course on introduction to artificial intelligence at the university of saskatchewan in the winter 2024 semester.

Typology: Assignments

2023/2024

Uploaded on 04/19/2024

khushdeep-sandhu
khushdeep-sandhu 🇨🇦

1 document

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Department of Computer Science
176 Thorvaldson Building
110 Science Place, Saskatoon, SK, S7N 5C9, Canada
Telephone: (306) 966-4886, Facsimile: (306) 966-4884
CMPT 317
Winter 2024
Introduction to Artificial Intelligence
Assignment 1
Search Problems
Date Due: Friday January 26, 5:00pm Total Marks: 15
General Instructions
This assignment is individual work. You may discuss questions and problems with anyone, but
the work you hand in for this assignment must be your own work.
If you intend to use resources not supplied by the instructor, please request permission prior to
starting. You should not use any resource that substantially evades the learning objectives for
this assignment. You must provide an attribution for any external resource (library, API, etc) you
use. If there’s any doubt, ask! No harm can come from asking, even if the answer is no.
Each question indicates what the learning objective is, what to hand in, and how you’ll be evalu-
ated.
Do not submit folders, or zip files, even if you think it will help.
Assignments must be submitted to Canvas.
pf3
pf4
pf5

Partial preview of the text

Download Introduction to Artificial Intelligence: The Water Jugs Problem - Prof. sag and more Assignments Computer Science in PDF only on Docsity!

Department of Computer Science 176 Thorvaldson Building 110 Science Place, Saskatoon, SK, S7N 5C9, Canada Telephone: (306) 966-4886, Facsimile: (306) 966-

Winter 2024 Introduction to Artificial Intelligence

Assignment 1

Search Problems

Date Due: Friday January 26, 5:00pm Total Marks: 15

General Instructions

  • This assignment is individual work. You may discuss questions and problems with anyone, but the work you hand in for this assignment must be your own work.
  • If you intend to use resources not supplied by the instructor, please request permission prior to starting. You should not use any resource that substantially evades the learning objectives for this assignment. You must provide an attribution for any external resource (library, API, etc) you use. If there’s any doubt, ask! No harm can come from asking, even if the answer is no.
  • Each question indicates what the learning objective is, what to hand in, and how you’ll be evalu- ated.
  • Do not submit folders, or zip files, even if you think it will help.
  • Assignments must be submitted to Canvas.

Department of Computer Science 176 Thorvaldson Building 110 Science Place, Saskatoon, SK, S7N 5C9, Canada Telephone: (306) 966-4886, Facsimile: (306) 966-

Winter 2024 Introduction to Artificial Intelligence

The Water Jugs problem

Consider the following form of a classic logic puzzle. You have three jugs, with capacities 16 liters, 7 liters and 5 liters, along with a water faucet with infinite water. You have some target value G, meaning that you want to end up in a situation where you have EXACTLY G liters of water in one of the jugs (it does not matter to you which one). Your possible actions consist of:

  • Filling a particular jug from the faucet (regardless of whether it was empty or not)
  • Emptying a particular jug onto the ground
  • Transferring water from one jug to another, but you must always pour exactly as MUCH as you can without spilling (Example: if you pour from a (full) 16 liter jug to an (empty) 5 liter jug, you will end up with 11 liters left in the big jug and 5 liters in the small jug)

A solution to a Water Jugs problem consists of a sequence of actions taken from the above possibilities that results in exactly G liters in one of the jugs. Obviously, if G is either 16, 7, or 5, the solution is trivial: simply fill the matching jug from the faucet. For other values of G, it may not be so easy and may require a combination of fills, dumps, and transfers.

Department of Computer Science 176 Thorvaldson Building 110 Science Place, Saskatoon, SK, S7N 5C9, Canada Telephone: (306) 966-4886, Facsimile: (306) 966-

Winter 2024 Introduction to Artificial Intelligence

Question 2 (5 points):

Purpose: To apply uninformed search algorithms

AIMA Chapter(s): 3.1-3.

For this question, your task is to impelement the Water Jugs problem as a search problem. You have been provided with several Python files. These include a generalized, object-oriented imple- mentations of the basic search algorithms below:

  • Breadth-first (BFS)
  • Depth-first (DFS)
  • Iterative-deepening (IDS)

Each of the algorithms above can be run using either the Tree search or Graph search variants. The only file you need to CHANGE is WaterJugs.py. This file implements both the State and Problem classes that are used by the search algorithms. The provided version of WaterJugs.py contains only method headers. You need to implement these methods correctly to capture the specific dynamics of the Water Jugs problem, using your understanding of search problem encoding and of AIMA Chapter 3. When you are done, you can test your implementation by running see_solutions.py with the following arguments:   python see_solutions. py 1 ids graph 10   If everything is working correctly, this should find a solution to the Water Jug problem for the target value of 1 liter. However, BEFORE you do this, it is crucial that you ensure your state and problem implementation is cor- rect. Testing via search is a BAD idea, as the search may examine thousands or even millions of nodes. A simple example of a test file is provided to give you some testing ideas. You don’t need to hand in this testing, but there is virtually no chance that your implementation will be correct if you don’t do it. Hint: By far the most common problem in implementing a search problem is "not copying things that need to be copied" when you create a new state. For example, recall that in Python, you can easily create a (shallow) copy of a list like so:   new_list = [ x for x in old_list ]   Some students are tempted to use built-in Python methods like .deepcopy, but this can be extraordinarily inefficient if called blindly. Making manual copies with list comprehensions and copying only what you need usually works out much better.

What to Hand In

  • Your problem implementation in a file called WaterJugs.py. You do NOT need to re-hand-in any of the other provided files.

Be sure to include your name, NSID, student number, and course number at the top of all documents.

Evaluation

  • 5 marks: Your implementation of the State and Problem classes are correct

Department of Computer Science 176 Thorvaldson Building 110 Science Place, Saskatoon, SK, S7N 5C9, Canada Telephone: (306) 966-4886, Facsimile: (306) 966-

Winter 2024 Introduction to Artificial Intelligence

Question 3 (5 points):

Purpose: To understand the differences between search algorithms

AIMA Chapter(s): 3.1-3.

This question assumes that you have a working State and Problem class for the Water Jugs problem. For this question, you will run several different provided search algorithms and summarize the results in table. Run all of the search algorithms shown in the table below to try to find the solution to a Water Jugs prob- lem with a target value of ONE LITER , using a time limit of 10 seconds. You can do this by running see_solutions.py with different command line parameters. A quick look at the code in the file should make it obvious how to do this.

BFS-T BFS-G DFS-T DFS-G IDS-T IDS-G

actions in solution

Time used (secs) Memory used (nodes)

Your table should be neat and readable (use tabs in plain text, or a table in Word, etc). Round or truncate the time values to 3 decimal points worth of precision (i.e. number of milliseconds). After collecting the data, answer the following questions.

  • Overall, which algorithm performed the best for this problem?
  • Do you notice a difference between the tree-search and graph-search variants of these algorithms? Why do you think that is?

What to Hand In

  • Your data table as described above. You can use a plain text file, or you can submit a MSWord doc- ument, or PDF. Name your document a1q3_TABLES with an appropriate extension (e.g., txt, pdf, docx, etc).
  • Your answer about the search approaches. This can be in the same document as your table.

Be sure to include your name, NSID, student number, and course number at the top of all documents.

Evaluation

  • 3 marks: Your tables are neat and show plausible results
  • 2 marks: You analyzed the data and showed an understanding of the difference between tree and graph search