-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.py
57 lines (49 loc) · 2.32 KB
/
schedule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import numpy as np
from model import Term, Course, Student
import config
#------------------------------------------------------------------------------
# Function initilize
#
# Purpose: Initialization of required objects. Objects are linked between
# eachother and input arrays are filled with objects.
#
# Parameters:
# terms - Numpy array of term objects.
# courses - Numpy array of course objects.
# students - Numpy array of student objects.
# rng - np.random.default_rng() object for random number generation.
#
# Returns: None. Three input arrays are modified.
#
#------------------------------------------------------------------------------
def initilize(terms, courses, students, rng) -> None:
#Initialization of terms
for i in range(config.numOfTerms):
terms[i] = Term(i)
#Picking a random starting term for each course
termIdListForCourses = rng.integers(low=0, high=config.numOfTerms,
size=config.numOfCourses)
#Initialization of each course object and
#setting previously picked random term
for i in range(config.numOfCourses):
courses[i] = Course(i)
courses[i].term = terms[termIdListForCourses[i]]
#Picking a random number of courses for each student
numOfCoursesForEachStudent = rng.integers(low=config.minNumOfCoursesPerStudent,
high=config.maxNumOfCoursesPerStudent,
size=config.numOfStudents, endpoint=True)
#Initialization of each student object
for i in range(config.numOfStudents):
curNumOfCourses = numOfCoursesForEachStudent[i]
students[i] = Student(i, curNumOfCourses)
#For each student we pick random courses they will enrole
courseIdListForStudent = rng.choice(config.numOfCourses,
curNumOfCourses, replace=False)
curCourses = np.empty(curNumOfCourses, dtype=object)
#We add each student to the courses they've enrolled
for j in range(curNumOfCourses):
courses[courseIdListForStudent[j]].students.append(students[i])
curCourses[j] = courses[courseIdListForStudent[j]]
#We set all the courses student enrolled to that student
students[i].courses = curCourses
students[i].setTerms()