0% found this document useful (0 votes)
4 views

final_project_AI

Artificial Intelligence final project

Uploaded by

Fatima Khalil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

final_project_AI

Artificial Intelligence final project

Uploaded by

Fatima Khalil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

1

Final Lab Report


Course: Artificial Intelligence
Roll No: FA22-BDS-051
Submitted to: Dr. Saira Baig
Submitted by: Fatima Khalil

Date: 27 May,2024
2

1.CSP
CSP involves variables with domains and constraints that limit variable assignments. The
university scheduling problem fits this framework, making CSP suitable for solving it.
Problem : University scheduling Managnment

1. Introduction
This project aims to develop a university scheduling system using Constraint Satisfaction
Problems (CSP) principles. The system will efficiently assign courses to rooms and times while
adhering to constraints and requirements.

2. Problem Description
University Scheduling
The university scheduling problem involves assigning courses to rooms and timeslots.
Constraints include room capacities, instructor availability, and course precedence.
CSP Formulation
• Variables: Each course is a variable to be assigned a room and time.
• Domains: Rooms and timeslots available for scheduling.
• Constraints: Room capacities, instructor availability, and course precedence.

3. Solution Approach
 Class Definition
T Scheduling class encapsulates the solution logic, including methods for initializing the
problem, solving it using CSP techniques, and ensuring constraints are met.
 Initialization (int method): Initializes variables, domains, and constraints.
 Solve Method (solve method): Initiates the CSP algorithm to assign courses to rooms
and timeslots. Backtracking (backtrack method): Recursively assigns values to variables
while adhering to constraints.
 Variable Selection (select_unassigned_variable method): Uses heuristics to select the
next variable to assign.
 Value Ordering (order_domain_values method): Orders domain values for each
variable. Consistency Check (is_consistent method): Ensures that the current assignment
does not violate constraints.

4. Implementation
3

• Problem Setup
The university scheduling problem is represented with variables for each course, domains for
rooms and timeslots, and constraints for capacities, availability, and precedence.
• Code Walkthrough
The provided code initializes a University Scheduling instance with variables, domains, and
constraints. It then solves the scheduling problem using CSP techniques.

5.Pseudo-Code:
 Initialize the problem:
- Define variables for each course to be scheduled, each with domains representing possible
rooms and timeslots.
- Assign initial values to variables based on constraints such as room capacities and instructor
availability.

 Define constraints:
- Room capacity constraint: Ensure that the number of students enrolled in a course does not
exceed the capacity of the assigned room.
- Instructor availability constraint: Ensure that the instructor teaching a course is available
during the assigned timeslot.
- Course precedence constraint: Define the order in which certain courses must be scheduled
(e.g., C1 must be scheduled before C2).

 Implement the CSP algorithm:


- Use backtracking to systematically assign values to variables while ensuring constraints are
met.
- Select unassigned variables using heuristics such as the Minimum Remaining Values (MRV)
heuristic.
- Order domain values using heuristics such as the Least Constraining Value (LCV) heuristic.
- Check consistency at each step to ensure that the current assignment does not violate
constraints - Invoke the CSP algorithm to find a valid assignment of courses to rooms and
timeslots.
- If a solution is found, output the schedule with assigned rooms and timeslots for each course.
- If no solution is found, indicate that the scheduling problem is infeasible.
4

 Performance optimization:
- Implement pruning techniques such as forward checking and constraint propagation to reduce
the search space.
- Explore additional heuristics for variable selection and value ordering to improve algorithm
efficiency.
- Benchmark and profile the algorithm to identify potential bottlenecks and areas for
improvement.

 Output the schedule:


- Print or display the final schedule with assigned rooms and timeslots for each course.
- Provide feedback or visual representation of the schedule to stakeholders for review and
validation.

 Conclusion and future work:


- Summarize the results of the scheduling process and discuss any insights or lessons learned.
- Identify areas for future work, such as incorporating additional constraints or optimizing the
algorithm further.

6. Results
 Solution Generation
The algorithm successfully generates a schedule by assigning courses to rooms and timeslots
while satisfying constraints.
 Output:
The schedule is printed, displaying the assigned rooms and timeslots for each course.
 Performance
The backtracking algorithm performs efficiently for typical university scheduling scenarios.
Further optimization may be explored for larger-scale problems.

7. Conclusion
Summary: This project demonstrates the effectiveness of using CSP to solve university
scheduling problems. The implemented algorithm efficiently assigns courses to rooms and times
5

while meeting constraints, showcasing the applicability of CSP in real-world scheduling


scenarios.
Future Work
Future enhancements could include incorporating additional constraints or preferences,
optimizing the algorithm for larger datasets, and integrating with university scheduling systems
for practical use.
8.CODE:
6

OUTPUT:
7

2.GENETIC ALGORITHM
A genetic algorithm (GA) is a type of optimization algorithm inspired by the process of natural
selection and evolution. It is used to find approximate solutions to optimization and search
problems by mimicking the process of natural selection, where the fittest individuals are more
likely to survive and produce offspring.
Report: Travelling Salesman Problem

1. Project Overview :
The objective of this project is to solve the Traveling Salesman Problem (TSP) using a Genetic
Algorithm (GA). The TSP is a classic optimization problem that requires finding the shortest
possible route that visits each city exactly once and returns to the starting city. This report details
the implementation and performance of a GA to tackle this problem for a set of five cities.

2. Problem Description
 Traveling Salesman Problem (TSP)
The TSP involves a salesman who must visit a set of cities, each exactly once, and return to the
origin city. The goal is to minimize the total travel distance. Given its NP-hard nature, exact
solutions become impractical for large numbers of cities, making heuristic and metaheuristic
approaches like GAs valuable.

3. Genetic Algorithm approach to TSP


Explanation of Genetic Algorithm:
 Inspired by the process of natural selection and evolution.
 Based on the principles of selection, crossover, and mutation.
Application of GA to TSP:
 Representing solutions: Chromosomes as routes.
 Fitness evaluation: Measure of the total distance traveled.
 Selection: Favoring fitter individuals for reproduction.
 Crossover: Exchanging genetic material between selected individuals.
 Mutation: Introducing random changes to maintain diversity.

4.Class Definitions
 City Class: Represents a city with a name and coordinates.
 Route Class: Represents a route with a sequence of cities and a fitness score.

5.Pseudo-Code :
 Initialization: Generate an initial population of random routes.
 Evaluation: Calculate the fitness of each route.
8

 Selection: Select the best routes based on fitness.


 Crossover and Mutation: Generate new routes by crossing over selected routes and
applying mutations.
 Replacement: Form a new population from the offspring.
 Termination: Repeat steps 2-5 for a fixed number of generations or until convergence.

Initialize population
Evaluate fitness of each individual
Repeat until termination condition is met:
Select individuals for reproduction
Perform crossover to create offspring
Apply mutation to offspring
Evaluate fitness of new population
Select best solution as final result

5. Function Definitions
 initialize_population: Generate initial population of solutions (routes).
 evaluate_fitness: Calculate fitness (total distance) for each individual.
 selection: Choose individuals for reproduction based on fitness.
 crossover: Exchange genetic material between selected individuals.
 mutation: Introduce random changes to maintain diversity.
 termination_condition: Define criteria for terminating the algorithm.

6.Detailed Explanation
 Initialization: Random routes are generated to form the initial population.
 Fitness Calculation: Fitness of each route is calculated based on total travel distance.
 Crossover and Mutation: Crossover combines routes from parents, and mutation
introduces small changes.
 Selection and Replacement: The best routes are selected to form the new population
for the next generation.

7.Performance Analysis
 Time complexity: Analyze the time complexity of each operation.
 Space complexity: Assess memory requirements.
 Convergence rate: Measure how quickly the algorithm finds optimal solutions.
 Scalability: Evaluate performance on large problem instances.

8. Results
9

 Best Route
The algorithm identifies the best route after iterating through the generations. Example output:

Best Route: A B E D C
Total Distance: 10.0

 Performance Metrics:
Total Distance: The fitness value representing the total distance of the best route found.
Generations: Number of iterations to achieve convergence or reach the maximum generation
limit.
9. Conclusion
 Summary
The project successfully demonstrates the application of Genetic Algorithms to solve the TSP for
a small set of cities. The GA approach efficiently finds a near-optimal solution by evolving the
population through selection, crossover, and mutation.

10.Future Work
 Optimization: Explore advanced GA techniques such as elitism, adaptive mutation rates,
and different selection methods to improve solution quality and convergence speed.
 Larger Instances: Test and optimize the algorithm for larger sets of cities to assess
scalability and performance on more complex problem instances.
 Parallel Processing: Implement parallel processing techniques to distribute
computations across multiple cores or nodes, thereby speeding up the execution time for
large-scale TSP instances.
CODE:
10
11
12

Output :
13

3.PROLOG

Prolog is a logic programming language that is particularly well-suited for tasks that involve
symbolic or non-numeric computation. It is based on formal logic and provides a powerful
mechanism for representing and reasoning about knowledge.

Problem : Car Diagnosis Expert System


1. Introduction
 Project Overview
The project involves developing an expert system that diagnoses car problems based on
symptoms reported by the user.
 Purpose
The expert system aims to assist users in identifying potential issues with their cars quickly
and accurately.

2. Solution Approach:
 Algorithm Design
The application consists of key components including:
 Knowledge Base: Contains symptoms and corresponding car problems.
 Inference Engine: Determines potential car problems based on reported symptoms.
 User Interface: Collects symptoms from the user and displays the diagnosis.

3.Class Definitions :
 Question Class: Represents each symptom and associated car problem.
 Answer Class: Represents possible answers for each symptom.

4.Data Structures Used :


 Lists to store symptoms and corresponding car problems.

5.Pseudo-Code:
function infer_solution(query):
if query is a fact in the knowledge base:
return true
else if query matches a rule in the knowledge base:
14

for each sub-goal in the rule:


if not infer_solution(sub-goal):
return false
return true
else:
return false

knowledge_base = [
fact1,
fact2,
rule1,
rule2,
...
]

function main():
initialize knowledge_base
while true:
prompt user for query
if query == "exit":
exit the program
else:
result = infer_solution(query)
if result is true:
display "Yes, the query is true."
else:
display "No, the query is false."

main()

5.Key Functions
 infer_solution(query): This function recursively searches the knowledge base to
determine whether the given query can be inferred from the facts and rules. If the query
matches a fact, it returns true. If the query matches a rule, it recursively evaluates the sub-
goals of the rule to determine if they are all true. If any sub-goal is false, the function
returns false.
 knowledge_base: This is a collection of facts and rules that represent the knowledge of
the system.
15

 main(): This is the main entry point of the program. It initializes the knowledge base,
prompts the user for queries, and displays the results of inference. The program continues
to prompt the user for queries until the user decides to exit.

6. Implementation:
 Initialization: Symptoms and corresponding car problems are initialized in lists.
 Symptom Collection: The application prompts the user to report symptoms.
 Diagnosis: The inference engine determines potential car problems based on reported
symptoms.

Example Execution Flow


 Starting the Diagnosis: The user is welcomed and asked to report symptoms.
 Symptom Collection: The user inputs symptoms.
 Diagnosis Display: The application displays potential car problems based on reported
symptoms.

7. Conclusion
Summary:
 The expert system successfully diagnoses car problems based on reported symptoms,
assisting users in identifying potential issues with their cars.

8.Future Work:
 The system can be expanded with additional symptoms and car problems to enhance its
diagnostic capabilities.
This report outlines the development of a Car Diagnosis Expert System, providing insights into
its structure, functionality, and potential for future enhancements.
16

CODE:
17

OUTPUT:

You might also like