MTE 513: INTRODUCTION TO ARTIFICIAL INTELLIGENCE (AI)
Course contents
Introduction to search methods in AI problems. Self-organizing systems, information theory,
rational decision making, pattern recognition, parametric and non-parametric training for
developing pattern classifiers; problem-solving. The Minimax and alpha-beta algorithms and
heuristic approaches to state space search problems.
Introduction
One can hardly avoid encountering mentions of AI today, it’s almost everywhere. You see AI in
the movies, in books, in the news, and online. AI is part of robots, self-driving cars, drones,
medical systems, online shopping sites, and all sorts of other technologies that affect your daily
life in so many ways.
Artificial Intelligence (AI) has had several false starts and stops over the years, partly because
people don’t understand what AI is all about, or even what it should accomplish. A major part of
the problem is that movies, television shows, and books have all conspired to give false hopes as
to what AI will accomplish. In addition, the human tendency to anthropomorphize
(give human characteristics to) technology makes it seem as if AI must do more than it can hope
to accomplish. So, the best way to start is to define what AI is. People define intelligence in
many different ways. However, you can say that intelligence involves certain mental activities
composed of the following activities:
➢ Learning: Having the ability to obtain and process new information.
➢ Reasoning: Being able to manipulate information in various ways.
➢ Understanding: Considering the result of information manipulation.
➢ Grasping truths: Determining the validity of the manipulated information.
➢ Seeing relationships: Divining how validated data interacts with other data.
➢ Considering meanings: Applying truths to particular situations in a manner consistent
with their relationship.
➢ Separating fact from belief: Determining whether the data is adequately supported by
provable sources that can be demonstrated to be consistently valid.
The list could easily get quite long, but even this list is relatively prone to interpretation by
anyone who accepts it as viable. As you can see from the list, however, intelligence often follows
a process that a computer system can mimic as part of a simulation:
1. Set a goal based on needs or wants.
2. Assess the value of any currently known information in support of the goal.
3. Gather additional information that could support the goal.
4. Manipulate the data such that it achieves a form consistent with existing information.
5. Define the relationships and truth values between existing and new information.
6. Determine whether the goal is achieved.
7. Modify the goal in light of the new data and its effect on the probability of success.
8. Repeat Steps 2 through 7 as needed until the goal is achieved (found true) or the
possibilities for achieving it are exhausted (found false)
Definition - Artificial intelligence (AI) is a subfield of computer science aimed at the
development of computers capable of doing things that are normally done by people — in
particular, things associated with people acting intelligently. In other words, Artificial
Intelligence (AI) is the simulation of human intelligence by machines so that the machine can
have the ability to solve problems, ability to act rationally and ability to act like humans. Luger
and Stubblefield. 1993, also defines AI as the branch of computer science that is concerned with
the automation of intelligent behavior.
In general, when thinking about AI, notice an interplay between goal seeking, data processing
used to achieve that goal, and data acquisition used to better understand the goal. AI relies on
algorithms to achieve a result that may or may not have anything to do with human goals or
methods of achieving those goals. With this in mind, one can view AI in four ways.
➢ Acting humanly: When a computer acts like a human, it best reflects the Turing test, in
which the computer succeeds when differentiation between the computer and a human
isn’t possible. This type also reflects what the media would have you believe AI is all
about. You see it employed for technologies such as natural language processing,
knowledge representation, automated reasoning, and machine learning (all four of which
must be present to pass the test). The original Turing Test didn’t include any physical
contact. The newer, Total Turing Test does include physical contact in the form of
perceptual ability
interrogation, which means that the computer must also employ both computer vision and
robotics to succeed. Modern techniques include the idea of achieving the goal rather than
mimicking humans completely. For example, the Wright Brothers didn’t succeed in
creating an airplane by precisely copying the flight of birds; rather, the birds provided
ideas that led to aerodynamics that eventually led to human flight. The goal is to fly. Both
birds and humans achieve this goal, but they use different approaches.
➢ Thinking humanly: When a computer thinks like a human, it performs tasks that require
intelligence (as contrasted with rote procedures) from a human to succeed, such as
driving a car. To determine whether a program thinks like a human, you must have some
method of determining how humans think, which the cognitive modelling approach
defines. This model relies on three techniques:
• Introspection: Detecting and documenting the techniques used to achieve goals
by monitoring one’s thought processes.
• Psychological testing: Observing a person’s behavior and adding it to a database
of similar behaviors from other persons given a similar set of circumstances,
goals, resources, and environmental conditions (among other things).
• Brain imaging: Monitoring brain activity directly through various mechanical
means, such as Computerized Axial Tomography (CAT), Positron Emission
Tomography (PET), Magnetic Resonance Imaging (MRI), and
Magnetoencephalography (MEG).
After creating a model, you can write a program that simulates the model. Given the
amount of variability among human thought processes and the difficulty of accurately
representing these thought processes as part of a program, the results are experimental at
best. This category of human thinking humanly is often used in psychology and other
fields in which modelling the human thought process to create realistic simulations is
essential.
➢ Thinking rationally: Studying how humans think using some standard enables the
creation of guidelines that describe typical human behaviors. A person is considered
rational when following these behaviors within certain levels of deviation. A computer
that thinks rationally relies on the recorded behaviors to create a guide as to how to
interact with an environment based on the data at hand. The goal of this approach is to
solve problems logically, when possible. In many cases, this approach would enable the
creation of a baseline technique for solving a problem, which would then be modified to
solve the problem. In other words, the solving of a problem in principle is often different
from solving it in practice, but you still need a starting point.
➢ Acting rationally: Studying how humans act in given situations under specific
constraints enables you to determine which techniques are both efficient and effective. A
computer that acts rationally relies on the recorded actions to interact with an
environment based on conditions, environmental factors, and existing data. As with
rational thought, rational acts depend on a solution in principle, which may not prove
useful in practice. However, rational acts do provide a baseline upon which a computer
can begin negotiating the successful completion of a goal.
Classification of AI
The categories used to define AI offer a way to consider various uses for or ways to apply AI.
Some of the systems used to classify AI by type are arbitrary and not distinct. For example, some
groups view AI as either strong (generalized intelligence that can adapt to a variety of situations)
or weak (specific intelligence designed to perform a particular task well). The problem with
strong AI is that it doesn’t perform any task well, while weak AI is too specific to perform tasks
independently. Even so, just two types of classifications won’t do the job even in a general sense.
The four classification types that form a better basis for understanding AI are:
i. Reactive machines: The machines you see beating humans at chess or playing on game
shows are examples of reactive machines. A reactive machine has no memory or experience
upon which to base a decision. Instead, it relies on pure computational power and smart
algorithms to recreate every decision every time. This is an example of a weak AI used for a
specific purpose.
ii. Limited memory: A self-driving car or autonomous robot can’t afford the time to make
every decision from scratch. These machines rely on a small amount of memory to provide
experiential knowledge of various situations. When the machine sees the same situation, it
can rely on experience to reduce reaction time and provide more resources for making new
decisions that haven’t yet been made. This is an example of the current level of strong AI.
iii. Theory of mind: A machine that can assess both its required goals and the potential goals
of other entities in the same environment has a kind of understanding that is feasible to some
extent today, but not in any commercial form. However, for self-driving cars to become
truly autonomous, this level of AI must be fully developed. A self-driving car would not
only need to know that it must go from one point to another, but also intuit the potentially
conflicting goals of drivers around it and react accordingly.
iv. Self-awareness: This is the sort of AI that you see in movies. However, it requires
technologies that aren’t even remotely possible now because such a machine would have a
sense of both self and consciousness. In addition, instead of merely intuiting the goals of
others based on environment and other entity reactions, this type of machine would be able
to infer the intent of others based on experiential knowledge.
Uses of AI
You find AI used in a great many applications today. The only problem is that the technology
works so well that you don’t know that it even exists. You might be surprised to find that many
devices in your home already make use of AI. For example, some smart thermostats
automatically create schedules for you based on how you manually control the temperature.
Likewise, voice input that is used to control some devices learns how you speak so that it can
better interact with you. AI appears in your car and most especially in the workplace. The uses
for AI number in the millions — all safely out of sight even when they’re quite dramatic in
nature. Here are just a few of how you might see AI used:
i. Fraud detection: You get a call from your credit card company asking whether you made
a particular purchase. The credit card company isn’t being nosy; it’s simply alerting you to
the fact that someone else could be making a purchase using your card. The AI embedded
within the credit card company’s code detected an unfamiliar spending pattern and alerted
someone to it.
ii. Resource scheduling: Many organizations need to schedule the use of resources
efficiently. For example, a hospital may have to determine where to put a patient based on
the patient’s needs, the availability of skilled experts, and the amount of time the doctor
expects the patient to be in the hospital.
iii. Complex analysis: Humans often need help with complex analysis because there are too
many factors to consider. For example, the same set of symptoms could indicate more than
one problem. A doctor or other expert might need help making a diagnosis promptly to
save a patient’s life.
iv. Automation: Any form of automation can benefit from the addition of AI to handle
unexpected changes or events. A problem with some types of automation today is that an
unexpected event, such as an object in the wrong place, can cause the automation to stop.
Adding AI to the automation can allow the automation to handle unexpected events and
continue as if nothing happened.
v. Customer service: The customer service line you call today may not even have a human
behind it. The automation is good enough to follow scripts and use various resources to
handle the vast majority of your questions. With good voice inflexion (provided by AI as
well), you may not even be able to tell that you’re talking with a computer.
vi. Safety systems: Many of the safety systems found in machines of various sorts today rely
on AI to take over the vehicle in a time of crisis. For example, many automatic braking
systems rely on AI to stop the car based on all the inputs that a vehicle can provide, such as
the direction of a skid.
vii. Machine efficiency: AI can help control a machine in such a manner as to obtain
maximum efficiency. The AI controls the use of resources so that the system doesn’t
overshoot speed or other goals. Every ounce of power is used precisely as needed to
provide the desired services.
INTRODUCTION TO PROBLEMS SOLVING BY SEARCH IN AI
One of the fundamental aspects of AI is problem-solving, and search algorithms play a key role
in this process. Problem-solving by search enables machines to navigate complex problem
spaces and find optimal or near-optimal solutions. It involves finding a sequence of actions or
steps to reach a desired state from an initial state in an environment. As AI continues to advance,
the refinement and application of search algorithms will play a pivotal role in addressing
complex real-world challenges.
Some of the well-known problems experienced in everyday life are games and puzzles. Using AI
techniques, we can solve these problems efficiently. In this sense, some of the most common
problems resolved by AI are:
➢ Travelling Salesman Problem
➢ Tower of Hanoi Problem
➢ Water-Jug Problem
➢ N-Queen Problem
➢ Chess
➢ Sudoku
➢ Crypt-arithmetic Problems
➢ Magic Squares
➢ Logical Puzzles and so on.
1. Traveling Salesman Problem (TSP)
The Travelling Salesman Problem (TSP) is a classic optimization problem in computer science
and operations research. The goal is to find the most efficient route that visits a given set of cities
exactly once and returns to the starting city, minimizing the total distance or cost travelled.
Consider the following situation. You are given a list of n cities with the distance between any
two cities. Now, you have to start with your office and visit all the cities only once each and
return to your office. What is the shortest path can you take? This problem is called the Traveling
Salesman Problem (TSP).
For example, consider the graph shown in the Figure below. A TSP tour in the graph is 1-2-4-
3-1. The cost of the tour is 10+25+30+15 which is 80.
i. Consider city 1 as the starting and ending point. Since the route is cyclic, we can
consider any point as a starting point.
ii. Generate all (n-1)! permutations of cities.
iii. Calculate the cost of every permutation and keep track of the minimum cost
permutation.
iv. Return the permutation with minimum cost.
The minimum weight Hamiltonian cycle found is
10 + 25 + 30 + 15 = 80
2. The Tower of Hanoi Problem
The Tower of Hanoi is a mathematical puzzle that consists of three towers (pegs) and multiple
disks. Initially, all the disks are placed on one rod. The disks are arranged on one over the other
in ascending order of size.
The objective is to move all disks from the initial tower to another tower without violating the
rule.
The Rule for Disk Movement in TOH
The rules according to which the disks have to be moved in Tower of Hanoi are as follows:
❖ Initially, the disks are placed in increasing order in size on Tower 1 (source) from top to
bottom.
❖ The objective is to move them to tower 2 (destination), making also use of an auxiliary
tower 3.
❖ The conditions for moving the disks are:
o All disks (except the one to be moved) must be on one of the three towers.
o Only one disk is possible to move at a time.
o Only the top disk can be moved i.e. taking from the top of one tower and placing
on the top of another tower.
❖ A larger disk can never be placed on a smaller disk.
NB: The Tower of Hanoi mathematical puzzle that has n disks with 3 towers can be solved
in a minimum of 2n -1 steps.
For an example
A puzzle with 3 disks has taken
23 – 1 = 7 steps.
Algorithm For Tower of Hanoi Puzzle
In the Tower of Hanoi puzzle we have three towers and some disks. We have to move this disk
from the initial tower to the destination tower using the auxiliary tower.
Suppose we have two disks and we want to move them from the source to the destination tower.
The approach we will follow
• First, we will move the top disk to the auxiliary tower.
• Then we will move the next disk (which is the bottom one in this case) to the
destination tower.
• And at last, we will move the disk from the auxiliary tower to the destination
tower.
Similarly, if we have n number of disks, then we aim to move the bottom which is disk n from
source to destination. And then put all other (n-1) disks onto it.
The steps we will follow are:
• Step 1 − Move n-1 disks from source to auxiliary
• Step 2 − Move the nth disk from source to destination
• Step 3 − Move n-1 disks from auxiliary to destination
Pictorial Representation of How the Tower of Hanoi Works
Let’s see the below example where we have three disks that have to move in the destination
tower which is the middle one with the help of the auxiliary tower.
Move disk 1 from tower source to tower destination
Move disk 2 from tower source to tower auxiliary
Move disk 1 from tower destination to tower auxiliary
Move disk 3 from tower source to tower destination
Move disk 1 from tower auxiliary to tower source
Move disk 2 from tower auxiliary to tower destination
Move disk 1 from tower source to tower destination
3. Water Jug problem
The water jug problem is a classic problem in AI and computer science. The problem involves
two water jugs of different capacities and the task is to measure out a specific amount of water
using these jugs. The problem is often formulated as follows:
You are given an X-litre jug and a Y-litre jug. Both the jugs are initially empty, but there is a
pump that can be used to fill the jugs with water. The jugs don’t have markings to allow
measuring smaller quantities. You have to use the jugs to measure Z litres of water where Z is
a positive integer.
As provided in the problem statement, at any given state we can do either of the following
operations:
1. Fill a jug
2. Empty a jug
3. Transfer water from one jug to another until either of them gets completely filled
or empty.
Examples:
Let's assume we have a 4-litre and a 3-liter jug, and we want to get exactly 2 litres of water.
Input: X = 4, Y = 3,
Target (output) =Z = 2
Output: {(0, 0), (4, 0), (1, 3), (1, 0), (0, 1), (4, 1), (2, 3)}
Explanation:
Fill the 4-litre jug:
Initial state: (4, 0)
Action: Fill the 4-litre jug
Resulting state: (4, 0)
i. Pour water from the 4-litre jug to the 3-litre jug:
Initial state: (4, 0)
Action: Pour water from the 4-litre jug to the 3-litre jug (leaving 1L water in a 4L
jug)
Resulting state: (1, 3)
ii. Empty the 3-litre jug:
Initial state: (1, 3)
Action: Empty the 3-litre jug
Resulting state: (1, 0)
iii. Pour water from the 4-litre jug to the 3-litre jug:
Initial state: (1, 0)
Action: Pour water from the 4-litre jug to the 3-litre jug
Resulting state: (0, 1)
iv. Fill the 4-litre jug:
Initial state: (0, 1)
Action: Fill the 4-litre jug
Resulting state: (4, 1)
v. Pour water from the 4-litre jug to the 3-litre jug until it is full:
Initial state: (4, 1)
Action: Pour water from the 4-litre jug to the 3-litre jug
Resulting state: (2, 3)
Now, you have exactly 2 litres of water in the 4-litre jug, and you have successfully solved the
Water Jug problem to measure out 2 liters using a 4-litre jug and a 3-litre jug.
4. N-Queen Problem
The N-Queens problem is a classic problem in artificial intelligence, computer science, and
combinatorial optimization. The goal is to place N chess queens on an N×N chessboard in such a
way that no two queens threaten each other. Queens can attack each other if they are in the same
row, column, or diagonal.
The problem is challenging due to the constraint that no two queens should share the same row,
column, or diagonal. The solution requires finding a placement of queens that satisfies all these
constraints.
Here's a more detailed explanation of the N-Queens problem:
Problem Formulation:
Given an (N XN) chessboard, the task is to place N queens on the board in such a way that no
two queens attack each other.
Constraints:
i. Row Constraint: Each row must contain exactly one queen.
ii. Column Constraint: Each column must contain exactly one queen.
iii. Diagonal Constraint: No two queens should be placed in the same diagonal.
Objective:
Find a configuration of queen placements that satisfies all constraints.
Solution Approaches:
1. Backtracking Algorithm
• The most common approach to solving the N-Queens problem is using backtracking.
• Start with an empty board and try placing queens one by one.
• If a queen placement violates any constraint, backtrack and try a different placement.
• Continue until all queens are placed or a valid solution is found.
2. Genetic Algorithms
• Genetic algorithms can be used to evolve a population of queen configurations.
• Solutions are represented as chromosomes, and genetic operations (crossover,
mutation) are applied to generate new configurations.
• Fitness is determined by the number of conflicts, and the process continues until a
solution is found.
3. Constraint Satisfaction Problem (CSP)
• The N-Queens problem can be formulated as a CSP, where each variable represents
the placement of a queen.
• Constraints are applied to ensure no conflicts in rows, columns, and diagonals.
• Backtracking, constraint propagation, and heuristics can be employed to find a valid
assignment.
4. Simulated Annealing
• Simulated annealing is a probabilistic optimization algorithm.
• The state space represents different queen configurations, and the algorithm explores
the space by accepting "worse" solutions with decreasing probability.
• It can escape local optima and converge to a valid solution.
Example:
For N = 8, a solution might look like this:
In this example, each 'Q' represents a queen, and the configuration satisfies all constraints.
The N-Queens problem is not only a classic AI problem but also a fundamental problem in
combinatorial optimization, and it has applications in various areas such as cryptography,
scheduling, and network design.
Task 1
A: Find the algorithms for the following AI problems
i. Chess
ii. Sudoku
iii. Crypt-arithmetic Problems
iv. Magic Squares
v. Logical Puzzles
B: Run the Python script for each of the problems discussed above.