final_project_AI
final_project_AI
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).
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.
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
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.
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
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.
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.
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
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.
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: