Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

AI Mids

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

Page 1 of 22

Mid‐Term Exam (Take‐Home) Fall ‐ 2020

Subject: Artificial Intelligence Submission Day: Sunday

Instructor: Engr. DARAKHSHAN SYED, Engr. SYED SAFDAR HUSSAIN, DR. AARIJ MAHMOOD HUSSAAN ‐,
Submission Date: 29th November 2020

Program: Computer Science Max. Marks: 25

Department of _____Computer Science_______________

Please follow the instructions carefully:

1. Write your answers in a Word file and upload the file before the due date on BlackBoard.
2. Write your name and registration ID on the first page of your Word file.
3. Answer scripts can be uploaded on BlackBoard any time before its deadline.
Therefore, do not wait for the last hour to avoid any unforeseen problems.
4. Submission of answer copy(ies) will be considered acceptable through BlackBoard
only. Therefore, do not submit your document through email or any other medium.
5. Use 12 pt. font size and Times New Roman font style along with 1-inch page margins.
6. Follow the requirements of the word limit and the marking criteria while writing your
answers
7. Provide relevant, original and conceptual answers, as this exam aims to test your ability to
examine, explain, modify or develop concepts discussed in class.
8. Do not copy answers from the internet or other sources. The plagiarism of your answers
may be checked through Turnitin.
9. Recheck your answers before the submission on BlackBoard to correct any content or
language related errors.

Page 1 of 22
Page 2 of 22

10. Double check your word file before uploading it on BlackBoard to ensure that you have
uploaded the correct file with your answers.

Question 1) Agents 03 marks


Describe a utility-based agent for an autonomous delivery robot. You must describe the
following for this agent:

• How the utility will be measures?


• How will it differ from Goal Based Agent?
• What information would it require of the environment to make good decisions.
• How can you convert this agent to a learning agent? Describe the working of the different
components

Solution:
An agent is a system that is situated in an environment.it is capable of perceiving its environment,and it is
capable of acting in its environment with the goal of satisfying its design objectives.anything that can be
viewed as perceiving its environment through sensors and sensors acting upon the environment through
actuators.

utility based agents is a model based,goals alone are not really enough to generate high quality behaviour
is most environments.goals just provide a crude binary distinction between happy and unhappy
states,where as a more general performance measure should allow a comparision of different world states
according to exactly how happy they would make the agent if they could be achieved.

a utility function maps a state onto a real number,which describes the associated degree of happiness.a
complete specification of the utility function allows rational decisions in cases where goals are inadequate.

->the utility function measures its preferences among states of the world.then it chooses the action that
leads to the best expected utility,where expected utility is computed by averaging overall possible outcome
states,weighted by the probability of the outcome.

->goal based agents decide s its actions based on goal whereas utility based agents decide its actions
based on utilities.goal based agents are more flexible whereas utility based agents are less flexible.

->it is important to know that an intelligent agent is one that can make decisions based on the
environment.it makes decisions based on the maximum utility of its choices and it collects information and
there are several types.it is an agent that acts based not only on what the goal is,but the best way to reach
that goal.

->learning agent in artificial intelligence is the type of agent which can learn from its past experiences or its
has learning capabilities.it has different components,those are:learning element,critic,performance
element,problem generator.these are the working of the different components of the agents.

Page 2 of 22
Page 3 of 22

Question 2) Search 12 marks


Consider the game Move the Block (gameplay
https://www.youtube.com/watch?v=6d0NcUougD4). Move the Block : Slide Puzzle is a simple
game whose goal is sliding block puzzle game. The game instructions are extremely simple
(https://www.apkonline.net/games/puzzle/move-the-block-slide-puzzle-online-android):

• You have to move the red block in order to the exit.  You can move horizontal blocks
from side to side  You can move vertical blocks up and down.

The game has also the following characteristics:

• Your representation of the game should take into account that the grid size i.e. the number
of rows and columns would be as follows:
o number of rows >= 7 o
number of columns >= 8
• There could be an arbitrary number of blocks in the puzzle, however, the puzzle will
always have a solution
• The puzzle could also have many solutions
• You will be given the best possible solution
• Every slide will cost +1

For the game described above do the following

a) Describe the agent using the PEAS framework. Also describe the characteristics of the
task environment.

b) Model this game as a search problem. You have to describe the following:
i. Data
structure to be used
to represent the
state
ii. State
space iii.
Initial State iv.
Successor
Function
v. Actions
vi. Goal Test

Page 3 of 22
Page 4 of 22

c)Use the following puzzle to show the working of the BFS and IDS for upto depth = 3.
Show the contents of the frontier list, and the selected node at every step.

c) Develop two admissible heuristics for this problem. Also show that they are admissible.
d) Use the heuristics developed in part (e) to run A* search and Greedy Search to a depth =
5. Show the contents of the frontier list, and the selected node at every step.
e) Describe in your words why UCS is optimal

Solution:

This agent is an intellegent environment that has following characterstics :--

a) Performance measure

b) Environment

c) Actuators

d) Sensors

Lets understand these characterstics using a simple example:--

Lets consider taxi driver as our agent. Now:-

>>  Performance measure can be profit made by him , safe ride for his customers, comfortable and fast
ride.

Page 4 of 22
Page 5 of 22

>>  Environment is defined as the roads, climate, traffic

>>  Actuators are seat belts, horn, wheels, gear

>> Sensors are speadometer, air bag senson, camera, break sensors.

Class Main {
public void bfs()
{
// BFS uses Queue data structure
Queue queue = new LinkedList();
queue.add(this.rootNode);
printNode(this.rootNode);
rootNode.visited = true;
while(!queue.isEmpty()) {
Node node = (Node)queue.remove();
Node child=null;
while((child=getUnvisitedChildNode(node))!=null) {
child.visited=true;
printNode(child);
queue.add(child);
}
}
// Clear visited property of nodes
clearNodes();
}
public void dfs() {
// DFS uses Stack data structure
Stack stack = new Stack();
stack.push(this.rootNode);
rootNode.visited=true;
printNode(rootNode);
while(!stack.isEmpty()) {
Node node = (Node)s.peek();
Node child = getUnvisitedChildNode(n);
if(child != null) {
child.visited = true;
printNode(child);
s.push(child);
}
else {

Page 5 of 22
Page 6 of 22

s.pop();
}
}
// Clear visited property of nodes
clearNodes();
}
}
Class Node {
Char data;
Public Node(char c) {
this.data=c;
}
}

#include<iostream>

using namespace std;

//node declaration

struct node

int info;

struct node *next;

}*start;

/*

* Class Declaration

*/

class single_llist

Page 6 of 22
Page 7 of 22

public:

node* create_node(int);

void insert();

void delete_pos();

void search();

void display();

single_llist()

start = NULL;

};

/*

* Main :contains menu

*/

int main()

int choice, nodes, element, position, i;

single_llist sl;

start = NULL;

while (1)

Page 7 of 22
Page 8 of 22

cout<<endl<<"---------------------------------"<<endl;

cout<<endl<<"Operations on singly linked list"<<endl;

cout<<endl<<"---------------------------------"<<endl;

cout<<"1.Add a node."<<endl;

cout<<"2.Delete a node."<<endl;

cout<<"3.Search a node."<<endl;

cout<<"4.Display a node."<<endl;

cout<<"5.Exit "<<endl;

cout<<"Enter your choice : ";

cin>>choice;

switch(choice)

case 1:

cout<<"Inserting Node: "<<endl;

sl.insert();

cout<<endl;

break;

case 2:

cout<<"Delete a node: "<<endl;

sl.delete_pos();

break;

case 3:

Page 8 of 22
Page 9 of 22

cout<<"Search a node: "<<endl;

sl.search();

cout<<endl;

break;

case 4:

cout<<"Display a node: "<<endl;

sl.display();

cout<<endl;

break;

case 5:

cout<<"Exiting..."<<endl;

exit(1);

break;

default:

cout<<"Wrong choice"<<endl;

//create a node

node *single_llist::create_node(int value)

struct node *temp, *s;

Page 9 of 22
Page 10 of 22

temp = new(struct node);

if (temp == NULL)

cout<<"Memory not allocated "<<endl;

return 0;

else

temp->info = value;

temp->next = NULL;

return temp;

//add a node

void single_llist::insert()

int value;

cout<<"Enter the value to be inserted: ";

cin>>value;

struct node *temp, *p;

temp = create_node(value);

if (start == NULL)

Page 10 of 22
Page 11 of 22

start = temp;

start->next = NULL;

else

p = start;

start = temp;

start->next = p;

cout<<"Element Inserted in linked list."<<endl;

//delete a node

void single_llist::delete_pos()

int pos, i, counter = 0;

if (start == NULL)

cout<<"List is empty"<<endl;

return;

cout<<"Enter the position of value to be deleted: ";

Page 11 of 22
Page 12 of 22

cin>>pos;

struct node *s, *ptr;

s = start;

if (pos == 1)

start = s->next;

else

while (s != NULL)

s = s->next;

counter++;

if (pos > 0 && pos <= counter)

s = start;

for (i = 1;i < pos;i++)

ptr = s;

s = s->next;

Page 12 of 22
Page 13 of 22

ptr->next = s->next;

else

cout<<"Position out of range"<<endl;

free(s);

cout<<"Element Deleted"<<endl;

//display a node

void single_llist::display()

struct node *temp;

if (start == NULL)

cout<<"The List is Empty"<<endl;

return;

temp = start;

cout<<"Elements of list are: "<<endl;

while (temp != NULL)

Page 13 of 22
Page 14 of 22

cout<<temp->info<<"->";

temp = temp->next;

cout<<"NULL"<<endl;

//search a node

void single_llist::search()

int value, pos = 0;

bool flag = false;

if (start == NULL)

cout<<"List is empty"<<endl;

return;

cout<<"Enter the value to be searched: ";

cin>>value;

struct node *s;

s = start;

while (s != NULL)

Page 14 of 22
Page 15 of 22

pos++;

if (s->info == value)

flag = true;

cout<<"Element "<<value<<" is found at position "<<pos<<endl;


}
s = s->next;
}
if (!flag)
cout<<"Element "<<value<<" not found in the list"<<endl;

Question 3) Constraint Satisfaction Problem 10 marks


Consider this variant of Sudoku

Calcudoku puzzles are similar to Sudoku, but also require some basic math skills to solve.
(https://www.calcudoku.org/en/2020-11-20/6/1)

The rules are:

I. the 4×4 puzzle uses the numbers 1-4, the 6×6 the numbers 1-6, and so on
II. in each row and in each column each digit can appear only once (just like in Sudoku)
III. each "cage" (the blocks with the thick border) shows a result and an operation (addition:
+, subtraction: -, multiplication: ×, or division: :). The operation applied to the numbers
in the cage should produce the result shown. Note that for subtraction and division the
order is not fixed (!)

More about this type of Sudoku can be found over the internet

Page 15 of 22
Page 16 of 22

https://en.wikipedia.org/wiki/KenKen. Do not worry you are not going to be asked to solve the
puzzle here. However, you are required to answer the following questions:

I. Model this problem as a CSP problem


II. What could be the time complexity of this problem if we solve this problem using DFS?
III. Apply vanilla backtracking on this problem for at-least 10 iterations. Show the domains
of the selected variables after every iteration
IV. Apply backtracking with Forward Checking for 5 iterations, show the variables whose
domains will be reduced if you follow the Most Constraining Variable heuristic. Show
the domains of the variables after every iteration
V. Apply arc-consistency and show the resulting domain of variables.

Executioner Sudoku is a riddle that joins components of sudoku and kakuro. In spite of the name, the
more straightforward executioner sudokus can be simpler to understand than ordinary sudokus,
contingent upon the solver's ability at mental number-crunching; the hardest ones, nonetheless, can take
hours to break.

An ordinary issue is appeared on the right, utilizing hues to characterize the gatherings of cells. All the
more frequently, puzzles are imprinted clearly, with slender spotted lines used to layout the "confines".

The goal is to fill the framework with numbers from 1 to 9 out of a way that

the accompanying conditions are met:

* Each line, segment, and nonet contains each number precisely once.

* The aggregate of all numbers in an enclosure must match the modest number printed

in its corner.

* No number shows up more than once in a pen. (This is the standard guideline

for executioner sudokus, and suggests that no confine can incorporate more

than 9 cells.)

Complexity- In the event that we are to illuminate Sudoku utilizing a bruteforce strategy, our calculation
would need to attempt each accessible number over every vacant cell. Such a calculation would have a
runtime unpredictability of O(N^(N²)), where n is the size of the Sudoku puzzle. For a 9x9 Sudoku puzzle
(N = 9), the calculation would perform 2*10⁷⁷ tasks to discover an answer. That would not be
commonsense. Practically speaking, the runtime would differ as per the trouble of the riddle itself and
the quantity of choices for each unfilled cell. For instance, a 17-piece of information puzzle with slanting

Page 16 of 22
Page 17 of 22

evenness is one of the hardest to tackle because of an enormous number of up-and-comers and
branches.

In 'Executioner X', an extra standard is that every one of the long diagonals

contains each number once.

The yield is:

215647398

368952174

794381652

586274931

142593867

973816425

821739546

659428713

437165289

Page 17 of 22
Page 18 of 22

Page 18 of 22
Page 19 of 22

Page 19 of 22
Page 20 of 22

Page 20 of 22
Page 21 of 22

Page 21 of 22

You might also like