You are on page 1of 3

Artificial Intelligence and Neural Network Lab

Lab Manual Artificial Intelligence and Neural Network


Session: 2019 Semester: 6th
Course Instructor: Rabeeya Saleem Degree Program: Computer Science-GCU-LHR

Objective:
 To be able to understand hill-climbing local search
 To be able to implement simpler variants of hill-climbing and genetic algorithms in Python.

Basic-Python Practice:
String Manipulation:
1. Write a program that check either given string contains the substring or not

List Manipulation:
2. Write a program to create a list and apply these functions:
 Insert(position, element)
 Remove(element)
 Count()
 Index(element)
 Sort()
 Append(element)

Dictionary Manipulation:
3. Write a program in python to create a dictionary:

Dict_marks ={ ‘DSA’: 78, ‘OOP’: 90, ‘AI’: 65, ‘CA’: 70}

From the given dictionary: Assume all subject are out of 100.

Find the sum of all marks, Obtained Marks, Highest and Lowest subject and finally the percentage of
marks.

Tuple Manipulation:
4. Write a program in python to sort a tuple by 2nd item

tuple1 = (('a', 23),('b', 37),('c', 11), ('d',29))

Local Search Algorithm:


A local search algorithm that moves continuously upward (increasing) until the best solution is attained.
An example of local search algorithm is ‘Hill-Climbing’ algorithm.

Features of Hill-Climbing Algorithm:


 Greedy Approach
 No Backtracking
 Feedback Mechanism
 Incremental changes
Artificial Intelligence and Neural Network Lab

Types of Hill-Climbing Algorithm:


 Simple hill climbing
This is a simple form of hill climbing that evaluates the neighboring solutions. If the next neighbor state
has a higher value than the current state, the algorithm will move. The neighboring state will then be set
as the current one.
Algorithm
1. Conduct an assessment of the current state. Stop the process and indicate success if it is a goal
state.
2. Perform looping on the current state if the assessment in step 1 did not establish a goal state.
3. Continue looping to attain a new solution.
4. Assess the new solution. If the new state has a higher value than the current state in steps 1 and 2,
then mark it as a current state.
5. Continue steps 1 to 4 until a goal state is attained. If this is the case, then exit the process.

 Steepest – Ascent hill climbing


This algorithm is more advanced than the simple hill-climbing algorithm. It chooses the next node by
assessing the neighboring nodes. The algorithm moves to the node that is closest to the optimal or goal
state.
Algorithm
1. Conduct an assessment of the current state. Stop the process and indicate success if it is a goal
state.
2. Perform looping on the current state if the assessment in step 1 did not establish a goal state.
3. Continue looping to attain a new solution.
4. Establish or set a state (X) such that current state successors have higher values than it.
5. Run the new operator and produce a new solution.
6. Assess this solution to establish whether it is a goal state. If this is the case, exit the program.
Otherwise, compare it with the state (X).
7. If the new state has a higher value than the state (X), set it as X. The current state should be set to
Target if the state (X) has a higher value than the current state.

 Stochastic hill climbing


In this algorithm, the neighboring nodes are selected randomly. The selected node is assessed to establish
the level of improvement. The algorithm will move to this neighboring node if it has a higher value than
the current state.

Application of Hill-Climbing:
 Traveling salesman problem
 Robotics
 Job Scheduling

Lab-Practice:
1. Solve a traveling saleman problem using Hill-Climbing Algorithm:
There are total 4 nodes that are needed to be explored. As a saleman you are required to visit these
nodes with minimum cost.
Artificial Intelligence and Neural Network Lab

2. Solve a traveling saleman problem using Hill-Climbing Algorithm:


There are total 7 cities that are needed to be explored. As a saleman you are required to visit these cities
with minimum cost.

Diagram for Question-01 Diagram for Question-02


Lab-Assignment:
1. Write a code in python to solve 8-queen puzzle using Hill-Climbing algorithm.
2. Let we have a dictionary D which contain roll number of students as key and its values shall be a
list. The list has tuples as its item. Each tuple represents the name of the subject and gpa of that
subject. You can visualize the data structure as of following:

Key Value
2021-CS-700 [(DSA,3.0), (Algo,2.5), (AI,3.3)]
2021-CS-701 [(DSA,2.7), (Algo,3.0), (AI,2.7)]
2021-CS-702 [(DSA,3.0), (Algo,2.5), (AI,2.7)]
2021-CS-710 [(DSA,3.3), (Algo,3.0), (AI,3.3)]
2021-CS-711 [(DSA,3.5), (Algo,3.5), (AI,3.7)]
2021-CS-712 [(DSA,3.0), (Algo,2.5), (AI,2.5)]
2021-CS-713 [(DSA,3.7), (Algo,2.5), (AI,3.0)]
a) Write a program which shall print GPA of all students. Assume all subject have 3 credit hours.
b) Write a program that print the highest number obtained in DSA
c) Write a program that print the total number of students those have less than 3.0 GPA
You are required to make a one page proposal as a semester project. It should contain
1. Title of your Project
2. Group Members
3. Problem Statement (One Paragraph or 150 Words)
4. How you solve this Problem (200 Words)

Lab Submission:
Create two python files name as 8-queen puzzle.py and python-practice.py
Create one document for proposal in MS-Word with name as: semester_project_proposal.docx
Submit it on email id: rabeeyasaleem@uet.edu.pk with subject 2019-GCU-CS-LABASSIGNMENT

You might also like