# Loop(Classroom1, m_count, h_count, t_count, l_count, loopsize)
File "/Users/maninder/git/TrialScheduler/TrialScheduler/main.py", line 27, in Loop
Loop(Classroom1, m_count, h_count, t_count, l_count, loopsize)
File "/Users/maninder/git/TrialScheduler/TrialScheduler/main.py", line 27, in Loop
Loop(Classroom1, m_count, h_count, t_count, l_count, loopsize)
File "/Users/maninder/git/TrialScheduler/TrialScheduler/main.py", line 27, in Loop #
The code:
from CProfessor import Professor
from CCourse import Course
from CClassroom import Classroom
import copy
def Loop(Classroom1, m_count, h_count, t_count, l_count, loopsize):
for i in range(0, loopsize):
Mutated = Classroom()
#Mutated = Classroom1.CopyOfClassroom(Mutated)
Mutated = copy.deepcopy(Classroom1)#Modification
Mutated.Mutate()
HardConstraintClassroomMet = Classroom1.ComputeHardConstraint()
HardConstraintMutatedMet = Mutated.ComputeHardConstraint()
if HardConstraintClassroomMet == False and HardConstraintMutatedMet == False:
h_count + 1
t_count + 1
Classroom1.Mutate()
continue
if Mutated.FitnessValue() > Classroom1.FitnessValue():
m_count + 1
t_count + 1
Classroom1 = Mutated
if Classroom1.ComputeHardConstraint() == False:
l_count + 1
temp = l_count*loopsize
print "Unable to meet hard consraints in %d" % temp
Loop(Classroom1, m_count, h_count, t_count, l_count, loopsize)
Professor0 = Professor(ProfessorId = 0, PreferedStartTime = 8, PreferedEndTime = 11)
Professor1 = Professor(ProfessorId = 1, PreferedStartTime = 10, PreferedEndTime = 13.75)
Professor2 = Professor(ProfessorId = 2, PreferedStartTime = 4, PreferedEndTime = 7.75)
# intializing Courses
Course0 = Course(CourseId = 0, ProfessorId = 0, CourseSlot = 0, CourseType ="UnderGraduate")
Course1 = Course(CourseId = 1, ProfessorId = 4, CourseSlot = 1) # we decided to leave this
coursetype to be emmpty and it is set none in the Course class
Course2 = Course(CourseId = 2, ProfessorId = 1, CourseSlot = 2, CourseType ="UnderGraduate")
Course3 = Course(CourseId = 3, ProfessorId = 4, CourseSlot = 3)
Course4 = Course(CourseId = 4, ProfessorId = 1, CourseSlot = 4, CourseType ="UnderGraduate")
Course5 = Course(CourseId = 5, ProfessorId = 4, CourseSlot = 5)
Course6 = Course(CourseId = 6, ProfessorId = 2, CourseSlot = 6, CourseType ="Graduate")
Course7 = Course(CourseId = 7, ProfessorId = 2, CourseSlot = 7, CourseType ="UnderGraduate")
# intializing
Classroom1 = Classroom(FirstCourseStartTime = 8, LastCourseEndTime = 7.75)
# Add all courses to Classroom1
Classroom1.AddCourse(Course0)
Classroom1.AddCourse(Course1)
Classroom1.AddCourse(Course2)
Classroom1.AddCourse(Course3)
Classroom1.AddCourse(Course4)
Classroom1.AddCourse(Course5)
Classroom1.AddCourse(Course6)
Classroom1.AddCourse(Course7)
# Add Professors to the classroom.
Classroom1.AddProfessor(Professor0)
Classroom1.AddProfessor(Professor1)
Classroom1.AddProfessor(Professor2)
m_count = 0 # mutations caused by grea
h_count = 0
t_count = 0
l_count = 0
loopsize = 10000
Loop(Classroom1, m_count, h_count, t_count, l_count, loopsize)
"""
Printing out the results:
"""
print '\n'
print "Mutation caused by greater fitness value %d" % m_count
print "Mutation caused by Hard Constraint Violations %d" % h_count
print "Number of Mutations before Converging" % t_count
Classroom1.PrintClassroom()
Here’s the relevant part of the code:
In other words, when you call Loop with loopsize=10, it will call Loop 10 more times with loopsize 10… which will call Loop 100 more times… which will call it 1000 more times. So eventually, you’re going to run out of stack space.
The only way you ever skip the recursive case is if Classroom1.ComputeHardConstraint(), in which case you skip over one call to Loop, but you’ve still got loopcount-1 other calls. A properly-defined algorithm might complete, but it seems like you’re diverging—you cut off successful branches of the recursion tree, but continue on the rest forever. And even if it does converge, the recursion is almost certainly going to get very deep and wide, probably enough so to kill the stack anyway. (If you were counting on tail recursion elimination, Python doesn’t do that, and it wouldn’t help anyway except to maybe knock 1 call out of each loopcount.)
As a side note, much of your code doesn’t actually do anything. For example:
This evaluates the expression “h_count + 1”, then throws away the result. It doesn’t store it anywhere, use it for anything, change the value of h_count, or anything else.