Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
61e3887
Add files via upload
Codent47 Sep 18, 2018
920caa0
Update Course.py
Codent47 Sep 18, 2018
ba0013b
Update Course.py
Codent47 Sep 18, 2018
6e9dad0
Update Compute.py
KeerthanaSrikanth Sep 18, 2018
46d276f
Update Student.py
KeerthanaSrikanth Sep 18, 2018
dd1ad22
Update Compute.py
Codent47 Sep 18, 2018
281826b
Update Compute.py
Codent47 Sep 18, 2018
337307c
Update Compute.py
KeerthanaSrikanth Sep 19, 2018
c631f3e
Update Course.py
KeerthanaSrikanth Sep 19, 2018
f0b9347
Update Student.py
KeerthanaSrikanth Sep 19, 2018
ce6b8fc
Add temporary data
KeerthanaSrikanth Sep 20, 2018
84e603a
Add temporary instructor and course data
KeerthanaSrikanth Sep 20, 2018
eb72431
Add files via upload
KeerthanaSrikanth Sep 20, 2018
3df9ecf
Delete course.py.ods
KeerthanaSrikanth Sep 21, 2018
151a484
Delete instructor.ods
KeerthanaSrikanth Sep 21, 2018
bcfc656
Add self to methods
KeerthanaSrikanth Sep 21, 2018
7bc56ef
Add self to methods
KeerthanaSrikanth Sep 21, 2018
e5b2031
Add self to methods
KeerthanaSrikanth Sep 21, 2018
8a361d0
Delete ARC - Sheet2.csv
KeerthanaSrikanth Sep 21, 2018
ce0bde2
Create course_list and student_list
KeerthanaSrikanth Sep 21, 2018
57ca8f7
Add temporary course, instructor and student data
KeerthanaSrikanth Sep 21, 2018
3edc28b
Update Compute.py
Codent47 Sep 22, 2018
d48471c
documentcompute.py
harshrawat17 Sep 26, 2018
5a3efa1
course_document.py
harshrawat17 Sep 26, 2018
2ef5258
document_instructor.py
harshrawat17 Sep 26, 2018
7ada913
document_student.py
harshrawat17 Sep 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 147 additions & 20 deletions Compute.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,151 @@
import Course
import Instructor
import Student
#Returns lambda_c for a single course
from Course import *
from Student import *
from Instructor import *
import operator
import pandas as pd

#Calculates lambda_c(which is used to rank the courses) for a single course
def lambda_c(course, student_list): #course is an object of course class, student_list is a list of Students
c1=0;
c2=0;
c3=0;
for j in student_list:
for i in j.preferences: #Checking priority for particular course.
if(i[0]==course.course_code):
c1=c1+1;
elif(i[1]==course.course_code):
c2=c2+1;
elif(i[2]==course.course_code):
c3=c3+1;
c=[0,0,0,0,0]
for j in student_list:
cnt=0
for i in j.getPreferences(): #Checking priority for particular course.
if (i[0]==course.getCourseCode()):
c[cnt]+=1
cnt+=1

app=3*c1+2*c2+1*c3; #Calculating lambda_c
lam_c=app/course.size_remaining;
app=5*c[0]+4*c[1]+3*c[2]+2*c[3]+c[4] #Calculating lambda_c
lam_c=app/course.getSizeRemaining()

return lam_c

#Calculates lambda_s (which is used to rank the students) for a single student
def lambda_s(student, grade): #returns lambda_s
grade=float(grade)
return (grade*10+float(student.getCG()))

#allots the students who have been recommended by the instructors of various courses into the respective courses
def instructorAllotPreference(instructor_list, course_list): #Not checking for clashes, not checking if student applied for the course.
#List of all instructors, list of all courses.
for i in instructor_list:
for k, l in i.getPreferences():
l.allotCourse(k.getCourseCode())
k.decrementSize()

#alloting first preference to students from the course list sorted on the basis of lambda_c
def fillAppliedFirstPreference(course_list, student_list):
#List of all courses, list of all students
for i in student_list:
if (i.getAllotedCourse()!="None"):
continue
x=i.getPreferences()
ls=lambda_s(i, x[0][1])
course_code_dict[x[0][0]].addToApplied(i, ls)

#sorts the courses according to the lambda_c as parameter
def sortCourses(course_list, student_list):
#List of all courses, list of all students
lambda_c_list=[]
for i in course_list:
c=lambda_c(i, student_list)
lambda_c_list.append((i, c))

lambda_c_list.sort(key=operator.itemgetter(1))
lambda_c_list=[course for course, lam_c in lambda_c_list]
return lambda_c_list

#alloting the students their respective courses from the sorted list of that course
def allot(course):
while(course.getSizeRemaining()>0 and course.appliedRemaining()>0):
most_deserving=course.popApplied()
course.allot(-most_deserving[0], most_deserving[1])
most_deserving[1].allotCourse(course.getCourseCode())

fillRemaining(course)

#filling the remaining seats of the course
def fillRemaining(course):
while(course.appliedRemaining()>0):
most_deserving=course.popApplied()
nextPreference(most_deserving[1], course)

#pushing students into the next preference course list if their current preference is full
def nextPreference(student, course):
flag=False
for j in student.getPreferences():
if(j[0]==course): #If course matches
flag=True
elif(flag):
ls=lambda_s(student, j[1])
if(j[0].getSizeRemaining()>0): #And next preference is not full
j[0].addToApplied(l, ls) #Push student into applied of next preference
else:
ifFull(ls, student, j[0])
break

#checking whether their current preference course list is full or not and sending them to next preference if list full
def ifFull(ls, student, course):
worst_student=getWorstSelected()
for k, l in worst_student:
if(k<ls):
student.allotCourse(course.getCourseCode())
course.popWorstSelected()
l.allotCourse("None")
nextPreference(k, l, course)
else:
nextPreference(ls, student, course)

#(don't know much about pandas so can't do documentation)
df=pd.read_csv('Course.csv')
course_list=[]
course_code_dict={}
for index, row in df.iterrows():
c=Course(row['course_code'],row['Size-remaining'])
course_list.append(c)
course_code_dict[c.getCourseCode()]=c

df=pd.read_csv('Student.csv')
student_list=[]
student_id_dict={}
for index, row in df.iterrows():
if (row['ID'] in student_id_dict): #to take care of duplicate data set
continue
prefs=[(row['Course1'],row['Grade1']),(row['Course2'],row['Grade2']),(row['Course3'],row['Grade3']),(row['Course4'],row['Grade4']),(row['Course5'],row['Grade5'])]
s=Student(row['ID'],prefs,"None",row['CG'])
student_list.append(s)
student_id_dict[s.getID()]=s

df=pd.read_csv('Instructor.csv')
instructor_list=[]
instructor_id_dict={}
for index, row in df.iterrows():
c=course_code_dict[row['Course']]
s=student_id_dict[row['Student']]
prefs=[(c,s)]
if (row['Instructor'] in instructor_id_dict):
instructor_id_dict[row['Instructor']].addToPreferences(c,s)
else:
i=Instructor(prefs)
instructor_list.append(i)
instructor_id_dict[row['Instructor']]=i

instructorAllotPreference (instructor_list,course_list)

for c in course_list:
if (c.getSizeRemaining()==0):
course_list.remove(c)

course_list=sortCourses(course_list,student_list)

fillAppliedFirstPreference(course_list,student_list)

for c in course_list:
allot(c)

print(len(student_list))

for s in student_list:
print(s.getID(),s.getAllotedCourse())


return lam_c;

def lambda_s(student): #Returns lambda_s
return (student.preferences[0][1]*0.8+student.CG*0.2);
10 changes: 10 additions & 0 deletions Course.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
course_code,Size-remaining
A,5
B,4
C,4
D,3
E,7
F,2
G,1
H,6
I,3
56 changes: 48 additions & 8 deletions Course.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
import heapq
from heapq import heappush,heappop
class Course:
def __init__(self, course_code, size_remaining):
self.course_code=course_code
self.size_remaining=size_remaining
self.applied=[]
self.selected=[]

def __init__(self, course_code, size_remaining, selected, applied):
self.course_code=course_code;
self.size_remaining=size_remaining;
self.selected=selected;
heapq.heapify(selected);
self.applied=applied
heapq.heapify(applied);
#adding students to the applied list
def addToApplied(self, student,lambda_s):
heappush(self.applied,(-lambda_s,student))

#prints the student ID no.s who have applied
def printApplied(self):
for x in self.applied:
print(x[1].getID())

#pops the best student suitable for the course on the basis of lambda_s
def popApplied(self):
return heappop(self.applied)

#checking the number of students in the applied list
def appliedRemaining(self):
return len(self.applied)

#decrements the size of the course list
def decrementSize(self):
self.size_remaining-=1

#pushing the worst student (on basis of lambda_s) to the top of the list
def allot(self, student,lambda_s):
heappush(self.selected,(lambda_s,student))
self.decrementSize()

#returns the worst student
def getWorstSelected(self):
return self.selected[0]

#removes the worst student from the selected list
def popWorstSelected(self):
self.size_remaining-=1
return heappop(self.selected)

#returns the course code of the course
def getCourseCode(self):
return self.course_code

#returns the size remaining in the course
def getSizeRemaining(self):
return self.size_remaining
12 changes: 12 additions & 0 deletions Instructor.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Instructor,Course1,Student1,Student2
Z,A,2017A7PS0054G,
Z,B,2016A7PS0002G,
Y,,,
X,D,2015A8PS0326G,
W,H,2017AAPS0267G,2017AAPS0452G
V,,,
U,,,
T,G,2014B1A40567G,
S,I,2015A3PS0562G,
R,,,
Q,C,2016B3A10421G,2015B4TS0631G
13 changes: 10 additions & 3 deletions Instructor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@

class Instructor:
class Instructor:

def __init__(self, preference):
self.preference=preference; #List of pairs (Course, Student)
self.preference=preference #here preference is a list of pairs (Course, Student)

#list of students given by the instructors of their respective courses:-
def getPreferences(self):
return self.preference

#adding students into the above preference list:-
def addToPreferences(self,course,student):
self.preference.append((course,student))
30 changes: 30 additions & 0 deletions Student.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ID,CG,Course1,Grade1,Course2,Grade2,Course3,Grade3,Course4,Grade4,Course5,Grade5
2017A3PS0453G,9.2,A,10,B,8,D,9,,,,
2017A3PS0455G,8.3,E,8,G,9,,,,,,
2017A3PS0456G,7.4,F,9,E,7,D,8,,,,
2017A3PS0458G,8.5,A,10,G,9,,,,,,
2017A3PS0459G,9.7,B,6,G,8,A,9,,,,
2017A3PS0899G,8.3,E,7,D,9,,,,,,
2017A3PS0900G,7.9,E,8,A,8,,,,,,
2017A3PS0901G,8.7,A,9,,,,,,,,
2017A3PS0902G,8.1,D,10,,,,,,,,
2017A3PS1900G,7.7,F,8,A,7,G,8,,,,
2017A3PS1901G,7.9,E,7,A,9,B,9,,,,
2017A3PS0453G,7.2,C,9,H,8,D,8,,,,
2017A3PS0455G,7.4,F,7,D,7,C,7,,,,
2017A3PS0456G,8.6,A,8,B,9,C,9,G,9,,
2017A3PS0458G,8.8,F,9,D,10,E,8,,,,
2017A3PS0459G,10,A,6,C,6,D,9,F,8,I,10
2017A3PS0899G,8.5,A,7,C,9,B,7,,,,
2017A3PS0900G,9.1,H,8,D,9,H,6,,,,
2017A3PS0901G,8.2,H,7,I,10,,,,,,
2017A3PS0902G,8.8,B,8,C,8,H,10,A,10,,
2017A3PS1900G,7.6,E,9,F,7,A,10,C,10,,
2016A3PS0166G,7.2,I,7,D,9,E,9,G,9,,
2016A3PS0167G,7.4,H,10,B,10,A,7,D,8,,
2016A3PS0168G,8.5,B,8,D,9,G,8,H,9,E,8
2016A3PS0169G,7.5,I,9,B,10,H,10,G,7,,
2016A3PS0170G,8,A,6,E,9,G,9,D,6,,
2016A3PS0173G,9,A,8,C,9,B,10,D,9,,
2016A3PS0178G,7.7,F,7,A,8,,,,,,
2016A3PS0180G,7.3,B,10,I,9,A,9,C,8,,
35 changes: 30 additions & 5 deletions Student.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
class Student:

def __init__ (self,ID,preferences ,alloted,CG):
self.ID=ID;
self.preferences=preferences;
self.alloted=alloted;
self.CG=CG;
def __init__ (self,ID,preferences,alloted,CG):
self.ID=ID
self.preferences=preferences #here preferences is a list of (grade,course)
self.alloted=alloted
self.CG=CG

#redefining the greater than operator. (if two students are compared, they will be compared on the bases of ID)
def __gt__(self, student2):
return self.ID > student2.getID()

#allots the course to the student:-
def allotCourse(self, alloted):
self.alloted=alloted

#returns the alloted course of the student:-
def getAllotedCourse(self):
return self.alloted

#returns preference list of the student:-
def getPreferences(self):
return self.preferences

#returns CG of the student:-
def getCG(self):
return self.CG
#returns ID of the student:-
def getID(self):
return self.ID