Professional Documents
Culture Documents
Pavan Kumar V
Pavan Kumar V
Pavan Kumar V
Experiment No:6
Define the following terms: graph, vertex, edge, path, cycle, and weighted graph.
What are the pros and cons of using heuristics for solving the TSP?
Experiment No: 07
Implementation of problem-solving strategies: either using Forward Chaining or Backward Chaining
In what scenarios would you prefer to use forward chaining over backward chaining, and vice versa?
Given the propositions: "If it rains, the ground will be wet" and "It is raining", use Modus Ponens to
infer a conclusion.
Given the predicates: "All humans are mortal" and "Socrates is a human", use universal instantiation
to draw a conclusion.’
Describe common inference rules such as Modus Ponens, Modus Tollens, and the Law of Syllogism.
The Traveling Salesman Problem (TSP) is a classic optimization problem in which a salesman is
required to visit a set of cities exactly once and return to the starting city, with the objective of
minimizing the total travel distance. The TSP is NP-hard, meaning that there is no known efficient
solution to solve all instances of the problem in polynomial time.
Definitions
Graph
A graph is a mathematical structure used to model pairwise relationships between objects. It consists
of a set of vertices (nodes) and a set of edges (connections) that connect pairs of vertices.
Vertex
Edge
Path
A path in a graph is a sequence of vertices connected by edges, where each vertex is visited at most
once.
Cycle
A cycle is a path in a graph that starts and ends at the same vertex, with all other vertices visited
exactly once.
A weighted graph is a graph in which each edge has an associated numerical value (weight), often
representing distance, cost, or time.
Directed Graph
In a directed graph, edges have a direction, meaning they go from one vertex to another. The order of
vertices in an edge matters (e.g., an edge from vertex A to vertex B is different from an edge from
vertex B to vertex A).
Undirected Graph
In an undirected graph, edges do not have a direction. The connection between two vertices is
bidirectional (e.g., an edge between vertex A and vertex B is the same as an edge between vertex B
and vertex A).
1. Logistics and Transportation**: Optimizing delivery routes for goods and services.
3. Circuit Design**: Minimizing the length of wire required to connect components on a circuit
board.
4. DNA Sequencing**: Reconstructing the shortest possible sequence that contains a set of given
subsequences.
Speed: Heuristics can provide good solutions quickly, making them suitable for large instances
where exact methods are impractical.
- Simplicity: Heuristics are often easier to implement and understand compared to exact algorithms.
Cons
Optimality: Heuristics do not guarantee finding the optimal solution, only a good approximation.
Performance Variability: The quality of the solution provided by heuristics can vary depending on
the problem instance.
-Parameter Tuning: Many heuristics require careful tuning of parameters to perform well, which can
be time-consuming.
u, v, weight = edge
matrix[u][v] = weight
if not directed:
matrix[v][u] = weight
num_vertices = 4
print(adj_matrix)
```python
total_distance = 0
num_vertices = len(tour)
for i in range(num_vertices):
u = tour[i]
total_distance += adjacency_matrix[u][v]
return total_distance
tour = [0, 1, 2, 3]
print(distance)