我是Python新手。 我收到一个错误,上面写着“未定义的变量”。我无法理解。 代码中的陈述如下:
Classroom1 = Classroom(FirstCourseStartTime = 8, LastCourseEndTime = 7.75)
m_count = 0
h_count = 0
t_count = 0
l_count = 0
loopsize = 10000
Loop(Classroom1, m_count, h_count, t_count, l_count, loopsize)
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.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)
答案 0 :(得分:3)
在定义之前,您正在调用Loop()
函数。
答案 1 :(得分:0)
首先你需要组织:
class classroom,
def loop
在函数循环中写入globals:
global m_count
global h_count
global t_count
最后更改if语句:
if HardConstraintClassroomMet == False and HardConstraintMutatedMet == False:
h_count = h_count + 1
t_count = t_count + 1