Professional Documents
Culture Documents
Project Report
Introduction
The theme of the project is Smart Campus. A smart college/university campus is the one which uses modern
technology in various fields where it can be used. Some of the salient features of a smart campus can be:
For this project report, we are considering only one of these aspects: Analysis and Control of Mutual harmony among
students. Harmony among the students is very important. Two roommates if well suited for each other would not
just only live in greater peace but will be friends for life. Thus good friendship and lesser conflicts will ensure a better
life on campus for everyone.For this purpose, we have developed an algorithm using genetic algorithm to pair
roommates as per their preferences. Genetic Algorithm mimics the process of natural selection inspired by mutation,
cross over, inheritance and selection is used to get the best solution. Our algorithm provides the fitness of each pair
which is indicative of their compatibility. This fitness can be used by the Hostel Management Council to prevent usual
conflicts, maintain harmony among students and provide necessary counselling when required.
Project Methodology
Data Collection
First and foremost, the variables to be considered were decided. And several observations were recorded. The data
was collected using a web form which was shared on Facebook.
Fitness C alculation
Following rules have been used for calculation of fitness of each pair:
If both the roommates smoke or dont smoke, fitness is increased by 0.5 otherwise it is decreased by 0.2.
If both roommates prefer the same level of tidiness in the room, fitness is updated by 0.3 otherwise it is
decreased by 0.2.
If both roommate listen to same genre of music, fitness is increased by 0.5 otherwise decreased by 0.2.
If both roommate fulfil alcoholism preference for each other, fitness is increased by 0.4 otherwise decreased
by 0.1.
If both roommate fulfil outgoing/flexible/reserve preference for each other, fitness is increased by 0.4 for
each of them otherwise decreased by 0.1.
Here, we have considered only some of the parameters. The rest of the parameters have not been used due to
availability of less data and lesser effect of mutual harmony.
Genetic Algorithm
The Genetic Algorithm is a model of machine learning which derives its behavior from a metaphor of the processes of
evolution in nature. This is done by the creation within a machine of a population of individuals represented by
chromosomes, in essence a set of character strings that are analogous to the base-4 chromosomes that we see in our
own DNA. The individuals in the population then go through a process of evolution.
The rooms with maximum fitness value are taken and stored in a separate permanent roommates list.
The people who have been already paired are removed from the original residents list and the residue list is
again taken through the whole process until the whole list is exhausted and all people are paired successfully.
Limitations
Our program has the following limitations:
The solution in the considered case is three-levelled as opposed to optimization of mathematical functions
where there are only two levels.
There are multiple solutions in the considered case which are the different pairs.
All the above mentioned factors add to the computation time of the algorithm and difficulty to the coding.
Due to crossover of groups between two solutions, there are repetitions of people in the solution which has
to be removed which leads to wastage of a lot of solutions and increases the time as well.
The algorithm has not yet been designed to handle males and females separately due to lack of female entries
in the sample data. Although, the algorithm can be operated on males and females separately to get the
desired result.
Due to an unconventional modelling of the problem, the problem is difficult to code and debug.
The program doesnt have a Graphical User Interface due to internal limitations of R language.
The program doesnt take into consideration special preferences (not included in the form) of students as of
yet.
Future Projections
Our program can be further improved and expanded to take care of the following projections:
The code can be further improved and consolidated to reduce the time, consider gender and provide a
Graphical User Interface.
The input variables can be increased after conducting a psychological study to investigate the factors that
affect the harmony between room partners.
The algorithm can be appropriately modified to devise a match-making algorithm to provide dating and
marriage related advice.
The algorithm can be further improved to include the factors that are leading to decrease in fitness, in the
result. These factors will help the Hostel Council to understand conflict points better.
The code can be further improved and consolidated to reduce the time, consider gender and provide a
Graphical User Interface.
The input variables can be increased after conducting a psychological study to investigate the factors that
affect the harmony between room partners.
The algorithm can be appropriately modified to devise a match-making algorithm to provide dating and
marriage related advice.
The algorithm can be further improved to include the factors that are leading to decrease in fitness, in the
result. These factors will help the Hostel Council to understand conflict points better.
Summary
Genetic Algorithm is a very efficient and much easier to code method to arrive at the most optimal solution. Here,
genetic algorithm has been used on an unconventionally modelled problem to arrive at the best arrangement of
roommates. The programmed can be improved a lot to do away with the limitations and add the future projections.
Codes
initialallot.R
##divides residents into two groups for the sake of crossover
initialbuildingallot <- function(res) {
br <- sample(1:nrow(residents))
b1 <- sample(br, buildingcapacity , replace=F)
b2 <- setdiff(br, b1)
blist <- list("b1" = b1, "b2" = b2)
}
##randomly pair the residents of one building
initialroomallot <- function(buil){
builcap <- length(buil)
fitness <- vector(mode="numeric",length = builcap/2)
randombuilres <- sample(buil)
r1 <- sample(randombuilres, builcap/2, replace=F)
r2 <- setdiff(randombuilres,r1)
rooms <- cbind(r1,r2,fitness)
rooms
}
if(res[x,10] == res[y,10]) {
rooms[i,3] <- rooms[i,3] +
}
else
{
rooms[i,3] <- rooms[i,3] }
if(res[x,11] == res[y,12]) {
rooms[i,3] <- rooms[i,3] +
}
else
{
rooms[i,3] <- rooms[i,3] }
if(res[x,12] == res[y,11]) {
rooms[i,3] <- rooms[i,3] +
}
else {
rooms[i,3] <- rooms[i,3] }
if(res[x,13] == res[y,13]) {
rooms[i,3] <- rooms[i,3] +
}
else{
rooms[i,3] <- rooms[i,3] }
if(res[x,15] == res[y,16]) {
rooms[i,3] <- rooms[i,3] +
}
else{
rooms[i,3] <- rooms[i,3] }
if(res[x,16] == res[y,15]) {
rooms[i,3] <- rooms[i,3] +
}
else{
rooms[i,3] <- rooms[i,3] }
0.3
0.2
0.4
0.1
0.4
0.1
0.5
0.2
0.4
0.1
0.4
0.1
}
rooms
}
##calculates the sum of the fitness function of one set of groups/one
solution
solutionfitness <- function(r1,r2){
sum(r1[ ,3])+sum(r2[ ,3])
}
solutionmaker.R
mainfunctions.R
##calculates the average fitness of each solution
}
sum/length(pop)
}
ec <- vector(length=length(pop))
for(i in 1:length(pop)){
ec[i] = pop[[i]][[3]]/af
}
ec
}
cs
##generates the vector which will used to populate the mating pool
for(i in 1:length(cs)){
if(i==1){
if(a[j]<=cs[i]){
g[j] <- i
}
}
else if(a[j]>=cs[i-1] & a[j]<=cs[i]){
g[j] <- i
}
}
}
g
}
l
}
10
11
body.R
##the MAIN function
12
stop()
}
##generates a population of 10 solutions
population <- list(solutionmaker(),solutionmaker(),solutionmaker()
,solutionmaker(),solutionmaker(),solutionmaker(),
solutionmaker(),solutionmaker(),solutionmaker(),
solutionmaker())
##the population goes through 40 iterations of natural selection,
crossover and mutation
for(i in 1:40){
ec <- ecount(population)
ps <- probselection(ec)
cs <- cprobselection(ps)
g <- matingvector(cs)
l <- matingpoolmaker(g,population)
population <- crossover(population)
population <- updatecrossfitness(population)
population <- mutate(population,residents)
}
##calculates best fitness value
bf <- bestfitness(population)
##generation of empty vectors to store the roommates with maximum
fitness
fr1 <- vector("numeric")
fr2 <- vector("numeric")
ff <- vector("numeric")
13
d <- 1
for(i in 1:length(population)){
for(k in 1:2){
for(h in 1:nrow(population[[i]][[k]])){
if(population[[i]][[k]][[h,3]] == bf){
fr1[d] <- population[[i]][[k]][[h,1]]
fr2[d] <- population[[i]][[k]][[h,2]]
ff <- bf
d = d+1
}
}
}
}
##calculates the best pairs
pmates1 <<append(pmates1,as.vector(residents$name[bestpairs[[i,1]]]))
pmates2 <<append(pmates2,as.vector(residents$name[bestpairs[[i,2]]]))
pmates3 <<- append(pmates3,as.vector(bestpairs[[i,3]]))
}
}
}
14
names(residents)<c("name","rn","email","age","sex","smoke","mnper","athletic","study","
tidy","nature","roomienature","music","fpref","alcohol","rooal","rel")
##setting the building/group capacity to a fixed initial value
buildingcapacity <<- 10
##runs the MAIN 'algo' function
while(nrow(residents)>=2){
algo(residents)
}
##displays the final paired data in the console
data.frame(pmates1,pmates2,pmates3)
15