【发布时间】:2017-07-18 15:57:44
【问题描述】:
我对 Python 不是很好,我知道我的班级出了点问题,但我不确定它出了什么问题。这似乎是一个非常普遍的问题,但无论出于何种原因,我都很难理解为什么。
class distance:
def distance(operator_location,local_location):
global hsff_conveyor
global hsff_unload
global hsdr_conveyor
global hsdr_unload1
global hsdr_unload2
global distance_between_hsff_load_and_hsff_unload
global distance_between_hsff_load_and_hsdr_load
global distance_between_hsff_load_and_hsdr_unload1
global distance_between_hsff_load_and_hsdr_unload2
global distance_between_hsff_and_hsdr_conveyor
global distance_between_hsff_unload_and_hsdr_unload1
global distance_between_hsff_load_and_hsdr_unload2
global distance_between_hsdr_load_and_hsdr_unload1
global distance_between_hsdr_load_and_hsdzr_unload2
global distance_between_hsdr_unload1_and_unload2
if operator_location==hsff_conveyor and local_location==hsff_unload:
return distance_between_hsff_load_and_hsff_unload
elif operator_location==hsff_conveyor and local_location==hsdr_conveyor:
return distance_between_hsff_load_and_hsdr_load
elif operator_location==hsff_conveyor and local_location==hsdr_unload1:
return distance_between_hsff_load_and_hsdr_unload1
elif operator_location==hsff_conveyor and local_location==hsdr_unload2:
return distance_between_hsff_load_and_hsdr_unload2
elif operator_location==hsff_unload and local_location==hsdr_conveyor:
return distance_between_hsff_and_hsdr_conveyor
elif operator_location==hsff_unload and local_location==hsdr_unload1:
return distance_between_hsff_unload_and_hsdr_unload1
elif operator_location==hsff_unload and local_location==hsdr_unload2:
return distance_between_hsff_unload_and_hsdr_unload2
elif operator_location==hsdr_conveyor and local_location==hsdr_unload1:
return distance_between_hsdr_load_and_hsdr_unload1
elif operator_location==hsdr_conveyor and local_location==hsdr_unload2:
return distance_between_hsdr_load_and_hsdr_unload2
elif operator_location==hsdr_unload1 and local_location==hsdr_unload2:
return distance_between_hsdr_unload1_and_unload2
else:
return int(0)
当它到达这里时,它会返回标题中的错误:
def hsff_fill_conveyor(env, operator, logfile):
global hsff_pick_and_load_time
global conveyor
global hsff_conveyor_holds
global operator_location
global total_walk
global total_walk_time
global hsff_conveyor
global hsff_unload
local_location=hsff_conveyor
while True:
if operator_location==hsff_conveyor:
hsff_start_loading_conveyor=env.now
yield hsff_raw_container_cont.get(hsff_pick_quantity)
hsff_conveyor_short_time=env.now-hsff_start_loading_conveyor
with operator.request() as req1:
yield req1
hsff_conveyor_waiting_for_operator=env.now-hsff_start_loading_conveyor
yield env.timeout(hsff_pick_and_load_time)
hsff_load_cycle_ende=env.now
yield hsff_conveyor_cont.put(hsff_pick_quantity)
elif operator_location!=hsff_conveyor:
hsff_operator_ready_to_walk=env.now
hsff_operator_ready_to_walk_short_time=env.now-hsff_operator_ready_to_walk
with operator.request() as req1:
yield req1
hsff_conveyor_waiting_for_operator=env.now-hsff_operator_ready_to_walk
yield env.timeout(20) #FILLER
walk_end=env.now
total_walk=total_walk + distance() + 1
operator_location=hsff_conveyor
total_walk = total_walk + distance() + 1 引发错误。我在其他方面也发生了这种情况。试图模拟一个有五种不同资源可以请求他的操作员。
编辑:+1 不应该在 total_walk 行中。我只是用它来检查它是否还在工作一段时间。大脑被炸了,出于某种原因,我认为离开很重要。哎呀。
【问题讨论】:
-
为什么你的
distance类存在? -
错误信息是什么?
-
@CaryShindell 在标题中
-
需要堆栈跟踪来帮助(或有错误的行)
-
distance函数可以有多个returns。由于您想将1添加到其中,您必须确保它们都是数字的。正如@Rob 所说,删除class定义。还有distance需要参数才能运行;不能这样称呼它distance()..
标签: python python-2.7 simpy