Artificial Intelligence
Third Year Students
Department of Computer Science
T.A. Rehab Emad El-Dein Sayed
FCI-Minia University 1
Agenda
 Search Algorithms in AI
 Search Algorithm Terminologies
 Properties of Search Algorithms
 Types of Search Algorithms
 Search Algorithm over Graph
FCI-Minia University 2
Search Algorithms in AI
3
 Problem-Solving Agents:
 ArtificialIntelligence is the study of buildingagents that act rationally.
 Rational agents or Problem-solving agents in AI mostly used these search
strategies or algorithms to solve a specific problem and provide the best result.
Problem-solving agents are the goal-based agents and use atomic representation.
 Search Algorithms are one of the most important areas of Artificial
Intelligence.
 Search Algorithms are universal problem-solving methods.
Agenda
 Search Algorithms in AI
Search Algorithm Terminologies
 Properties of Search Algorithms
 Types of search algorithms
 Search over Graph
FCI-Minia University 4
5
Search Algorithm Terminologies
 Search: Searching is a step by step procedure to solve a search-problem in a given search space.
 A Search Problem can have three main factors:
 Search Space: Search space represents a set of possible solutions, which a system may have.
 Start State: It is a state from where agent begins the search.
 Goal test: It is a function which observe the current state and returns whether the goal state is
achieved or not.
 Search tree: A tree representation of search problem is called Search tree.
 The root of the search tree is the root node which is corresponding to the initial state.
 Actions: It gives the description of all the available actions to the agent.
 Transition model: A description of what each action do, can be represented as a transition model.
 Path Cost: It is a function which assigns a numeric cost to each path.
 Solution: It is an action sequence (Path) which leads from the start node to the goal node.
 Optimal Solution: If a solution has the lowest cost among all solutions.
Agenda
 Search Algorithms in AI
 Search Algorithm Terminologies
Properties of Search Algorithms
 Types of Search Algorithms
 Search Algorithm over Graph
FCI-Minia University 6
Properties of Search Algorithms
 There are the Four essential properties of search algorithms to compare the efficiency
of these algorithms:
 Completeness: A search algorithm is said to be complete if it guarantees to return a
solution if at least any solution exists for any random input.
 Optimality: If a solution found for an algorithm is guaranteed to be the best solution
(lowest path cost) among all other solutions, then such a solution for is said to be an
optimal solution.
 Time Complexity: Time complexity is a measure of time for an algorithm to complete its
task.
 Space Complexity: It is the maximum storage space required at any point during the
search, as the complexity of the problem. 7
Agenda
 Search Algorithms in AI
 Search Algorithm Terminologies
 Properties of Search Algorithms
Types of Search Algorithms
 Search Algorithm over Graph
FCI-Minia University 8
9
Types of search algorithms
 Based on the search problems we can classify the search algorithms into:
1. Uninformed Search (Blind Search)Algorithms.
2. Informed Search (Heuristic Search) Algorithms.
10
Uninformed/BlindSearch:
 Uninformed Search does not contain any domain knowledge such as closeness, the location of the
goal.
 Uninformed Search operates in a brute-force way as it only includes information about how to
traverse the tree and how to identify leaf and goal nodes.
 Uninformed Search applies a way in which search tree is searched without any information about
the search space like initial state operators and test for the goal, so it is also called blind search.
 Uninformed Search examines each node of the tree until it achieves the goal node.
 It can be divided into 5 main types:
Breadth-first search Iterative deepening depth-first search
Uniform costsearch BidirectionalSearch
Depth-first search
Types of Search Algorithms
FCI-Minia University 11
Informed Search
 Informed Search Algorithms use domain knowledge.
 In an informed search, problem information is available which can guide the search.
 Informed Search strategy can find a solution more efficiently than an uninformed search
strategy.
 Informed Search is also called a Heuristic Search.
 A heuristic is a way which might not always be guaranteed for best solutions but
guaranteed to find a good solution in reasonable time.
 Informed Search can solve much complex problem which could not be solved in another
way.
 An example of informed search algorithms .
Greedy Search A* Search
Types of Search Algorithms
Agenda
 Search Algorithms in AI
 Search Algorithm Terminologies
 Properties of Search Algorithms
 Types of Search Algorithms
Search Algorithm over Graph
FCI-Minia University 12
Search over Graph
13
Python representations of graph components:
 Graph nodes (Vertices): A "graph" in mathematics and computer science consists of "nodes",
also known as "vertices".
 Nodes may or may not be connected with one another.
 the node "a" is connected with the node "c",
 but "a" is not connected with "b".
 Graph edge: The connecting line between two nodes is called an edge.
 Undirected graph: If the edges between the nodes are undirected, the graph is called an
undirected graph.
 Directed graph: If an edge is directed from one vertex (node) to another, a graph is called a
directed graph. An directed edge is called an arc.
Usages of Graph in AI
FCI-Minia University 14
 Though graphs may look very theoretical, many practical problems can be represented by
graphs.
 They are often used to model problems or situations in physics, biology, psychology and
above all in computer science using graph.
 In computer science, graphs are used to represent networks of communication, data
organization, computational devices, the flow of computation.
 They are used to represent the data organization, like the file system of an operating
system, or communication networks. The link structure of websites can be seen as a graph
as well.
Graph Implementation
FCI-Minia University 15
 Graph can be implemented in python using data type (dictionary)
 The keys of the dictionaryare the nodes of our graph.
 The values of the dictionary are lists with the nodes, which are connecting by an
edge.
graph = { "a" : ["c"],
"b" : ["c", "e"],
"c" : ["a", "b", "d", "e"],
"d" : ["c"],
"e" : ["c", "b"],
"f" : [] }
16
 Declarationof graph Class
 Declarationof Functionsthat generating a list of graph nodes and edges
FCI-Minia University 17
Output
18
 Declarationof Functionto add a node to graph
 Declarationof Functionto add an edge to graph
FCI-Minia University 19
Output
FCI-Minia University 20
Output
FCI-Minia University 21
Output
22
 Declarationof Function__str__ to representgraph
23
 Declarationof Function Searchovergraph
FCI-Minia University 24
Output
FCI-Minia University 25
Assignment
1. Try to update the Method of find_path() to be find_all_paths() finds all the paths
between a start node to an end node.
Thanks…
Next: DFS , BFS
FCI-Minia University 26

Lab5--AI--Search Algorithms in Artificial Intelligence.pdf

  • 1.
    Artificial Intelligence Third YearStudents Department of Computer Science T.A. Rehab Emad El-Dein Sayed FCI-Minia University 1
  • 2.
    Agenda  Search Algorithmsin AI  Search Algorithm Terminologies  Properties of Search Algorithms  Types of Search Algorithms  Search Algorithm over Graph FCI-Minia University 2
  • 3.
    Search Algorithms inAI 3  Problem-Solving Agents:  ArtificialIntelligence is the study of buildingagents that act rationally.  Rational agents or Problem-solving agents in AI mostly used these search strategies or algorithms to solve a specific problem and provide the best result. Problem-solving agents are the goal-based agents and use atomic representation.  Search Algorithms are one of the most important areas of Artificial Intelligence.  Search Algorithms are universal problem-solving methods.
  • 4.
    Agenda  Search Algorithmsin AI Search Algorithm Terminologies  Properties of Search Algorithms  Types of search algorithms  Search over Graph FCI-Minia University 4
  • 5.
    5 Search Algorithm Terminologies Search: Searching is a step by step procedure to solve a search-problem in a given search space.  A Search Problem can have three main factors:  Search Space: Search space represents a set of possible solutions, which a system may have.  Start State: It is a state from where agent begins the search.  Goal test: It is a function which observe the current state and returns whether the goal state is achieved or not.  Search tree: A tree representation of search problem is called Search tree.  The root of the search tree is the root node which is corresponding to the initial state.  Actions: It gives the description of all the available actions to the agent.  Transition model: A description of what each action do, can be represented as a transition model.  Path Cost: It is a function which assigns a numeric cost to each path.  Solution: It is an action sequence (Path) which leads from the start node to the goal node.  Optimal Solution: If a solution has the lowest cost among all solutions.
  • 6.
    Agenda  Search Algorithmsin AI  Search Algorithm Terminologies Properties of Search Algorithms  Types of Search Algorithms  Search Algorithm over Graph FCI-Minia University 6
  • 7.
    Properties of SearchAlgorithms  There are the Four essential properties of search algorithms to compare the efficiency of these algorithms:  Completeness: A search algorithm is said to be complete if it guarantees to return a solution if at least any solution exists for any random input.  Optimality: If a solution found for an algorithm is guaranteed to be the best solution (lowest path cost) among all other solutions, then such a solution for is said to be an optimal solution.  Time Complexity: Time complexity is a measure of time for an algorithm to complete its task.  Space Complexity: It is the maximum storage space required at any point during the search, as the complexity of the problem. 7
  • 8.
    Agenda  Search Algorithmsin AI  Search Algorithm Terminologies  Properties of Search Algorithms Types of Search Algorithms  Search Algorithm over Graph FCI-Minia University 8
  • 9.
    9 Types of searchalgorithms  Based on the search problems we can classify the search algorithms into: 1. Uninformed Search (Blind Search)Algorithms. 2. Informed Search (Heuristic Search) Algorithms.
  • 10.
    10 Uninformed/BlindSearch:  Uninformed Searchdoes not contain any domain knowledge such as closeness, the location of the goal.  Uninformed Search operates in a brute-force way as it only includes information about how to traverse the tree and how to identify leaf and goal nodes.  Uninformed Search applies a way in which search tree is searched without any information about the search space like initial state operators and test for the goal, so it is also called blind search.  Uninformed Search examines each node of the tree until it achieves the goal node.  It can be divided into 5 main types: Breadth-first search Iterative deepening depth-first search Uniform costsearch BidirectionalSearch Depth-first search Types of Search Algorithms
  • 11.
    FCI-Minia University 11 InformedSearch  Informed Search Algorithms use domain knowledge.  In an informed search, problem information is available which can guide the search.  Informed Search strategy can find a solution more efficiently than an uninformed search strategy.  Informed Search is also called a Heuristic Search.  A heuristic is a way which might not always be guaranteed for best solutions but guaranteed to find a good solution in reasonable time.  Informed Search can solve much complex problem which could not be solved in another way.  An example of informed search algorithms . Greedy Search A* Search Types of Search Algorithms
  • 12.
    Agenda  Search Algorithmsin AI  Search Algorithm Terminologies  Properties of Search Algorithms  Types of Search Algorithms Search Algorithm over Graph FCI-Minia University 12
  • 13.
    Search over Graph 13 Pythonrepresentations of graph components:  Graph nodes (Vertices): A "graph" in mathematics and computer science consists of "nodes", also known as "vertices".  Nodes may or may not be connected with one another.  the node "a" is connected with the node "c",  but "a" is not connected with "b".  Graph edge: The connecting line between two nodes is called an edge.  Undirected graph: If the edges between the nodes are undirected, the graph is called an undirected graph.  Directed graph: If an edge is directed from one vertex (node) to another, a graph is called a directed graph. An directed edge is called an arc.
  • 14.
    Usages of Graphin AI FCI-Minia University 14  Though graphs may look very theoretical, many practical problems can be represented by graphs.  They are often used to model problems or situations in physics, biology, psychology and above all in computer science using graph.  In computer science, graphs are used to represent networks of communication, data organization, computational devices, the flow of computation.  They are used to represent the data organization, like the file system of an operating system, or communication networks. The link structure of websites can be seen as a graph as well.
  • 15.
    Graph Implementation FCI-Minia University15  Graph can be implemented in python using data type (dictionary)  The keys of the dictionaryare the nodes of our graph.  The values of the dictionary are lists with the nodes, which are connecting by an edge. graph = { "a" : ["c"], "b" : ["c", "e"], "c" : ["a", "b", "d", "e"], "d" : ["c"], "e" : ["c", "b"], "f" : [] }
  • 16.
    16  Declarationof graphClass  Declarationof Functionsthat generating a list of graph nodes and edges
  • 17.
  • 18.
    18  Declarationof Functiontoadd a node to graph  Declarationof Functionto add an edge to graph
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
    FCI-Minia University 25 Assignment 1.Try to update the Method of find_path() to be find_all_paths() finds all the paths between a start node to an end node.
  • 26.
    Thanks… Next: DFS ,BFS FCI-Minia University 26