コード例 #1
0
ファイル: algorithm.py プロジェクト: qtmdev/DegreeBuilder
	def add_later(course):
		needed_prereqs = list(course.prereqs)
		course_units = course.units

		pre_tech_total = 0
		if course.technical:
			pre_tech_total = course_units

		for key in student_dict:
			sem_total = course_units
			tech_total = pre_tech_total
			this_sem_prereq = False

			for course1 in student_dict[key]:
				course1 = get_course(course1)
				if not course1:
					sem_total += 0
				else:
					sem_total += course1.units

					if course1.technical:
						tech_total += course1.units

					if course1 in needed_prereqs:
						needed_prereqs.remove(course1.toString())
						this_sem_prereq = True

			if sem_total <= unit_cap and tech_total <= technical_cap and not this_sem_prereq:
				student_dict[key].append(course.toString())
				return True

		return False
コード例 #2
0
ファイル: algorithm.py プロジェクト: qtmdev/DegreeBuilder
	def add_early(course):
		course_units = course.units

		pre_tech_total = 0
		if course.technical:
			pre_tech_total = course_units

		for key in student_dict:
			sem_total = course_units
			tech_total = pre_tech_total

			for course1 in student_dict[key]:
				course1 = get_course(course1)
				if not course1:
					sem_total += 0
				else:
					sem_total += course1.units

					if course1.technical:
						tech_total += course1.units

					if sem_total > unit_cap or tech_total > technical_cap:
						break

			if sem_total <= unit_cap and tech_total <= technical_cap:
				student_dict[key].append(course.toString())
				return True

		return False
コード例 #3
0
ファイル: algorithm.py プロジェクト: qtmdev/DegreeBuilder
def course_map(student_dict, needed_courses, student, completed_courses, unit_cap = 16, technical_cap = 12):

	def add_later(course):
		needed_prereqs = list(course.prereqs)
		course_units = course.units

		pre_tech_total = 0
		if course.technical:
			pre_tech_total = course_units

		for key in student_dict:
			sem_total = course_units
			tech_total = pre_tech_total
			this_sem_prereq = False

			for course1 in student_dict[key]:
				course1 = get_course(course1)
				if not course1:
					sem_total += 0
				else:
					sem_total += course1.units

					if course1.technical:
						tech_total += course1.units

					if course1 in needed_prereqs:
						needed_prereqs.remove(course1.toString())
						this_sem_prereq = True

			if sem_total <= unit_cap and tech_total <= technical_cap and not this_sem_prereq:
				student_dict[key].append(course.toString())
				return True

		return False


	def add_early(course):
		course_units = course.units

		pre_tech_total = 0
		if course.technical:
			pre_tech_total = course_units

		for key in student_dict:
			sem_total = course_units
			tech_total = pre_tech_total

			for course1 in student_dict[key]:
				course1 = get_course(course1)
				if not course1:
					sem_total += 0
				else:
					sem_total += course1.units

					if course1.technical:
						tech_total += course1.units

					if sem_total > unit_cap or tech_total > technical_cap:
						break

			if sem_total <= unit_cap and tech_total <= technical_cap:
				student_dict[key].append(course.toString())
				return True

		return False


	def scan_prereq(course):
		for prereq in course.prereqs:
			if prereq not in completed_courses:
				if prereq not in needed_courses:
					needed_courses.append(prereq)
				return False
		return True

	while len(needed_courses) != 0:
		for course in needed_courses:
			course = get_course(course)
			if not course: continue
			if len(course.prereqs) == 0:
				for i in range(3):
					map_del(student_dict, course.toString())
				if add_early(course):
					needed_courses.remove(course.toString())
					completed_courses.append(course.toString())
				else:
					return student_dict #return {FAILURE: course}
			else:
				completed_courses = completed(student_dict)
				if scan_prereq(course):
					map_del(student_dict, course.toString())
					if add_later(course):
						needed_courses.remove(course.toString())
						completed_courses.append(course.toString())
					else:
						return student_dict #{FAILURE: course}

	for key in student.major.requirements:
		need = student.major.requirements[key]
		for item in key:
			if item in completed_courses:
				need -= 1
				if need <= 0:
					break

		while need > 0:
			test_course = random.choice(key)
			print test_course
			if test_course not in completed_courses:
				completed_courses.append(test_course)
				add_later(get_course(test_course))
				need -= 1

	return student_dict