Implementing Tower of Hanoi Problem, Lab Reports of Artificial Intelligence

The Tower of Hanoi is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a pointed shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple

Typology: Lab Reports

2020/2021

Uploaded on 01/28/2021

nimra-nawaz-1
nimra-nawaz-1 🇵🇰

5

(2)

5 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The University of Lahore, Islamabad Campus
Fall 2019
Lab Manual
Artificial Intelligence
CS13217
Experiment No # 8
1
pf3

Partial preview of the text

Download Implementing Tower of Hanoi Problem and more Lab Reports Artificial Intelligence in PDF only on Docsity!

The University of Lahore, Islamabad Campus

Fall 2019

Lab Manual

Artificial Intelligence

CS

Experiment No # 8

Implementing Travelling Salesman Problem

Objective: To understand and implement Traveling Salesman problem using Nearest Neighborhood Algorithm. Introduction: Problem A traveling salesman has to travel through a bunch of cities in a loop, in such a way that the expenses on traveling are minimized. This is the infamous Traveling Salesman Problem (aka TSP ) problem it belongs to a family of problems, called NP-complete problem. It is conjectured that all those problems requires exponential time to solve them. In our case, this means that to find the optimal solution you have to go through all possible routes, and the numbers of routes increases exponentially with the numbers of cities. Formal Definition We are given a complete undirected graph G that has a nonnegative integer cost (weight) associated with each edge, and we must find a Hamiltonian cycle (a tour that passes through all the vertices) of G with minimum cost. Theory: In our case we have points in the plane (i.e. cities) and the cost of the traveling between two points is the distance between them. In other words, we have a map with cities, any two of which are connected by a direct straight road and we want to find a shortest tour for our poor traveling salesman, who "wants" to visit every city. Nearest Neighborhood Algorithm: These are the steps of the algorithm:

_1. start on an arbitrary vertex as current vertex.

  1. find out the shortest edge connecting current vertex and an unvisited vertex V.
  2. set current vertex to V.
  3. mark V as visited.
  4. if all the vertices in domain are visited, then terminate.
  5. Go to step 2.
  6. The sequence of the visited vertices is the output of the algorithm._ Tasks:
  7. Implement Travelling Salesman Problem using Nearest Neighborhood Algorithm.