Skip to content

Instantly share code, notes, and snippets.

@mukuljainx
Last active November 2, 2017 06:48
Show Gist options
  • Save mukuljainx/93de6106124b677ed9df2e9f51eb87f7 to your computer and use it in GitHub Desktop.
Save mukuljainx/93de6106124b677ed9df2e9f51eb87f7 to your computer and use it in GitHub Desktop.
A program to allocate courses to student as per their preferences and availability.
#This will left many unallocated student as there is no upper cap defiend for cce student on CSE and ECE courses.
import numpy as np
studentPreferenceFile = open("generated.csv", "r")
#creating objects of student choice
studentPreferenceFileData = studentPreferenceFile.readlines()
studentPreference = [] #of objects
for line in studentPreferenceFileData:
line = line.strip()
studentDataArray = line.split(",")
studentDataObject = {"rollNumber": studentDataArray[0], "branch": studentDataArray[1], "courseCount": int(studentDataArray[2]) ,"preferrence" : studentDataArray[3:], "alloted" : []}
studentPreference.append(studentDataObject)
#creating objects of course seat availability
courseAvailabilityFile = open("course.csv", "r")
courseAvailabilityFileData = courseAvailabilityFile.readlines()
courseAvailability = {}
for line in courseAvailabilityFileData:
line = line.strip()
courseDataArray = line.split(",")
courseAvailability[courseDataArray[0]] = {"name": courseDataArray[1], "seats": int(courseDataArray[2])}
allotmentList = []
file = open("allotmentList.csv", "w")
for x in xrange(0,8):
np.random.shuffle(studentPreference)
for student in studentPreference:
# print "coursecount: " + str(student["courseCount"])
# print "x: " + str(x)
# print len(student["preferrence"])
# print "--------------------"
if student["courseCount"] > 0 and len(student["preferrence"]) >= (x+1) and courseAvailability[student["preferrence"][x]]["seats"] > 0:
# print courseAvailability[student["preferrence"][x]]["seats"]
# print "x-----x"
courseAvailability[student["preferrence"][x]]["seats"] -= 1
student["alloted"].append(student["preferrence"][x])
student["courseCount"] -= 1
if student["courseCount"] == 0:
allotmentList.append(student)
studentPreference.remove(student)
print len(studentPreference)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment