You are on page 1of 15

Page 1 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

Soft Computing Project Report

Submitted To: Dr. Aloke Datta

Submitted By:
1. Smit Patel (21UCS205)
2. Yash Chugh (21UCS234)
3. Arnit Gupta (21UCS029)
4. Shashvat Jain (21UCS189)
Page 2 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

1. FUZZY LOGIC CONTROLLER FOR WASHING MACHINE WASH TIME


Objective
The task involves designing a fuzzy logic controller using Mamdani's approach to determine the wash time of a
domestic washing machine based on the dirt and grease on clothes. The inputs are represented using ve
descriptors for dirt (VSD, SD, MD, HD, VHD) and three descriptors for grease (SG, MG, HG). The output
variable, wash time, is represented using ve descriptors (VST, ST, MT, HT, VHT).

Membership Functions
Triangular membership functions were employed for all fuzzy classes to represent the linguistic variables of dirt,
grease, and wash time. These membership functions allow for a smooth transition between different classes.

Rules for Fuzzy Logic Table


The set of rules for fuzzy logic tables is as follows:

SG MG HG

VSD VST VST ST

SD VST ST MT

MD ST MT HT

HD MT HT VHT

VHD HT VHT VHT

Inputs and Outputs


The input scale for grease is 0 to 50, while for dirt, it is 0 to 100. The output scale for wash time is 0 to 60
minutes.
In this report we used the following triangular membership functions for
1. Dirt
fi
fi
Page 3 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

2. Grease

3. Wash Time
Page 4 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

Implementation:

Step 1: Import Libraries

This imports the necessary libraries, skfuzzy for fuzzy logic operations and numpy for numerical operations.

Step 2: De ne Universes of Discourse

Here we de nedthe universes of discourse for dirt (0 to 100), grease (0 to 50), and wash time (0 to 60) using
NumPy arrays.

Step 3: De ne Membership Functions for Variables

Here we de ned the triangular membership functions for linguistic variables within their respective ranges. The
graph of which we have plotted before in our Report.
fi
fi
fi
fi
Page 5 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

Step 4: De ne Fuzzy Rules and Create Control System

Fuzzy rules based on combinations of dirt and grease levels, associating them with wash time.

Next we created a control system with the de ned rules. Initialised the simulation object using this control
system.

Step 5: Input Values and Perform Fuzzy Inference


fi
fi
Page 6 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

Next, we have speci ed input values for dirt and grease in lists, then iterate through the lists, inputting values
into the simulation, computing the wash time, and printing the results.

Step 6: showing the output Graphs

Visualising the fuzzy sets for dirt, grease, and wash time using the view method. And that is the output of
our code also for the following values of dirt and grease:-
fi
Page 7 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

Result:
The program successfully determines the wash time for any given combination of dirt and grease values
within the speci ed ranges.

For example here we have shown the calculation for:-

Dirt = 60 , Grease = 20 our answer comes out as wash_time = 32.45852653271511.


fi
Page 8 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

2. GENETIC ALGORITHM FOR TRAVELING SALESMAN PROBLEM

Objective:
The task involves solving the Traveling Salesman Problem (TSP) using a Genetic Algorithm (GA). The TSP
consists of nding the most ef cient route that visits each city exactly once. The number of cities is 15, and the
weight matrix represents the distances between cities.The algorithm will run for 20 iterations with a population
size of 15 chromosomes.

Genetic Algorithm Components:


• Initialization:

A population of 15 chromosomes, each representing a unique sequence of cities, is randomly generated. The
chromosomes encode potential solutions to the TSP.

• Selection:

Roulette-wheel based selection is employed to choose parents for crossover. Roulette-wheel based selection
in genetic algorithms allocates selection probabilities to individuals proportional to their tness. After
normalising tness values, a virtual roulette wheel is created, and individuals are chosen based on randomly
generated numbers. This method ensures that tter individuals have higher chances of selection while
maintaining diversity. Selected individuals are then used as parents for crossover, contributing to the evolution
of the population toward optimal solutions in optimisation problems

• Crossover:

A one-point crossover is performed between randomly selected parents. The crossover point is chosen
randomly to introduce diversity in the offspring.

• Mutation:

To maintain diversity in the population, a mutation operation is applied with a low probability. Mutation involves
swapping two cities in a chromosome.

• Elitism:

The best-performing chromosomes from the current population are directly transferred to the next generation,
ensuring that the best solutions are preserved.
fi
fi
fi
fi
fi
Page 9 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

Implementation:

Step 1: Initialization Section

This section initialises various parameters and data structures used in the genetic algorithm for solving the
Traveling Salesman Problem (TSP).

• population: List to hold paths (routes) for the individuals in the population.
• population_size: Number of individuals in each generation.
• mutate_prob: Probability of mutation occurring during reproduction.
• n_generations: Number of generations to run the genetic algorithm.
• routes_length: List to store the lengths of routes in the population.
• tness: List to store the tness values of individuals in the population.
• best_path: Initially set to a high value; it will be updated as the algorithm progresses.

Step 2: Initialising distances and de ning a function for it


fi
fi
fi
Page 10 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

Here in this part we have initialised the following:-

• distances: 2D list representing the distance matrix between cities. It’s an 15x15 matrix.
• cities: List representing the cities to be visited.
• calc_distance: Function to calculate the distance between two cities.

Step 3: Population Initialization Section

This section de nes functions for creating initial random routes, calculating the total length of a route, and
creating the initial population.
• create_route(): Generates a random route by shuf ing the cities.
• calc_route_length(): Calculates the total length of each route in the population and updates routes_length
and tness.
• create_population(): Initialises the population by generating random routes.
fi
fi
fl
Page 11 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

Step 4: Genetic Operations Section

This section de nes mutation and crossover operations.


• swap_mutation(ind): Swaps two cities in a route with a given probability.
• one_point_crossover(ind1, ind2): Performs one-point crossover between two parent routes.
fi
Page 12 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

Step 5: Selection and Evaluation Section

This section includes functions for parent selection and nding the ttest individual.
• roulette_wheel_selection(): Implements Fitness Proportionate Selection (Roulette Wheel Selection) to choose
a parent based on their tness.
• nd_ ttest(): Finds the index of the ttest individual in the current population.
fi
fi
fi
fi
fi
fi
Page 13 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

Step 6: Main Genetic Algorithm Loop Section

This section initialises the algorithm, prints initial population details, and contains the main loop for the
speci ed number of generations.

Step 7: Main Genetic Algorithm Operations Section


fi
Page 14 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

This section includes crossover, mutation, and selection operations within the main loop.
• one_point_crossover(ind1, ind2) is used for crossover, and swap_mutation(ind) is used for mutation.
• The combined population is created by combining the current population and the offspring generated
through crossover.
• The best individuals are selected for the next generation using elitism.

Step 5: Finding Best Path and Results Printing Section

• The overall best path and its length are updated if a better path is found during the current generation.
• This section prints the results of each generation, including the best route and its length.
• Finally, the code prints the nal result, which is the best path found by the genetic algorithm.
fi
Page 15 of 15

THE LNM INSTITUTE OF INFORMATION TECHNOLOGY

• Output

After running it successfully for 20 iterations in this case we got the output 85 but different output will be
shown when we run it again because of the randomisation involved in this process.

Result:
After 20 iterations, the algorithm converges, providing a sequence of cities representing the optimal route for
the traveling salesman. The distance covered by this route is the minimum among the population. We have
shown its correct implementation above.

You might also like