我對Python並不擅長,我知道某些東西與我的類混爲一談,但我不確定它出了什麼問題。這似乎是一個相當普遍的問題,但無論出於什麼原因,我都很難理解爲什麼。TypeError:不支持的操作數類型爲+:'int'和'instance'
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線。我只是用它來檢查它是否在一段時間後才工作。大腦被炸,出於某種原因,我認爲這是足夠重要的離開。哎呀。
爲什麼你的「距離」類存在? – user2357112
什麼是錯誤信息? –
@CaryShindell標題 –